Wrap up multiple font styles into EpdFontFamily

This commit is contained in:
Dave Allie
2025-12-06 00:34:16 +11:00
parent fa0f27df6a
commit 05a027e2bf
13 changed files with 184 additions and 129 deletions

View File

@@ -89,7 +89,7 @@ void waitForNoButton() {
// Enter deep sleep mode
void enterDeepSleep() {
enterNewScreen(new FullScreenMessageScreen(renderer, "Sleeping", true, false, true));
enterNewScreen(new FullScreenMessageScreen(renderer, "Sleeping", BOLD, true));
Serial.println("Power button released after a long press. Entering deep sleep.");
delay(1000); // Allow Serial buffer to empty and display to update
@@ -137,7 +137,7 @@ void setup() {
display.setTextColor(GxEPD_BLACK);
Serial.println("Display initialized");
enterNewScreen(new FullScreenMessageScreen(renderer, "Booting...", true));
enterNewScreen(new FullScreenMessageScreen(renderer, "Booting...", BOLD));
// SD Card Initialization
SD.begin(SD_SPI_CS, SPI, SPI_FQ);

View File

@@ -134,8 +134,8 @@ void EpubReaderScreen::renderPage() {
const int h = renderer->getLineHeight() + margin * 2;
renderer->fillRect(x, y, w, h, 0);
renderer->drawText(x + margin, y + margin, "Indexing...");
renderer->drawRect(x + 5, y + 5, w - 10, h - 10, 1);
renderer->flushArea(x - 20, y - 20, w + 40, h + 40);
renderer->drawRect(x + 5, y + 5, w - 10, h - 10);
renderer->flushArea(x, y, w, h);
}
section->setupCacheDir();
@@ -199,23 +199,23 @@ void EpubReaderScreen::renderStatusBar() const {
constexpr int y = 772;
// Top line
renderer->drawLine(x, y, x + batteryWidth - 4, y, 1);
renderer->drawLine(x, y, x + batteryWidth - 4, y);
// Bottom line
renderer->drawLine(x, y + batteryHeight - 1, x + batteryWidth - 4, y + batteryHeight - 1, 1);
renderer->drawLine(x, y + batteryHeight - 1, x + batteryWidth - 4, y + batteryHeight - 1);
// Left line
renderer->drawLine(x, y, x, y + batteryHeight - 1, 1);
renderer->drawLine(x, y, x, y + batteryHeight - 1);
// Battery end
renderer->drawLine(x + batteryWidth - 4, y, x + batteryWidth - 4, y + batteryHeight - 1, 1);
renderer->drawLine(x + batteryWidth - 3, y + 2, x + batteryWidth - 3, y + batteryHeight - 3, 1);
renderer->drawLine(x + batteryWidth - 2, y + 2, x + batteryWidth - 2, y + batteryHeight - 3, 1);
renderer->drawLine(x + batteryWidth - 1, y + 2, x + batteryWidth - 1, y + batteryHeight - 3, 1);
renderer->drawLine(x + batteryWidth - 4, y, x + batteryWidth - 4, y + batteryHeight - 1);
renderer->drawLine(x + batteryWidth - 3, y + 2, x + batteryWidth - 3, y + batteryHeight - 3);
renderer->drawLine(x + batteryWidth - 2, y + 2, x + batteryWidth - 2, y + batteryHeight - 3);
renderer->drawLine(x + batteryWidth - 1, y + 2, x + batteryWidth - 1, y + batteryHeight - 3);
// The +1 is to round up, so that we always fill at least one pixel
int filledWidth = percentage * (batteryWidth - 5) / 100 + 1;
if (filledWidth > batteryWidth - 5) {
filledWidth = batteryWidth - 5; // Ensure we don't overflow
}
renderer->fillRect(x + 1, y + 1, filledWidth, batteryHeight - 2, 1);
renderer->fillRect(x + 1, y + 1, filledWidth, batteryHeight - 2);
// Page width minus existing content with 30px padding on each side
const int leftMargin = 20 + percentageTextWidth + 30;

View File

@@ -91,14 +91,14 @@ void FileSelectionScreen::render() const {
renderer->clearScreen();
const auto pageWidth = renderer->getPageWidth();
const auto titleWidth = renderer->getTextWidth("CrossPoint Reader", true);
renderer->drawText((pageWidth - titleWidth) / 2, 0, "CrossPoint Reader", true);
const auto titleWidth = renderer->getTextWidth("CrossPoint Reader", BOLD);
renderer->drawText((pageWidth - titleWidth) / 2, 0, "CrossPoint Reader", 1, BOLD);
if (files.empty()) {
renderer->drawSmallText(50, 50, "No EPUBs found");
} else {
// Draw selection
renderer->fillRect(0, 50 + selectorIndex * 20 + 2, pageWidth - 1, 20, 1);
renderer->fillRect(0, 50 + selectorIndex * 20 + 2, pageWidth - 1, 20);
for (size_t i = 0; i < files.size(); i++) {
const auto file = files[i];

View File

@@ -21,7 +21,7 @@ class FileSelectionScreen final : public Screen {
void render() const;
void loadFiles();
public:
public:
explicit FileSelectionScreen(EpdRenderer* renderer, const std::function<void(const std::string&)>& onSelect)
: Screen(renderer), onSelect(onSelect) {}
void onEnter() override;

View File

@@ -3,13 +3,13 @@
#include <EpdRenderer.h>
void FullScreenMessageScreen::onEnter() {
const auto width = renderer->getTextWidth(text.c_str(), bold, italic);
const auto width = renderer->getTextWidth(text.c_str(), style);
const auto height = renderer->getLineHeight();
const auto left = (renderer->getPageWidth() - width) / 2;
const auto top = (renderer->getPageHeight() - height) / 2;
renderer->clearScreen(invert);
renderer->drawText(left, top, text.c_str(), bold, italic, invert ? 0 : 1);
renderer->drawText(left, top, text.c_str(), invert ? 0 : 1, style);
// If inverted, do a full screen update to ensure no ghosting
renderer->flushDisplay(!invert);
}

View File

@@ -2,17 +2,17 @@
#include <string>
#include <utility>
#include "EpdFontFamily.h"
#include "Screen.h"
class FullScreenMessageScreen final : public Screen {
std::string text;
bool bold;
bool italic;
EpdFontStyle style;
bool invert;
public:
explicit FullScreenMessageScreen(EpdRenderer* renderer, std::string text, const bool bold = false,
const bool italic = false, const bool invert = false)
: Screen(renderer), text(std::move(text)), bold(bold), italic(italic), invert(invert) {}
explicit FullScreenMessageScreen(EpdRenderer* renderer, std::string text, const EpdFontStyle style = REGULAR,
const bool invert = false)
: Screen(renderer), text(std::move(text)), style(style), invert(invert) {}
void onEnter() override;
};