Re-applies changes that were accidentally discarded during a prior dry-run cherry-pick reset (git checkout -- .). - PR #1005: Use HalPowerManager for battery percentage (uint16_t return type, remove Battery.h, update theme files) - PR #1010: Fix dangling pointer in onGoToReader() - PR #1003: Render image placeholders while waiting for decode (adds isCached, renderPlaceholder, renderTextOnly, countUncachedImages, renderImagePlaceholders) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -61,6 +61,49 @@ std::unique_ptr<PageImage> PageImage::deserialize(FsFile& file) {
|
||||
return std::unique_ptr<PageImage>(new PageImage(std::move(ib), xPos, yPos));
|
||||
}
|
||||
|
||||
bool PageImage::isCached() const { return imageBlock->isCached(); }
|
||||
|
||||
void PageImage::renderPlaceholder(GfxRenderer& renderer, const int xOffset, const int yOffset) const {
|
||||
int x = xPos + xOffset;
|
||||
int y = yPos + yOffset;
|
||||
int w = imageBlock->getWidth();
|
||||
int h = imageBlock->getHeight();
|
||||
renderer.fillRect(x, y, w, h, true);
|
||||
if (w > 2 && h > 2) {
|
||||
renderer.fillRect(x + 1, y + 1, w - 2, h - 2, false);
|
||||
}
|
||||
}
|
||||
|
||||
void Page::renderTextOnly(GfxRenderer& renderer, const int fontId, const int xOffset, const int yOffset) const {
|
||||
for (auto& element : elements) {
|
||||
if (element->getTag() == TAG_PageLine) {
|
||||
element->render(renderer, fontId, xOffset, yOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Page::countUncachedImages() const {
|
||||
int count = 0;
|
||||
for (auto& element : elements) {
|
||||
if (element->getTag() == TAG_PageImage) {
|
||||
auto* img = static_cast<PageImage*>(element.get());
|
||||
if (!img->isCached()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void Page::renderImagePlaceholders(GfxRenderer& renderer, const int xOffset, const int yOffset) const {
|
||||
for (auto& element : elements) {
|
||||
if (element->getTag() == TAG_PageImage) {
|
||||
auto* img = static_cast<PageImage*>(element.get());
|
||||
img->renderPlaceholder(renderer, xOffset, yOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// PageTableRow
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -80,6 +80,8 @@ class PageImage final : public PageElement {
|
||||
void render(GfxRenderer& renderer, int fontId, int xOffset, int yOffset) override;
|
||||
bool serialize(FsFile& file) override;
|
||||
PageElementTag getTag() const override { return TAG_PageImage; }
|
||||
bool isCached() const;
|
||||
void renderPlaceholder(GfxRenderer& renderer, int xOffset, int yOffset) const;
|
||||
static std::unique_ptr<PageImage> deserialize(FsFile& file);
|
||||
|
||||
// Helper to get image block dimensions (needed for bounding box calculation)
|
||||
@@ -104,4 +106,8 @@ class Page {
|
||||
// Returns true if page has images and fills out the bounding box coordinates.
|
||||
// If no images, returns false.
|
||||
bool getImageBoundingBox(int& outX, int& outY, int& outWidth, int& outHeight) const;
|
||||
|
||||
void renderTextOnly(GfxRenderer& renderer, int fontId, int xOffset, int yOffset) const;
|
||||
int countUncachedImages() const;
|
||||
void renderImagePlaceholders(GfxRenderer& renderer, int xOffset, int yOffset) const;
|
||||
};
|
||||
|
||||
@@ -93,6 +93,11 @@ bool renderFromCache(GfxRenderer& renderer, const std::string& cachePath, int x,
|
||||
|
||||
} // namespace
|
||||
|
||||
bool ImageBlock::isCached() const {
|
||||
std::string cachePath = getCachePath(imagePath);
|
||||
return Storage.exists(cachePath.c_str());
|
||||
}
|
||||
|
||||
void ImageBlock::render(GfxRenderer& renderer, const int x, const int y) {
|
||||
LOG_DBG("IMG", "Rendering image at %d,%d: %s (%dx%d)", x, y, imagePath.c_str(), width, height);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class ImageBlock final : public Block {
|
||||
int16_t getHeight() const { return height; }
|
||||
|
||||
bool imageExists() const;
|
||||
bool isCached() const;
|
||||
|
||||
BlockType getType() override { return IMAGE_BLOCK; }
|
||||
bool isEmpty() override { return false; }
|
||||
|
||||
Reference in New Issue
Block a user