Merge 93ce00aed90f904d62c3a32699c609a4e3adc006 into 3ce11f14ce7bc3ce1f2f040bfb09a9b3d9f87f72
This commit is contained in:
commit
d42ae2e646
@ -123,9 +123,7 @@ bool Section::clearCache() const {
|
|||||||
bool Section::createSectionFile(const int fontId, const float lineCompression, const bool extraParagraphSpacing,
|
bool Section::createSectionFile(const int fontId, const float lineCompression, const bool extraParagraphSpacing,
|
||||||
const uint8_t paragraphAlignment, const uint16_t viewportWidth,
|
const uint8_t paragraphAlignment, const uint16_t viewportWidth,
|
||||||
const uint16_t viewportHeight, const bool hyphenationEnabled,
|
const uint16_t viewportHeight, const bool hyphenationEnabled,
|
||||||
const std::function<void()>& progressSetupFn,
|
|
||||||
const std::function<void(int)>& progressFn) {
|
const std::function<void(int)>& progressFn) {
|
||||||
constexpr uint32_t MIN_SIZE_FOR_PROGRESS = 50 * 1024; // 50KB
|
|
||||||
const auto localPath = epub->getSpineItem(spineIndex).href;
|
const auto localPath = epub->getSpineItem(spineIndex).href;
|
||||||
const auto tmpHtmlPath = epub->getCachePath() + "/.tmp_" + std::to_string(spineIndex) + ".html";
|
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);
|
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)) {
|
if (!SdMan.openFileForWrite("SCT", filePath, file)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,6 @@ class Section {
|
|||||||
bool clearCache() const;
|
bool clearCache() const;
|
||||||
bool createSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, uint8_t paragraphAlignment,
|
bool createSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, uint8_t paragraphAlignment,
|
||||||
uint16_t viewportWidth, uint16_t viewportHeight, bool hyphenationEnabled,
|
uint16_t viewportWidth, uint16_t viewportHeight, bool hyphenationEnabled,
|
||||||
const std::function<void()>& progressSetupFn = nullptr,
|
|
||||||
const std::function<void(int)>& progressFn = nullptr);
|
const std::function<void(int)>& progressFn = nullptr);
|
||||||
std::unique_ptr<Page> loadPageFromSectionFile();
|
std::unique_ptr<Page> loadPageFromSectionFile();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -55,8 +55,6 @@ class GfxRenderer {
|
|||||||
int getScreenWidth() const;
|
int getScreenWidth() const;
|
||||||
int getScreenHeight() const;
|
int getScreenHeight() const;
|
||||||
void displayBuffer(EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH) 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 invertScreen() const;
|
||||||
void clearScreen(uint8_t color = 0xFF) const;
|
void clearScreen(uint8_t color = 0xFF) const;
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,43 @@ void ScreenComponents::drawBattery(const GfxRenderer& renderer, const int left,
|
|||||||
renderer.fillRect(x + 2, y + 2, filledWidth, batteryHeight - 4);
|
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 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};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenComponents::fillPopupProgress(const GfxRenderer& renderer, const PopupLayout& layout, const int progress) {
|
||||||
|
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 > barWidth) {
|
||||||
|
fillWidth = barWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fillWidth > 2) {
|
||||||
|
renderer.fillRect(barX + 1, barY + 1, fillWidth - 2, barHeight - 2, true);
|
||||||
|
}
|
||||||
|
renderer.displayBuffer(EInkDisplay::FAST_REFRESH);
|
||||||
|
}
|
||||||
|
|
||||||
int ScreenComponents::drawTabBar(const GfxRenderer& renderer, const int y, const std::vector<TabInfo>& tabs) {
|
int ScreenComponents::drawTabBar(const GfxRenderer& renderer, const int y, const std::vector<TabInfo>& tabs) {
|
||||||
constexpr int tabPadding = 20; // Horizontal padding between tabs
|
constexpr int tabPadding = 20; // Horizontal padding between tabs
|
||||||
constexpr int leftMargin = 20; // Left margin for first tab
|
constexpr int leftMargin = 20; // Left margin for first tab
|
||||||
|
|||||||
@ -13,8 +13,24 @@ struct TabInfo {
|
|||||||
|
|
||||||
class ScreenComponents {
|
class ScreenComponents {
|
||||||
public:
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
static void drawBattery(const GfxRenderer& renderer, int left, int top, bool showPercentage = true);
|
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 horizontal tab bar with underline indicator for selected tab
|
// Draw a horizontal tab bar with underline indicator for selected tab
|
||||||
// Returns the height of the tab bar (for positioning content below)
|
// Returns the height of the tab bar (for positioning content below)
|
||||||
static int drawTabBar(const GfxRenderer& renderer, int y, const std::vector<TabInfo>& tabs);
|
static int drawTabBar(const GfxRenderer& renderer, int y, const std::vector<TabInfo>& tabs);
|
||||||
|
|||||||
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
void SleepActivity::onEnter() {
|
void SleepActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
renderPopup("Entering Sleep...");
|
|
||||||
|
|
||||||
if (SETTINGS.sleepScreen == CrossPointSettings::SLEEP_SCREEN_MODE::BLANK) {
|
if (SETTINGS.sleepScreen == CrossPointSettings::SLEEP_SCREEN_MODE::BLANK) {
|
||||||
return renderBlankSleepScreen();
|
return renderBlankSleepScreen();
|
||||||
@ -31,20 +30,6 @@ void SleepActivity::onEnter() {
|
|||||||
renderDefaultSleepScreen();
|
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 {
|
void SleepActivity::renderCustomSleepScreen() const {
|
||||||
// Check if we have a /sleep directory
|
// Check if we have a /sleep directory
|
||||||
auto dir = SdMan.open("/sleep");
|
auto dir = SdMan.open("/sleep");
|
||||||
|
|||||||
@ -10,7 +10,6 @@ class SleepActivity final : public Activity {
|
|||||||
void onEnter() override;
|
void onEnter() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void renderPopup(const char* message) const;
|
|
||||||
void renderDefaultSleepScreen() const;
|
void renderDefaultSleepScreen() const;
|
||||||
void renderCustomSleepScreen() const;
|
void renderCustomSleepScreen() const;
|
||||||
void renderCoverSleepScreen() const;
|
void renderCoverSleepScreen() const;
|
||||||
|
|||||||
@ -285,49 +285,15 @@ void EpubReaderActivity::renderScreen() {
|
|||||||
viewportHeight, SETTINGS.hyphenationEnabled)) {
|
viewportHeight, SETTINGS.hyphenationEnabled)) {
|
||||||
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
|
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
|
||||||
|
|
||||||
// Progress bar dimensions
|
pagesUntilFullRefresh = 0;
|
||||||
constexpr int barWidth = 200;
|
const auto popupLayout = ScreenComponents::drawPopup(renderer, "Indexing...");
|
||||||
constexpr int barHeight = 10;
|
const auto progressCallback = [this, popupLayout](int progress) {
|
||||||
constexpr int boxMargin = 20;
|
ScreenComponents::fillPopupProgress(renderer, popupLayout, progress);
|
||||||
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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(),
|
if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(),
|
||||||
SETTINGS.extraParagraphSpacing, SETTINGS.paragraphAlignment, viewportWidth,
|
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());
|
Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis());
|
||||||
section.reset();
|
section.reset();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -192,24 +192,7 @@ void TxtReaderActivity::buildPageIndex() {
|
|||||||
|
|
||||||
Serial.printf("[%lu] [TRS] Building page index for %zu bytes...\n", millis(), fileSize);
|
Serial.printf("[%lu] [TRS] Building page index for %zu bytes...\n", millis(), fileSize);
|
||||||
|
|
||||||
// Progress bar dimensions (matching EpubReaderActivity style)
|
const auto popupLayout = ScreenComponents::drawPopup(renderer, "Indexing...");
|
||||||
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();
|
|
||||||
|
|
||||||
while (offset < fileSize) {
|
while (offset < fileSize) {
|
||||||
std::vector<std::string> tempLines;
|
std::vector<std::string> tempLines;
|
||||||
@ -235,9 +218,7 @@ void TxtReaderActivity::buildPageIndex() {
|
|||||||
lastProgressPercent = progressPercent;
|
lastProgressPercent = progressPercent;
|
||||||
|
|
||||||
// Fill progress bar
|
// Fill progress bar
|
||||||
const int fillWidth = (barWidth - 2) * progressPercent / 100;
|
ScreenComponents::fillPopupProgress(renderer, popupLayout, progressPercent);
|
||||||
renderer.fillRect(barX + 1, barY + 1, fillWidth, barHeight - 2, true);
|
|
||||||
renderer.displayBuffer(EInkDisplay::FAST_REFRESH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yield to other tasks periodically
|
// Yield to other tasks periodically
|
||||||
@ -383,9 +364,6 @@ void TxtReaderActivity::renderScreen() {
|
|||||||
|
|
||||||
// Initialize reader if not done
|
// Initialize reader if not done
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
renderer.clearScreen();
|
|
||||||
renderer.drawCenteredText(UI_12_FONT_ID, 300, "Indexing...", true, EpdFontFamily::BOLD);
|
|
||||||
renderer.displayBuffer();
|
|
||||||
initializeReader();
|
initializeReader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -332,9 +332,6 @@ void setup() {
|
|||||||
|
|
||||||
setupDisplayAndFonts();
|
setupDisplayAndFonts();
|
||||||
|
|
||||||
exitActivity();
|
|
||||||
enterNewActivity(new BootActivity(renderer, mappedInputManager));
|
|
||||||
|
|
||||||
APP_STATE.loadFromFile();
|
APP_STATE.loadFromFile();
|
||||||
RECENT_BOOKS.loadFromFile();
|
RECENT_BOOKS.loadFromFile();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user