From 400b92e78880aedf66c0df15894c2226f8a0d9c7 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Tue, 20 Jan 2026 08:42:35 +0500 Subject: [PATCH 1/6] refactor: streamline popup rendering and remove unused BootActivity --- lib/Epub/Epub/Section.cpp | 7 ---- lib/Epub/Epub/Section.h | 1 - lib/GfxRenderer/GfxRenderer.h | 2 - src/ScreenComponents.cpp | 39 +++++++++++++++++ src/ScreenComponents.h | 22 ++++++++++ src/activities/boot_sleep/BootActivity.cpp | 20 --------- src/activities/boot_sleep/BootActivity.h | 9 ---- src/activities/boot_sleep/SleepActivity.cpp | 15 ------- src/activities/boot_sleep/SleepActivity.h | 1 - src/activities/reader/EpubReaderActivity.cpp | 44 +++----------------- src/activities/reader/TxtReaderActivity.cpp | 26 +----------- src/main.cpp | 5 +-- 12 files changed, 69 insertions(+), 122 deletions(-) delete mode 100644 src/activities/boot_sleep/BootActivity.cpp delete mode 100644 src/activities/boot_sleep/BootActivity.h diff --git a/lib/Epub/Epub/Section.cpp b/lib/Epub/Epub/Section.cpp index 581a364..31a99af 100644 --- a/lib/Epub/Epub/Section.cpp +++ b/lib/Epub/Epub/Section.cpp @@ -123,9 +123,7 @@ bool Section::clearCache() const { bool Section::createSectionFile(const int fontId, const float lineCompression, const bool extraParagraphSpacing, const uint8_t paragraphAlignment, const uint16_t viewportWidth, const uint16_t viewportHeight, const bool hyphenationEnabled, - const std::function& progressSetupFn, const std::function& progressFn) { - constexpr uint32_t MIN_SIZE_FOR_PROGRESS = 50 * 1024; // 50KB const auto localPath = epub->getSpineItem(spineIndex).href; const auto tmpHtmlPath = epub->getCachePath() + "/.tmp_" + std::to_string(spineIndex) + ".html"; @@ -171,11 +169,6 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c Serial.printf("[%lu] [SCT] Streamed temp HTML to %s (%d bytes)\n", millis(), tmpHtmlPath.c_str(), fileSize); - // Only show progress bar for larger chapters where rendering overhead is worth it - if (progressSetupFn && fileSize >= MIN_SIZE_FOR_PROGRESS) { - progressSetupFn(); - } - if (!SdMan.openFileForWrite("SCT", filePath, file)) { return false; } diff --git a/lib/Epub/Epub/Section.h b/lib/Epub/Epub/Section.h index 5b72614..cfa01fe 100644 --- a/lib/Epub/Epub/Section.h +++ b/lib/Epub/Epub/Section.h @@ -33,7 +33,6 @@ class Section { bool clearCache() const; bool createSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, uint8_t paragraphAlignment, uint16_t viewportWidth, uint16_t viewportHeight, bool hyphenationEnabled, - const std::function& progressSetupFn = nullptr, const std::function& progressFn = nullptr); std::unique_ptr loadPageFromSectionFile(); }; diff --git a/lib/GfxRenderer/GfxRenderer.h b/lib/GfxRenderer/GfxRenderer.h index b1fea69..009309e 100644 --- a/lib/GfxRenderer/GfxRenderer.h +++ b/lib/GfxRenderer/GfxRenderer.h @@ -55,8 +55,6 @@ class GfxRenderer { int getScreenWidth() const; int getScreenHeight() const; void displayBuffer(EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH) const; - // EXPERIMENTAL: Windowed update - display only a rectangular region - void displayWindow(int x, int y, int width, int height) const; void invertScreen() const; void clearScreen(uint8_t color = 0xFF) const; diff --git a/src/ScreenComponents.cpp b/src/ScreenComponents.cpp index 42b6ef7..cf579fc 100644 --- a/src/ScreenComponents.cpp +++ b/src/ScreenComponents.cpp @@ -42,6 +42,45 @@ void ScreenComponents::drawBattery(const GfxRenderer& renderer, const int left, renderer.fillRect(x + 2, y + 2, filledWidth, batteryHeight - 4); } +ScreenComponents::PopupLayout ScreenComponents::drawPopup(const GfxRenderer& renderer, const char* message, + const int y, const int minWidth, + const int minHeight) { + const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, message, EpdFontFamily::BOLD); + constexpr int margin = 16; + const int contentWidth = textWidth > minWidth ? textWidth : minWidth; + const int x = (renderer.getScreenWidth() - contentWidth - margin * 2) / 2; + const int w = contentWidth + margin * 2; + const int contentHeight = renderer.getLineHeight(UI_12_FONT_ID) + margin * 2; + const int h = contentHeight >= minHeight ? contentHeight : minHeight; + renderer.fillRect(x - 2, y - 2, w + 4, h + 4, true); + renderer.fillRect(x + 2, y + 2, w - 4, h - 4, false); + + const int barWidth = POPUP_DEFAULT_MIN_WIDTH; + const int barHeight = POPUP_DEFAULT_BAR_HEIGHT; + const int barX = x + (w - barWidth) / 2; + const int barY = y + renderer.getLineHeight(UI_12_FONT_ID) + margin * 2 - 6; + + const int textX = x + margin + (contentWidth - textWidth) / 2; + renderer.drawText(UI_12_FONT_ID, textX, y + margin, message, true, EpdFontFamily::BOLD); + renderer.displayBuffer(); + return {x, y, w, h, barX, barY, barWidth, barHeight}; +} + +void ScreenComponents::fillPopupProgress(const GfxRenderer& renderer, const PopupLayout& layout, + const int progress) { + int fillWidth = layout.barWidth * progress / 100; + if (fillWidth < 0) { + fillWidth = 0; + } else if (fillWidth > layout.barWidth) { + fillWidth = layout.barWidth; + } + + if (fillWidth > 2) { + renderer.fillRect(layout.barX + 1, layout.barY + 1, fillWidth - 2, layout.barHeight - 2, true); + } + renderer.displayBuffer(EInkDisplay::FAST_REFRESH); +} + void ScreenComponents::drawProgressBar(const GfxRenderer& renderer, const int x, const int y, const int width, const int height, const size_t current, const size_t total) { if (total == 0) { diff --git a/src/ScreenComponents.h b/src/ScreenComponents.h index 150fb0c..e272b34 100644 --- a/src/ScreenComponents.h +++ b/src/ScreenComponents.h @@ -7,8 +7,30 @@ class GfxRenderer; class ScreenComponents { public: + static constexpr int POPUP_DEFAULT_MIN_HEIGHT = 72; + static constexpr int POPUP_DEFAULT_BAR_HEIGHT = 6; + static constexpr int POPUP_DEFAULT_MIN_WIDTH = 200; + + struct PopupLayout { + int x; + int y; + int width; + int height; + + int barX; + int barY; + int barWidth; + int barHeight; + }; + static void drawBattery(const GfxRenderer& renderer, int left, int top, bool showPercentage = true); + static PopupLayout drawPopup(const GfxRenderer& renderer, const char* message, int y = 117, + int minWidth = POPUP_DEFAULT_MIN_WIDTH, + int minHeight = POPUP_DEFAULT_MIN_HEIGHT); + + static void fillPopupProgress(const GfxRenderer& renderer, const PopupLayout& layout, int progress); + /** * Draw a progress bar with percentage text. * @param renderer The graphics renderer diff --git a/src/activities/boot_sleep/BootActivity.cpp b/src/activities/boot_sleep/BootActivity.cpp deleted file mode 100644 index 65eb6a0..0000000 --- a/src/activities/boot_sleep/BootActivity.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "BootActivity.h" - -#include - -#include "fontIds.h" -#include "images/CrossLarge.h" - -void BootActivity::onEnter() { - Activity::onEnter(); - - const auto pageWidth = renderer.getScreenWidth(); - const auto pageHeight = renderer.getScreenHeight(); - - renderer.clearScreen(); - renderer.drawImage(CrossLarge, (pageWidth + 128) / 2, (pageHeight - 128) / 2, 128, 128); - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 70, "CrossPoint", true, EpdFontFamily::BOLD); - renderer.drawCenteredText(SMALL_FONT_ID, pageHeight / 2 + 95, "BOOTING"); - renderer.drawCenteredText(SMALL_FONT_ID, pageHeight - 30, CROSSPOINT_VERSION); - renderer.displayBuffer(); -} diff --git a/src/activities/boot_sleep/BootActivity.h b/src/activities/boot_sleep/BootActivity.h deleted file mode 100644 index 312f2ab..0000000 --- a/src/activities/boot_sleep/BootActivity.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../Activity.h" - -class BootActivity final : public Activity { - public: - explicit BootActivity(GfxRenderer& renderer, MappedInputManager& mappedInput) - : Activity("Boot", renderer, mappedInput) {} - void onEnter() override; -}; diff --git a/src/activities/boot_sleep/SleepActivity.cpp b/src/activities/boot_sleep/SleepActivity.cpp index bf2b585..994bf8b 100644 --- a/src/activities/boot_sleep/SleepActivity.cpp +++ b/src/activities/boot_sleep/SleepActivity.cpp @@ -14,7 +14,6 @@ void SleepActivity::onEnter() { Activity::onEnter(); - renderPopup("Entering Sleep..."); if (SETTINGS.sleepScreen == CrossPointSettings::SLEEP_SCREEN_MODE::BLANK) { return renderBlankSleepScreen(); @@ -31,20 +30,6 @@ void SleepActivity::onEnter() { renderDefaultSleepScreen(); } -void SleepActivity::renderPopup(const char* message) const { - const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, message, EpdFontFamily::BOLD); - constexpr int margin = 20; - const int x = (renderer.getScreenWidth() - textWidth - margin * 2) / 2; - constexpr int y = 117; - const int w = textWidth + margin * 2; - const int h = renderer.getLineHeight(UI_12_FONT_ID) + margin * 2; - // renderer.clearScreen(); - renderer.fillRect(x - 5, y - 5, w + 10, h + 10, true); - renderer.fillRect(x + 5, y + 5, w - 10, h - 10, false); - renderer.drawText(UI_12_FONT_ID, x + margin, y + margin, message, true, EpdFontFamily::BOLD); - renderer.displayBuffer(); -} - void SleepActivity::renderCustomSleepScreen() const { // Check if we have a /sleep directory auto dir = SdMan.open("/sleep"); diff --git a/src/activities/boot_sleep/SleepActivity.h b/src/activities/boot_sleep/SleepActivity.h index 283220c..87df8ba 100644 --- a/src/activities/boot_sleep/SleepActivity.h +++ b/src/activities/boot_sleep/SleepActivity.h @@ -10,7 +10,6 @@ class SleepActivity final : public Activity { void onEnter() override; private: - void renderPopup(const char* message) const; void renderDefaultSleepScreen() const; void renderCustomSleepScreen() const; void renderCoverSleepScreen() const; diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index d70a15c..15c7d25 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -283,49 +283,15 @@ void EpubReaderActivity::renderScreen() { viewportHeight, SETTINGS.hyphenationEnabled)) { Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis()); - // Progress bar dimensions - constexpr int barWidth = 200; - constexpr int barHeight = 10; - constexpr int boxMargin = 20; - const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, "Indexing..."); - const int boxWidthWithBar = (barWidth > textWidth ? barWidth : textWidth) + boxMargin * 2; - const int boxWidthNoBar = textWidth + boxMargin * 2; - const int boxHeightWithBar = renderer.getLineHeight(UI_12_FONT_ID) + barHeight + boxMargin * 3; - const int boxHeightNoBar = renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2; - const int boxXWithBar = (renderer.getScreenWidth() - boxWidthWithBar) / 2; - const int boxXNoBar = (renderer.getScreenWidth() - boxWidthNoBar) / 2; - constexpr int boxY = 50; - const int barX = boxXWithBar + (boxWidthWithBar - barWidth) / 2; - const int barY = boxY + renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2; - - // Always show "Indexing..." text first - { - renderer.fillRect(boxXNoBar, boxY, boxWidthNoBar, boxHeightNoBar, false); - renderer.drawText(UI_12_FONT_ID, boxXNoBar + boxMargin, boxY + boxMargin, "Indexing..."); - renderer.drawRect(boxXNoBar + 5, boxY + 5, boxWidthNoBar - 10, boxHeightNoBar - 10); - renderer.displayBuffer(); - pagesUntilFullRefresh = 0; - } - - // Setup callback - only called for chapters >= 50KB, redraws with progress bar - auto progressSetup = [this, boxXWithBar, boxWidthWithBar, boxHeightWithBar, barX, barY] { - renderer.fillRect(boxXWithBar, boxY, boxWidthWithBar, boxHeightWithBar, false); - renderer.drawText(UI_12_FONT_ID, boxXWithBar + boxMargin, boxY + boxMargin, "Indexing..."); - renderer.drawRect(boxXWithBar + 5, boxY + 5, boxWidthWithBar - 10, boxHeightWithBar - 10); - renderer.drawRect(barX, barY, barWidth, barHeight); - renderer.displayBuffer(); - }; - - // Progress callback to update progress bar - auto progressCallback = [this, barX, barY, barWidth, barHeight](int progress) { - const int fillWidth = (barWidth - 2) * progress / 100; - renderer.fillRect(barX + 1, barY + 1, fillWidth, barHeight - 2, true); - renderer.displayBuffer(EInkDisplay::FAST_REFRESH); + pagesUntilFullRefresh = 0; + const auto popupLayout = ScreenComponents::drawPopup(renderer, "Indexing..."); + const auto progressCallback = [this, popupLayout](int progress) { + ScreenComponents::fillPopupProgress(renderer, popupLayout, progress); }; if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), SETTINGS.extraParagraphSpacing, SETTINGS.paragraphAlignment, viewportWidth, - viewportHeight, SETTINGS.hyphenationEnabled, progressSetup, progressCallback)) { + viewportHeight, SETTINGS.hyphenationEnabled, progressCallback)) { Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis()); section.reset(); return; diff --git a/src/activities/reader/TxtReaderActivity.cpp b/src/activities/reader/TxtReaderActivity.cpp index db72532..60cafa7 100644 --- a/src/activities/reader/TxtReaderActivity.cpp +++ b/src/activities/reader/TxtReaderActivity.cpp @@ -192,24 +192,7 @@ void TxtReaderActivity::buildPageIndex() { Serial.printf("[%lu] [TRS] Building page index for %zu bytes...\n", millis(), fileSize); - // Progress bar dimensions (matching EpubReaderActivity style) - constexpr int barWidth = 200; - constexpr int barHeight = 10; - constexpr int boxMargin = 20; - const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, "Indexing..."); - const int boxWidth = (barWidth > textWidth ? barWidth : textWidth) + boxMargin * 2; - const int boxHeight = renderer.getLineHeight(UI_12_FONT_ID) + barHeight + boxMargin * 3; - const int boxX = (renderer.getScreenWidth() - boxWidth) / 2; - constexpr int boxY = 50; - const int barX = boxX + (boxWidth - barWidth) / 2; - const int barY = boxY + renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2; - - // Draw initial progress box - renderer.fillRect(boxX, boxY, boxWidth, boxHeight, false); - renderer.drawText(UI_12_FONT_ID, boxX + boxMargin, boxY + boxMargin, "Indexing..."); - renderer.drawRect(boxX + 5, boxY + 5, boxWidth - 10, boxHeight - 10); - renderer.drawRect(barX, barY, barWidth, barHeight); - renderer.displayBuffer(); + const auto popupLayout = ScreenComponents::drawPopup(renderer, "Indexing..."); while (offset < fileSize) { std::vector tempLines; @@ -235,9 +218,7 @@ void TxtReaderActivity::buildPageIndex() { lastProgressPercent = progressPercent; // Fill progress bar - const int fillWidth = (barWidth - 2) * progressPercent / 100; - renderer.fillRect(barX + 1, barY + 1, fillWidth, barHeight - 2, true); - renderer.displayBuffer(EInkDisplay::FAST_REFRESH); + ScreenComponents::fillPopupProgress(renderer, popupLayout, progressPercent); } // Yield to other tasks periodically @@ -383,9 +364,6 @@ void TxtReaderActivity::renderScreen() { // Initialize reader if not done if (!initialized) { - renderer.clearScreen(); - renderer.drawCenteredText(UI_12_FONT_ID, 300, "Indexing...", true, EpdFontFamily::BOLD); - renderer.displayBuffer(); initializeReader(); } diff --git a/src/main.cpp b/src/main.cpp index e0ad316..ee9c77c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,7 @@ #include "CrossPointState.h" #include "KOReaderCredentialStore.h" #include "MappedInputManager.h" -#include "activities/boot_sleep/BootActivity.h" +#include "ScreenComponents.h" #include "activities/boot_sleep/SleepActivity.h" #include "activities/browser/OpdsBookBrowserActivity.h" #include "activities/home/HomeActivity.h" @@ -300,9 +300,6 @@ void setup() { setupDisplayAndFonts(); - exitActivity(); - enterNewActivity(new BootActivity(renderer, mappedInputManager)); - APP_STATE.loadFromFile(); if (APP_STATE.openEpubPath.empty()) { onGoHome(); From 27176da81164cad2c140d9e814808edf2b1d8080 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Tue, 20 Jan 2026 08:53:34 +0500 Subject: [PATCH 2/6] refactor: remove unused ScreenComponents include from main.cpp --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ee9c77c..2be87aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,6 @@ #include "CrossPointState.h" #include "KOReaderCredentialStore.h" #include "MappedInputManager.h" -#include "ScreenComponents.h" #include "activities/boot_sleep/SleepActivity.h" #include "activities/browser/OpdsBookBrowserActivity.h" #include "activities/home/HomeActivity.h" From 4bd7232948489633ee4d935fb9a6069055c1357d Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Tue, 20 Jan 2026 08:58:38 +0500 Subject: [PATCH 3/6] clang format fix --- src/ScreenComponents.cpp | 8 +++----- src/ScreenComponents.h | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ScreenComponents.cpp b/src/ScreenComponents.cpp index cf579fc..6cd1f65 100644 --- a/src/ScreenComponents.cpp +++ b/src/ScreenComponents.cpp @@ -42,9 +42,8 @@ void ScreenComponents::drawBattery(const GfxRenderer& renderer, const int left, renderer.fillRect(x + 2, y + 2, filledWidth, batteryHeight - 4); } -ScreenComponents::PopupLayout ScreenComponents::drawPopup(const GfxRenderer& renderer, const char* message, - const int y, const int minWidth, - const int minHeight) { +ScreenComponents::PopupLayout ScreenComponents::drawPopup(const GfxRenderer& renderer, const char* message, const int y, + const int minWidth, const int minHeight) { const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, message, EpdFontFamily::BOLD); constexpr int margin = 16; const int contentWidth = textWidth > minWidth ? textWidth : minWidth; @@ -66,8 +65,7 @@ ScreenComponents::PopupLayout ScreenComponents::drawPopup(const GfxRenderer& ren return {x, y, w, h, barX, barY, barWidth, barHeight}; } -void ScreenComponents::fillPopupProgress(const GfxRenderer& renderer, const PopupLayout& layout, - const int progress) { +void ScreenComponents::fillPopupProgress(const GfxRenderer& renderer, const PopupLayout& layout, const int progress) { int fillWidth = layout.barWidth * progress / 100; if (fillWidth < 0) { fillWidth = 0; diff --git a/src/ScreenComponents.h b/src/ScreenComponents.h index e272b34..45448b1 100644 --- a/src/ScreenComponents.h +++ b/src/ScreenComponents.h @@ -26,8 +26,7 @@ class ScreenComponents { static void drawBattery(const GfxRenderer& renderer, int left, int top, bool showPercentage = true); static PopupLayout drawPopup(const GfxRenderer& renderer, const char* message, int y = 117, - int minWidth = POPUP_DEFAULT_MIN_WIDTH, - int minHeight = POPUP_DEFAULT_MIN_HEIGHT); + int minWidth = POPUP_DEFAULT_MIN_WIDTH, int minHeight = POPUP_DEFAULT_MIN_HEIGHT); static void fillPopupProgress(const GfxRenderer& renderer, const PopupLayout& layout, int progress); From 21304ec72df04fd2f46b54cb740b014858683eb8 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Tue, 20 Jan 2026 09:18:52 +0500 Subject: [PATCH 4/6] refactor: simplify PopupLayout by removing unused progress bar attributes --- src/ScreenComponents.cpp | 20 ++++++++++---------- src/ScreenComponents.h | 5 ----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/ScreenComponents.cpp b/src/ScreenComponents.cpp index 6cd1f65..d2ba807 100644 --- a/src/ScreenComponents.cpp +++ b/src/ScreenComponents.cpp @@ -54,27 +54,27 @@ ScreenComponents::PopupLayout ScreenComponents::drawPopup(const GfxRenderer& ren renderer.fillRect(x - 2, y - 2, w + 4, h + 4, true); renderer.fillRect(x + 2, y + 2, w - 4, h - 4, false); - const int barWidth = POPUP_DEFAULT_MIN_WIDTH; - const int barHeight = POPUP_DEFAULT_BAR_HEIGHT; - const int barX = x + (w - barWidth) / 2; - const int barY = y + renderer.getLineHeight(UI_12_FONT_ID) + margin * 2 - 6; - const int textX = x + margin + (contentWidth - textWidth) / 2; renderer.drawText(UI_12_FONT_ID, textX, y + margin, message, true, EpdFontFamily::BOLD); renderer.displayBuffer(); - return {x, y, w, h, barX, barY, barWidth, barHeight}; + return {x, y, w, h}; } void ScreenComponents::fillPopupProgress(const GfxRenderer& renderer, const PopupLayout& layout, const int progress) { - int fillWidth = layout.barWidth * progress / 100; + const int barWidth = POPUP_DEFAULT_MIN_WIDTH; + const int barHeight = POPUP_DEFAULT_BAR_HEIGHT; + const int barX = layout.x + (layout.width - barWidth) / 2; + const int barY = layout.y + layout.height - 16; // 16 pixels above bottom of popup + + int fillWidth = barWidth * progress / 100; if (fillWidth < 0) { fillWidth = 0; - } else if (fillWidth > layout.barWidth) { - fillWidth = layout.barWidth; + } else if (fillWidth > barWidth) { + fillWidth = barWidth; } if (fillWidth > 2) { - renderer.fillRect(layout.barX + 1, layout.barY + 1, fillWidth - 2, layout.barHeight - 2, true); + renderer.fillRect(barX + 1, barY + 1, fillWidth - 2, barHeight - 2, true); } renderer.displayBuffer(EInkDisplay::FAST_REFRESH); } diff --git a/src/ScreenComponents.h b/src/ScreenComponents.h index 45448b1..eb7c272 100644 --- a/src/ScreenComponents.h +++ b/src/ScreenComponents.h @@ -16,11 +16,6 @@ class ScreenComponents { int y; int width; int height; - - int barX; - int barY; - int barWidth; - int barHeight; }; static void drawBattery(const GfxRenderer& renderer, int left, int top, bool showPercentage = true); From e23091a109ab2b3e9e516f901a1be28b246ed504 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Tue, 20 Jan 2026 09:28:37 +0500 Subject: [PATCH 5/6] clang format fix --- src/ScreenComponents.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ScreenComponents.cpp b/src/ScreenComponents.cpp index d2ba807..80a0e1e 100644 --- a/src/ScreenComponents.cpp +++ b/src/ScreenComponents.cpp @@ -64,7 +64,7 @@ void ScreenComponents::fillPopupProgress(const GfxRenderer& renderer, const Popu const int barWidth = POPUP_DEFAULT_MIN_WIDTH; const int barHeight = POPUP_DEFAULT_BAR_HEIGHT; const int barX = layout.x + (layout.width - barWidth) / 2; - const int barY = layout.y + layout.height - 16; // 16 pixels above bottom of popup + const int barY = layout.y + layout.height - 16; // 16 pixels above bottom of popup int fillWidth = barWidth * progress / 100; if (fillWidth < 0) { From 93ce00aed90f904d62c3a32699c609a4e3adc006 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Wed, 21 Jan 2026 22:12:48 +0500 Subject: [PATCH 6/6] clang format fix --- src/ScreenComponents.cpp | 152 +++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/src/ScreenComponents.cpp b/src/ScreenComponents.cpp index 2a8396c..083b77e 100644 --- a/src/ScreenComponents.cpp +++ b/src/ScreenComponents.cpp @@ -79,94 +79,94 @@ void ScreenComponents::fillPopupProgress(const GfxRenderer& renderer, const Popu renderer.displayBuffer(EInkDisplay::FAST_REFRESH); } - int ScreenComponents::drawTabBar(const GfxRenderer& renderer, const int y, const std::vector& tabs) { - constexpr int tabPadding = 20; // Horizontal padding between tabs - constexpr int leftMargin = 20; // Left margin for first tab - constexpr int underlineHeight = 2; // Height of selection underline - constexpr int underlineGap = 4; // Gap between text and underline +int ScreenComponents::drawTabBar(const GfxRenderer& renderer, const int y, const std::vector& tabs) { + constexpr int tabPadding = 20; // Horizontal padding between tabs + constexpr int leftMargin = 20; // Left margin for first tab + constexpr int underlineHeight = 2; // Height of selection underline + constexpr int underlineGap = 4; // Gap between text and underline - const int lineHeight = renderer.getLineHeight(UI_12_FONT_ID); - const int tabBarHeight = lineHeight + underlineGap + underlineHeight; + const int lineHeight = renderer.getLineHeight(UI_12_FONT_ID); + const int tabBarHeight = lineHeight + underlineGap + underlineHeight; - int currentX = leftMargin; + int currentX = leftMargin; - for (const auto& tab : tabs) { - const int textWidth = - renderer.getTextWidth(UI_12_FONT_ID, tab.label, tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR); + for (const auto& tab : tabs) { + const int textWidth = + renderer.getTextWidth(UI_12_FONT_ID, tab.label, tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR); - // Draw tab label - renderer.drawText(UI_12_FONT_ID, currentX, y, tab.label, true, - tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR); + // Draw tab label + renderer.drawText(UI_12_FONT_ID, currentX, y, tab.label, true, + tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR); - // Draw underline for selected tab - if (tab.selected) { - renderer.fillRect(currentX, y + lineHeight + underlineGap, textWidth, underlineHeight); - } - - currentX += textWidth + tabPadding; + // Draw underline for selected tab + if (tab.selected) { + renderer.fillRect(currentX, y + lineHeight + underlineGap, textWidth, underlineHeight); } - return tabBarHeight; + currentX += textWidth + tabPadding; } - void ScreenComponents::drawScrollIndicator(const GfxRenderer& renderer, const int currentPage, const int totalPages, - const int contentTop, const int contentHeight) { - if (totalPages <= 1) { - return; // No need for indicator if only one page - } + return tabBarHeight; +} - const int screenWidth = renderer.getScreenWidth(); - constexpr int indicatorWidth = 20; - constexpr int arrowSize = 6; - constexpr int margin = 15; // Offset from right edge - - const int centerX = screenWidth - indicatorWidth / 2 - margin; - const int indicatorTop = contentTop + 60; // Offset to avoid overlapping side button hints - const int indicatorBottom = contentTop + contentHeight - 30; - - // Draw up arrow at top (^) - narrow point at top, wide base at bottom - for (int i = 0; i < arrowSize; ++i) { - const int lineWidth = 1 + i * 2; - const int startX = centerX - i; - renderer.drawLine(startX, indicatorTop + i, startX + lineWidth - 1, indicatorTop + i); - } - - // Draw down arrow at bottom (v) - wide base at top, narrow point at bottom - for (int i = 0; i < arrowSize; ++i) { - const int lineWidth = 1 + (arrowSize - 1 - i) * 2; - const int startX = centerX - (arrowSize - 1 - i); - renderer.drawLine(startX, indicatorBottom - arrowSize + 1 + i, startX + lineWidth - 1, - indicatorBottom - arrowSize + 1 + i); - } - - // Draw page fraction in the middle (e.g., "1/3") - const std::string pageText = std::to_string(currentPage) + "/" + std::to_string(totalPages); - const int textWidth = renderer.getTextWidth(SMALL_FONT_ID, pageText.c_str()); - const int textX = centerX - textWidth / 2; - const int textY = (indicatorTop + indicatorBottom) / 2 - renderer.getLineHeight(SMALL_FONT_ID) / 2; - - renderer.drawText(SMALL_FONT_ID, textX, textY, pageText.c_str()); +void ScreenComponents::drawScrollIndicator(const GfxRenderer& renderer, const int currentPage, const int totalPages, + const int contentTop, const int contentHeight) { + if (totalPages <= 1) { + return; // No need for indicator if only one page } - void ScreenComponents::drawProgressBar(const GfxRenderer& renderer, const int x, const int y, const int width, - const int height, const size_t current, const size_t total) { - if (total == 0) { - return; - } + const int screenWidth = renderer.getScreenWidth(); + constexpr int indicatorWidth = 20; + constexpr int arrowSize = 6; + constexpr int margin = 15; // Offset from right edge - // Use 64-bit arithmetic to avoid overflow for large files - const int percent = static_cast((static_cast(current) * 100) / total); + const int centerX = screenWidth - indicatorWidth / 2 - margin; + const int indicatorTop = contentTop + 60; // Offset to avoid overlapping side button hints + const int indicatorBottom = contentTop + contentHeight - 30; - // Draw outline - renderer.drawRect(x, y, width, height); - - // Draw filled portion - const int fillWidth = (width - 4) * percent / 100; - if (fillWidth > 0) { - renderer.fillRect(x + 2, y + 2, fillWidth, height - 4); - } - - // Draw percentage text centered below bar - const std::string percentText = std::to_string(percent) + "%"; - renderer.drawCenteredText(UI_10_FONT_ID, y + height + 15, percentText.c_str()); + // Draw up arrow at top (^) - narrow point at top, wide base at bottom + for (int i = 0; i < arrowSize; ++i) { + const int lineWidth = 1 + i * 2; + const int startX = centerX - i; + renderer.drawLine(startX, indicatorTop + i, startX + lineWidth - 1, indicatorTop + i); } + + // Draw down arrow at bottom (v) - wide base at top, narrow point at bottom + for (int i = 0; i < arrowSize; ++i) { + const int lineWidth = 1 + (arrowSize - 1 - i) * 2; + const int startX = centerX - (arrowSize - 1 - i); + renderer.drawLine(startX, indicatorBottom - arrowSize + 1 + i, startX + lineWidth - 1, + indicatorBottom - arrowSize + 1 + i); + } + + // Draw page fraction in the middle (e.g., "1/3") + const std::string pageText = std::to_string(currentPage) + "/" + std::to_string(totalPages); + const int textWidth = renderer.getTextWidth(SMALL_FONT_ID, pageText.c_str()); + const int textX = centerX - textWidth / 2; + const int textY = (indicatorTop + indicatorBottom) / 2 - renderer.getLineHeight(SMALL_FONT_ID) / 2; + + renderer.drawText(SMALL_FONT_ID, textX, textY, pageText.c_str()); +} + +void ScreenComponents::drawProgressBar(const GfxRenderer& renderer, const int x, const int y, const int width, + const int height, const size_t current, const size_t total) { + if (total == 0) { + return; + } + + // Use 64-bit arithmetic to avoid overflow for large files + const int percent = static_cast((static_cast(current) * 100) / total); + + // Draw outline + renderer.drawRect(x, y, width, height); + + // Draw filled portion + const int fillWidth = (width - 4) * percent / 100; + if (fillWidth > 0) { + renderer.fillRect(x + 2, y + 2, fillWidth, height - 4); + } + + // Draw percentage text centered below bar + const std::string percentText = std::to_string(percent) + "%"; + renderer.drawCenteredText(UI_10_FONT_ID, y + height + 15, percentText.c_str()); +}