Clang format fix

This commit is contained in:
CaptainFrito 2026-01-24 10:26:55 +07:00
parent 927c3c1f9f
commit a3a9f8a2af
28 changed files with 323 additions and 281 deletions

View File

@ -175,12 +175,15 @@ void GfxRenderer::drawArc(const int maxRadius, const int cx, const int cy, const
}; };
// Border is inside the rectangle, rounded corners // Border is inside the rectangle, rounded corners
void GfxRenderer::drawRoundedRect(const int x, const int y, const int width, const int height, const int lineWidth, const int cornerRadius, bool state) const { void GfxRenderer::drawRoundedRect(const int x, const int y, const int width, const int height, const int lineWidth,
const int cornerRadius, bool state) const {
drawRoundedRect(x, y, width, height, lineWidth, cornerRadius, true, true, true, true, state); drawRoundedRect(x, y, width, height, lineWidth, cornerRadius, true, true, true, true, state);
} }
// Border is inside the rectangle, rounded corners // Border is inside the rectangle, rounded corners
void GfxRenderer::drawRoundedRect(const int x, const int y, const int width, const int height, const int lineWidth, const int cornerRadius, bool roundTopLeft, bool roundTopRight, bool roundBottomLeft, bool roundBottomRight, bool state) const { void GfxRenderer::drawRoundedRect(const int x, const int y, const int width, const int height, const int lineWidth,
const int cornerRadius, bool roundTopLeft, bool roundTopRight, bool roundBottomLeft,
bool roundBottomRight, bool state) const {
if (lineWidth <= 0 || width <= 0 || height <= 0) { if (lineWidth <= 0 || width <= 0 || height <= 0) {
return; return;
} }
@ -281,7 +284,8 @@ void GfxRenderer::fillRectDither(const int x, const int y, const int width, cons
} }
} }
void GfxRenderer::fillArc(const int maxRadius, const int cx, const int cy, const int xDir, const int yDir, Color color) const { void GfxRenderer::fillArc(const int maxRadius, const int cx, const int cy, const int xDir, const int yDir,
Color color) const {
const int radiusSq = maxRadius * maxRadius; const int radiusSq = maxRadius * maxRadius;
for (int dy = 0; dy <= maxRadius; ++dy) { for (int dy = 0; dy <= maxRadius; ++dy) {
for (int dx = 0; dx <= maxRadius; ++dx) { for (int dx = 0; dx <= maxRadius; ++dx) {
@ -295,11 +299,14 @@ void GfxRenderer::fillArc(const int maxRadius, const int cx, const int cy, const
} }
} }
void GfxRenderer::fillRoundedRect(const int x, const int y, const int width, const int height, const int cornerRadius, const Color color) const { void GfxRenderer::fillRoundedRect(const int x, const int y, const int width, const int height, const int cornerRadius,
const Color color) const {
fillRoundedRect(x, y, width, height, cornerRadius, true, true, true, true, color); fillRoundedRect(x, y, width, height, cornerRadius, true, true, true, true, color);
} }
void GfxRenderer::fillRoundedRect(const int x, const int y, const int width, const int height, const int cornerRadius, bool roundTopLeft, bool roundTopRight, bool roundBottomLeft, bool roundBottomRight, const Color color) const { void GfxRenderer::fillRoundedRect(const int x, const int y, const int width, const int height, const int cornerRadius,
bool roundTopLeft, bool roundTopRight, bool roundBottomLeft, bool roundBottomRight,
const Color color) const {
if (width <= 0 || height <= 0) { if (width <= 0 || height <= 0) {
return; return;
} }
@ -330,21 +337,21 @@ void GfxRenderer::fillRoundedRect(const int x, const int y, const int width, con
if (roundTopRight) { if (roundTopRight) {
fillArc(maxRadius, x + width - maxRadius - 1, y + maxRadius, 1, -1, color); fillArc(maxRadius, x + width - maxRadius - 1, y + maxRadius, 1, -1, color);
} else { } else {
fillRectDither(x + width - maxRadius, y, maxRadius, maxRadius, color); fillRectDither(x + width - maxRadius, y, maxRadius, maxRadius, color);
} }
if (roundBottomRight) { if (roundBottomRight) {
fillArc(maxRadius, x + width - maxRadius - 1, y + height - maxRadius - 1, 1, 1, color); fillArc(maxRadius, x + width - maxRadius - 1, y + height - maxRadius - 1, 1, 1, color);
} else { } else {
fillRectDither(x + width - maxRadius, y + height - maxRadius, maxRadius, maxRadius, color); fillRectDither(x + width - maxRadius, y + height - maxRadius, maxRadius, maxRadius, color);
} }
if (roundBottomLeft) { if (roundBottomLeft) {
fillArc(maxRadius, x + maxRadius, y + height - maxRadius - 1, -1, 1, color); fillArc(maxRadius, x + maxRadius, y + height - maxRadius - 1, -1, 1, color);
} else { } else {
fillRectDither(x, y + height - maxRadius, maxRadius, maxRadius, color); fillRectDither(x, y + height - maxRadius, maxRadius, maxRadius, color);
} }
} }
void GfxRenderer::drawImage(const uint8_t bitmap[], const int x, const int y, const int width, const int height) const { void GfxRenderer::drawImage(const uint8_t bitmap[], const int x, const int y, const int width, const int height) const {
// TODO: Rotate bits // TODO: Rotate bits

View File

@ -11,11 +11,11 @@
// 0 = transparent, 1-16 = gray levels (white to black) // 0 = transparent, 1-16 = gray levels (white to black)
using Color = uint8_t; using Color = uint8_t;
constexpr Color COLOR_CLEAR = 0x00; constexpr Color COLOR_CLEAR = 0x00;
constexpr Color COLOR_WHITE = 0x01; constexpr Color COLOR_WHITE = 0x01;
constexpr Color COLOR_LIGHT_GRAY = 0x05; constexpr Color COLOR_LIGHT_GRAY = 0x05;
constexpr Color COLOR_DARK_GRAY = 0x0A; constexpr Color COLOR_DARK_GRAY = 0x0A;
constexpr Color COLOR_BLACK = 0x10; constexpr Color COLOR_BLACK = 0x10;
class GfxRenderer { class GfxRenderer {
public: public:
@ -78,13 +78,15 @@ class GfxRenderer {
void drawLine(int x1, int y1, int x2, int y2, int lineWidth, bool state) const; void drawLine(int x1, int y1, int x2, int y2, int lineWidth, bool state) const;
void drawArc(int maxRadius, int cx, int cy, int xDir, int yDir, int lineWidth, bool state) const; void drawArc(int maxRadius, int cx, int cy, int xDir, int yDir, int lineWidth, bool state) const;
void drawRect(int x, int y, int width, int height, bool state = true) const; void drawRect(int x, int y, int width, int height, bool state = true) const;
void drawRect( int x, int y, int width, int height, int lineWidth, bool state) const; void drawRect(int x, int y, int width, int height, int lineWidth, bool state) const;
void drawRoundedRect(int x, int y, int width, int height, int lineWidth, int cornerRadius, bool state) const; void drawRoundedRect(int x, int y, int width, int height, int lineWidth, int cornerRadius, bool state) const;
void drawRoundedRect(int x, int y, int width, int height, int lineWidth, int cornerRadius, bool roundTopLeft, bool roundTopRight, bool roundBottomLeft, bool roundBottomRight, bool state) const; void drawRoundedRect(int x, int y, int width, int height, int lineWidth, int cornerRadius, bool roundTopLeft,
bool roundTopRight, bool roundBottomLeft, bool roundBottomRight, bool state) const;
void fillRect(int x, int y, int width, int height, bool state = true) const; void fillRect(int x, int y, int width, int height, bool state = true) const;
void fillRectDither(int x, int y, int width, int height, Color color) const; void fillRectDither(int x, int y, int width, int height, Color color) const;
void fillRoundedRect(int x, int y, int width, int height, int cornerRadius, Color color) const; void fillRoundedRect(int x, int y, int width, int height, int cornerRadius, Color color) const;
void fillRoundedRect(int x, int y, int width, int height, int cornerRadius, bool roundTopLeft, bool roundTopRight, bool roundBottomLeft, bool roundBottomRight, Color color) const; void fillRoundedRect(int x, int y, int width, int height, int cornerRadius, bool roundTopLeft, bool roundTopRight,
bool roundBottomLeft, bool roundBottomRight, Color color) const;
void drawImage(const uint8_t bitmap[], int x, int y, int width, int height) const; void drawImage(const uint8_t bitmap[], int x, int y, int width, int height) const;
void drawIcon(const uint8_t bitmap[], int x, int y, int width, int height) const; void drawIcon(const uint8_t bitmap[], int x, int y, int width, int height) const;
void drawBitmap(const Bitmap& bitmap, int x, int y, int maxWidth, int maxHeight, float cropX = 0, void drawBitmap(const Bitmap& bitmap, int x, int y, int maxWidth, int maxHeight, float cropX = 0,

View File

@ -13,10 +13,10 @@
#include "CrossPointSettings.h" #include "CrossPointSettings.h"
#include "CrossPointState.h" #include "CrossPointState.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "RecentBooksStore.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h" #include "fontIds.h"
#include "util/StringUtils.h" #include "util/StringUtils.h"
#include "RecentBooksStore.h"
void HomeActivity::taskTrampoline(void* param) { void HomeActivity::taskTrampoline(void* param) {
auto* self = static_cast<HomeActivity*>(param); auto* self = static_cast<HomeActivity*>(param);
@ -26,7 +26,7 @@ void HomeActivity::taskTrampoline(void* param) {
int HomeActivity::getMenuItemCount() const { int HomeActivity::getMenuItemCount() const {
int count = 3; // My Library, File transfer, Settings int count = 3; // My Library, File transfer, Settings
if (!recentBooks.empty()) { if (!recentBooks.empty()) {
count+= recentBooks.size(); count += recentBooks.size();
} }
if (hasOpdsUrl) { if (hasOpdsUrl) {
count++; count++;
@ -34,7 +34,7 @@ int HomeActivity::getMenuItemCount() const {
return count; return count;
} }
void HomeActivity::loadRecentBooks(int maxBooks) { //}, PopupCallbacks& popupCallbacks) { void HomeActivity::loadRecentBooks(int maxBooks) { //}, PopupCallbacks& popupCallbacks) {
recentsLoading = true; recentsLoading = true;
recentBooks.clear(); recentBooks.clear();
@ -44,10 +44,10 @@ void HomeActivity::loadRecentBooks(int maxBooks) { //}, PopupCallbacks& popupCal
// if (books.size() > 0) { // if (books.size() > 0) {
// popupCallbacks.setup(); // popupCallbacks.setup();
// } // }
for (const auto& path : books) { for (const auto& path : books) {
// popupCallbacks.update(recentBooks.size() * 30); // TODO improve progress calculation // popupCallbacks.update(recentBooks.size() * 30); // TODO improve progress calculation
// Limit to maximum number of recent books // Limit to maximum number of recent books
if (recentBooks.size() >= maxBooks) { if (recentBooks.size() >= maxBooks) {
break; break;
@ -245,7 +245,7 @@ void HomeActivity::displayTaskLoop() {
void HomeActivity::render() { void HomeActivity::render() {
auto metrics = UITheme::getMetrics(); auto metrics = UITheme::getMetrics();
bool bufferRestored = coverBufferStored && restoreCoverBuffer(); bool bufferRestored = coverBufferStored && restoreCoverBuffer();
if (!bufferRestored || !firstRenderDone) { if (!bufferRestored || !firstRenderDone) {
renderer.clearScreen(); renderer.clearScreen();
@ -258,16 +258,13 @@ void HomeActivity::render() {
if (hasContinueReading) { if (hasContinueReading) {
if (recentsLoaded) { if (recentsLoaded) {
UITheme::drawRecentBookCover(renderer, UITheme::drawRecentBookCover(renderer, Rect{0, metrics.homeTopPadding, pageWidth, metrics.homeCoverHeight},
Rect{0, metrics.homeTopPadding, pageWidth, metrics.homeCoverHeight}, recentBooks, selectorIndex, coverRendered, coverBufferStored, bufferRestored,
recentBooks, selectorIndex, std::bind(&HomeActivity::storeCoverBuffer, this));
coverRendered, coverBufferStored, bufferRestored,
std::bind(&HomeActivity::storeCoverBuffer, this)
);
} else if (!recentsLoading && firstRenderDone) { } else if (!recentsLoading && firstRenderDone) {
recentsLoading = true; recentsLoading = true;
// PopupCallbacks popupCallbacks = UITheme::drawPopupWithProgress(renderer, "Loading..."); // PopupCallbacks popupCallbacks = UITheme::drawPopupWithProgress(renderer, "Loading...");
loadRecentBooks(metrics.homeRecentBooksCount); //, popupCallbacks); loadRecentBooks(metrics.homeRecentBooksCount); //, popupCallbacks);
} }
} }
@ -277,12 +274,14 @@ void HomeActivity::render() {
// Insert Calibre Library after Browse Files // Insert Calibre Library after Browse Files
menuItems.insert(menuItems.begin() + 1, "Calibre Library"); menuItems.insert(menuItems.begin() + 1, "Calibre Library");
} }
UITheme::drawButtonMenu( UITheme::drawButtonMenu(
renderer, Rect{0, metrics.homeTopPadding + metrics.homeCoverHeight + metrics.verticalSpacing, pageWidth, pageHeight - (metrics.headerHeight + metrics.homeTopPadding + metrics.verticalSpacing * 2 + metrics.buttonHintsHeight)}, renderer,
static_cast<int>(menuItems.size()), Rect{0, metrics.homeTopPadding + metrics.homeCoverHeight + metrics.verticalSpacing, pageWidth,
selectorIndex - recentBooks.size(), [&menuItems](int index) { return std::string(menuItems[index]); }, pageHeight - (metrics.headerHeight + metrics.homeTopPadding + metrics.verticalSpacing * 2 +
false, nullptr); metrics.buttonHintsHeight)},
static_cast<int>(menuItems.size()), selectorIndex - recentBooks.size(),
[&menuItems](int index) { return std::string(menuItems[index]); }, false, nullptr);
const auto labels = mappedInput.mapLabels("", "Select", "Up", "Down"); const auto labels = mappedInput.mapLabels("", "Select", "Up", "Down");
UITheme::drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); UITheme::drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);

View File

@ -31,21 +31,22 @@ class HomeActivity final : public Activity {
const std::function<void()> onSettingsOpen; const std::function<void()> onSettingsOpen;
const std::function<void()> onFileTransferOpen; const std::function<void()> onFileTransferOpen;
const std::function<void()> onOpdsBrowserOpen; const std::function<void()> onOpdsBrowserOpen;
static void taskTrampoline(void* param); static void taskTrampoline(void* param);
[[noreturn]] void displayTaskLoop(); [[noreturn]] void displayTaskLoop();
void render(); void render();
int getMenuItemCount() const; int getMenuItemCount() const;
bool storeCoverBuffer(); // Store frame buffer for cover image bool storeCoverBuffer(); // Store frame buffer for cover image
bool restoreCoverBuffer(); // Restore frame buffer from stored cover bool restoreCoverBuffer(); // Restore frame buffer from stored cover
void freeCoverBuffer(); // Free the stored cover buffer void freeCoverBuffer(); // Free the stored cover buffer
void loadRecentBooks(int maxBooks); //, PopupCallbacks& popupCallbacks); void loadRecentBooks(int maxBooks); //, PopupCallbacks& popupCallbacks);
public: public:
explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, explicit HomeActivity(
const std::function<void(const std::string& path, MyLibraryActivity::Tab fromTab)>& onSelectBook, const std::function<void()>& onMyLibraryOpen, GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void()>& onSettingsOpen, const std::function<void()>& onFileTransferOpen, const std::function<void(const std::string& path, MyLibraryActivity::Tab fromTab)>& onSelectBook,
const std::function<void()>& onOpdsBrowserOpen) const std::function<void()>& onMyLibraryOpen, const std::function<void()>& onSettingsOpen,
const std::function<void()>& onFileTransferOpen, const std::function<void()>& onOpdsBrowserOpen)
: Activity("Home", renderer, mappedInput), : Activity("Home", renderer, mappedInput),
onSelectBook(onSelectBook), onSelectBook(onSelectBook),
onMyLibraryOpen(onMyLibraryOpen), onMyLibraryOpen(onMyLibraryOpen),

View File

@ -5,9 +5,9 @@
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "RecentBooksStore.h" #include "RecentBooksStore.h"
#include "components/UITheme.h"
#include "fontIds.h" #include "fontIds.h"
#include "util/StringUtils.h" #include "util/StringUtils.h"
#include "components/UITheme.h"
namespace { namespace {
constexpr int SKIP_PAGE_MS = 700; constexpr int SKIP_PAGE_MS = 700;
@ -134,7 +134,8 @@ void MyLibraryActivity::onExit() {
void MyLibraryActivity::loop() { void MyLibraryActivity::loop() {
// Long press BACK (1s+) goes to root folder // Long press BACK (1s+) goes to root folder
if (currentTab == Tab::Files && mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= GO_HOME_MS) { if (currentTab == Tab::Files && mappedInput.isPressed(MappedInputManager::Button::Back) &&
mappedInput.getHeldTime() >= GO_HOME_MS) {
if (basepath != "/") { if (basepath != "/") {
basepath = "/"; basepath = "/";
loadFiles(); loadFiles();
@ -172,8 +173,8 @@ void MyLibraryActivity::loop() {
onSelectBook(basepath + files[selectorIndex], currentTab); onSelectBook(basepath + files[selectorIndex], currentTab);
} }
} }
} }
if (mappedInput.wasReleased(MappedInputManager::Button::Back)) { if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
// Short press: go up one directory, or go home if at root // Short press: go up one directory, or go home if at root
if (mappedInput.getHeldTime() < GO_HOME_MS) { if (mappedInput.getHeldTime() < GO_HOME_MS) {
@ -193,8 +194,8 @@ void MyLibraryActivity::loop() {
onGoHome(); onGoHome();
} }
} }
} }
// Tab switching: Left/Right always control tabs // Tab switching: Left/Right always control tabs
if (leftReleased || rightReleased) { if (leftReleased || rightReleased) {
if (currentTab == Tab::Files) { if (currentTab == Tab::Files) {
@ -244,9 +245,9 @@ void MyLibraryActivity::render() const {
auto folderName = basepath == "/" ? "SD card" : basepath.substr(basepath.rfind('/') + 1).c_str(); auto folderName = basepath == "/" ? "SD card" : basepath.substr(basepath.rfind('/') + 1).c_str();
UITheme::drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, folderName); UITheme::drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, folderName);
UITheme::drawTabBar(renderer, Rect{0, metrics.topPadding + metrics.headerHeight, pageWidth, metrics.tabBarHeight}, UITheme::drawTabBar(renderer, Rect{0, metrics.topPadding + metrics.headerHeight, pageWidth, metrics.tabBarHeight},
{{"Recent", currentTab == Tab::Recent}, {"Files", currentTab == Tab::Files}}); {{"Recent", currentTab == Tab::Recent}, {"Files", currentTab == Tab::Files}});
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing; const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing;
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2;
@ -255,24 +256,20 @@ void MyLibraryActivity::render() const {
if (bookTitles.empty()) { if (bookTitles.empty()) {
renderer.drawText(UI_10_FONT_ID, metrics.contentSidePadding, contentTop + 20, "No recent books"); renderer.drawText(UI_10_FONT_ID, metrics.contentSidePadding, contentTop + 20, "No recent books");
} else { } else {
UITheme::drawList(renderer, UITheme::drawList(
Rect{0, contentTop, pageWidth, contentHeight}, renderer, Rect{0, contentTop, pageWidth, contentHeight}, bookTitles.size(), selectorIndex,
bookTitles.size(), selectorIndex, [this](int index) { return bookTitles[index]; }, [this](int index) { return bookTitles[index]; }, false, nullptr, false, nullptr);
false, nullptr,
false, nullptr);
} }
} else { } else {
if (files.empty()) { if (files.empty()) {
renderer.drawText(UI_10_FONT_ID, metrics.contentSidePadding, contentTop + 20, "No books found"); renderer.drawText(UI_10_FONT_ID, metrics.contentSidePadding, contentTop + 20, "No books found");
} else { } else {
UITheme::drawList(renderer, UITheme::drawList(
Rect{0, contentTop, pageWidth, contentHeight}, renderer, Rect{0, contentTop, pageWidth, contentHeight}, files.size(), selectorIndex,
files.size(), selectorIndex, [this](int index) { return files[index]; }, [this](int index) { return files[index]; }, false, nullptr, false, nullptr);
false, nullptr,
false, nullptr);
} }
} }
// Help text // Help text
const auto labels = mappedInput.mapLabels("« Home", "Open", "Up", "Down"); const auto labels = mappedInput.mapLabels("« Home", "Open", "Up", "Down");
UITheme::drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); UITheme::drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);

View File

@ -16,7 +16,7 @@ class MyLibraryActivity final : public Activity {
private: private:
TaskHandle_t displayTaskHandle = nullptr; TaskHandle_t displayTaskHandle = nullptr;
SemaphoreHandle_t renderingMutex = nullptr; SemaphoreHandle_t renderingMutex = nullptr;
Tab currentTab = Tab::Recent; Tab currentTab = Tab::Recent;
size_t selectorIndex = 0; size_t selectorIndex = 0;
bool updateRequired = false; bool updateRequired = false;
@ -44,9 +44,9 @@ class MyLibraryActivity final : public Activity {
public: public:
explicit MyLibraryActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, explicit MyLibraryActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void()>& onGoHome, const std::function<void()>& onGoHome,
const std::function<void(const std::string& path, Tab fromTab)>& onSelectBook, const std::function<void(const std::string& path, Tab fromTab)>& onSelectBook,
Tab initialTab = Tab::Recent, std::string initialPath = "/") Tab initialTab = Tab::Recent, std::string initialPath = "/")
: Activity("MyLibrary", renderer, mappedInput), : Activity("MyLibrary", renderer, mappedInput),
basepath(initialPath.empty() ? "/" : std::move(initialPath)), basepath(initialPath.empty() ? "/" : std::move(initialPath)),
currentTab(initialTab), currentTab(initialTab),

View File

@ -12,8 +12,8 @@
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "NetworkModeSelectionActivity.h" #include "NetworkModeSelectionActivity.h"
#include "WifiSelectionActivity.h" #include "WifiSelectionActivity.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
namespace { namespace {
// AP Mode configuration // AP Mode configuration

View File

@ -3,8 +3,8 @@
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
namespace { namespace {
constexpr int MENU_ITEM_COUNT = 2; constexpr int MENU_ITEM_COUNT = 2;

View File

@ -8,8 +8,8 @@
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "WifiCredentialStore.h" #include "WifiCredentialStore.h"
#include "activities/util/KeyboardEntryActivity.h" #include "activities/util/KeyboardEntryActivity.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
void WifiSelectionActivity::taskTrampoline(void* param) { void WifiSelectionActivity::taskTrampoline(void* param) {
auto* self = static_cast<WifiSelectionActivity*>(param); auto* self = static_cast<WifiSelectionActivity*>(param);

View File

@ -328,7 +328,8 @@ void EpubReaderActivity::renderScreen() {
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, popupCallbacks.setup, popupCallbacks.update)) { viewportHeight, SETTINGS.hyphenationEnabled, popupCallbacks.setup,
popupCallbacks.update)) {
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;
@ -460,7 +461,8 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in
} }
if (showBattery) { if (showBattery) {
UITheme::drawBattery(renderer, Rect{orientedMarginLeft + 1, textY, metrics.batteryWidth, metrics.batteryHeight}, showBatteryPercentage); UITheme::drawBattery(renderer, Rect{orientedMarginLeft + 1, textY, metrics.batteryWidth, metrics.batteryHeight},
showBatteryPercentage);
} }
if (showChapterTitle) { if (showChapterTitle) {

View File

@ -5,8 +5,8 @@
#include "KOReaderCredentialStore.h" #include "KOReaderCredentialStore.h"
#include "KOReaderSyncActivity.h" #include "KOReaderSyncActivity.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
namespace { namespace {
// Time threshold for treating a long press as a page-up/page-down // Time threshold for treating a long press as a page-up/page-down

View File

@ -8,8 +8,8 @@
#include "KOReaderDocumentId.h" #include "KOReaderDocumentId.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "activities/network/WifiSelectionActivity.h" #include "activities/network/WifiSelectionActivity.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
namespace { namespace {
void syncTimeWithNTP() { void syncTimeWithNTP() {

View File

@ -520,7 +520,8 @@ void TxtReaderActivity::renderStatusBar(const int orientedMarginRight, const int
} }
if (showBattery) { if (showBattery) {
UITheme::drawBattery(renderer, Rect{orientedMarginLeft, textY, metrics.batteryWidth, metrics.batteryHeight}, showBatteryPercentage); UITheme::drawBattery(renderer, Rect{orientedMarginLeft, textY, metrics.batteryWidth, metrics.batteryHeight},
showBatteryPercentage);
} }
if (showTitle) { if (showTitle) {

View File

@ -3,8 +3,8 @@
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
namespace { namespace {
constexpr int SKIP_PAGE_MS = 700; constexpr int SKIP_PAGE_MS = 700;

View File

@ -10,8 +10,8 @@
#include "activities/network/CalibreWirelessActivity.h" #include "activities/network/CalibreWirelessActivity.h"
#include "activities/network/WifiSelectionActivity.h" #include "activities/network/WifiSelectionActivity.h"
#include "activities/util/KeyboardEntryActivity.h" #include "activities/util/KeyboardEntryActivity.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
namespace { namespace {
constexpr int MENU_ITEMS = 2; constexpr int MENU_ITEMS = 2;

View File

@ -5,8 +5,8 @@
#include <SDCardManager.h> #include <SDCardManager.h>
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
void ClearCacheActivity::taskTrampoline(void* param) { void ClearCacheActivity::taskTrampoline(void* param) {
auto* self = static_cast<ClearCacheActivity*>(param); auto* self = static_cast<ClearCacheActivity*>(param);

View File

@ -7,8 +7,8 @@
#include "KOReaderSyncClient.h" #include "KOReaderSyncClient.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "activities/network/WifiSelectionActivity.h" #include "activities/network/WifiSelectionActivity.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
void KOReaderAuthActivity::taskTrampoline(void* param) { void KOReaderAuthActivity::taskTrampoline(void* param) {
auto* self = static_cast<KOReaderAuthActivity*>(param); auto* self = static_cast<KOReaderAuthActivity*>(param);

View File

@ -8,8 +8,8 @@
#include "KOReaderCredentialStore.h" #include "KOReaderCredentialStore.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "activities/util/KeyboardEntryActivity.h" #include "activities/util/KeyboardEntryActivity.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
namespace { namespace {
constexpr int MENU_ITEMS = 5; constexpr int MENU_ITEMS = 5;

View File

@ -5,9 +5,9 @@
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "activities/network/WifiSelectionActivity.h" #include "activities/network/WifiSelectionActivity.h"
#include "components/UITheme.h"
#include "fontIds.h" #include "fontIds.h"
#include "network/OtaUpdater.h" #include "network/OtaUpdater.h"
#include "components/UITheme.h"
void OtaUpdateActivity::taskTrampoline(void* param) { void OtaUpdateActivity::taskTrampoline(void* param) {
auto* self = static_cast<OtaUpdateActivity*>(param); auto* self = static_cast<OtaUpdateActivity*>(param);

View File

@ -3,16 +3,14 @@
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include "CrossPointSettings.h"
#include "MappedInputManager.h"
#include "fontIds.h"
#include "components/UITheme.h"
#include "CalibreSettingsActivity.h" #include "CalibreSettingsActivity.h"
#include "ClearCacheActivity.h" #include "ClearCacheActivity.h"
#include "CrossPointSettings.h" #include "CrossPointSettings.h"
#include "KOReaderSettingsActivity.h" #include "KOReaderSettingsActivity.h"
#include "MappedInputManager.h"
#include "OtaUpdateActivity.h" #include "OtaUpdateActivity.h"
#include "components/UITheme.h"
#include "fontIds.h"
const char* SettingsActivity::categoryNames[categoryCount] = {"Display", "Reader", "Controls", "System"}; const char* SettingsActivity::categoryNames[categoryCount] = {"Display", "Reader", "Controls", "System"};
@ -26,7 +24,7 @@ const SettingInfo displaySettings[displaySettingsCount] = {
SettingInfo::Enum("Hide Battery %", &CrossPointSettings::hideBatteryPercentage, {"Never", "In Reader", "Always"}), SettingInfo::Enum("Hide Battery %", &CrossPointSettings::hideBatteryPercentage, {"Never", "In Reader", "Always"}),
SettingInfo::Enum("Refresh Frequency", &CrossPointSettings::refreshFrequency, SettingInfo::Enum("Refresh Frequency", &CrossPointSettings::refreshFrequency,
{"1 page", "5 pages", "10 pages", "15 pages", "30 pages"}), {"1 page", "5 pages", "10 pages", "15 pages", "30 pages"}),
SettingInfo::Enum("UI Theme", &CrossPointSettings::uiTheme, {"Classic", "Lyra"}), SettingInfo::Enum("UI Theme", &CrossPointSettings::uiTheme, {"Classic", "Lyra"}),
}; };
constexpr int readerSettingsCount = 9; constexpr int readerSettingsCount = 9;
@ -70,9 +68,9 @@ void SettingsActivity::onEnter() {
renderingMutex = xSemaphoreCreateMutex(); renderingMutex = xSemaphoreCreateMutex();
// Reset selection to first category // Reset selection to first category
selectedCategoryIndex = 0; selectedCategoryIndex = 0;
selectedSettingIndex = 0; selectedSettingIndex = 0;
// Initialize with first category (Display) // Initialize with first category (Display)
settingsList = displaySettings; settingsList = displaySettings;
settingsCount = displaySettingsCount; settingsCount = displaySettingsCount;
@ -256,13 +254,14 @@ void SettingsActivity::render() const {
UITheme::drawTabBar(renderer, Rect{0, metrics.topPadding + metrics.headerHeight, pageWidth, metrics.tabBarHeight}, UITheme::drawTabBar(renderer, Rect{0, metrics.topPadding + metrics.headerHeight, pageWidth, metrics.tabBarHeight},
tabs); tabs);
UITheme::drawList(
UITheme::drawList(renderer, renderer,
Rect{0, metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing, pageWidth, pageHeight - (metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.buttonHintsHeight + metrics.verticalSpacing * 2)}, Rect{0, metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing, pageWidth,
settingsCount, selectedSettingIndex, pageHeight - (metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.buttonHintsHeight +
[this](int index) { return std::string(settingsList[index].name); }, metrics.verticalSpacing * 2)},
false, nullptr, settingsCount, selectedSettingIndex, [this](int index) { return std::string(settingsList[index].name); }, false,
true, [this](int i) { nullptr, true,
[this](int i) {
const auto& setting = settingsList[i]; const auto& setting = settingsList[i];
std::string valueText = ""; std::string valueText = "";
if (settingsList[i].type == SettingType::TOGGLE && settingsList[i].valuePtr != nullptr) { if (settingsList[i].type == SettingType::TOGGLE && settingsList[i].valuePtr != nullptr) {
@ -275,10 +274,12 @@ void SettingsActivity::render() const {
valueText = std::to_string(SETTINGS.*(settingsList[i].valuePtr)); valueText = std::to_string(SETTINGS.*(settingsList[i].valuePtr));
} }
return valueText; return valueText;
}); });
// Draw version text // Draw version text
renderer.drawText(SMALL_FONT_ID, pageWidth - metrics.versionTextRightX - renderer.getTextWidth(SMALL_FONT_ID, CROSSPOINT_VERSION), metrics.versionTextY, CROSSPOINT_VERSION); renderer.drawText(SMALL_FONT_ID,
pageWidth - metrics.versionTextRightX - renderer.getTextWidth(SMALL_FONT_ID, CROSSPOINT_VERSION),
metrics.versionTextY, CROSSPOINT_VERSION);
// Draw help text // Draw help text
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down"); const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");

View File

@ -47,9 +47,9 @@ class SettingsActivity final : public ActivityWithSubactivity {
bool updateRequired = false; bool updateRequired = false;
int selectedCategoryIndex = 0; // Currently selected category int selectedCategoryIndex = 0; // Currently selected category
int selectedSettingIndex = 0; int selectedSettingIndex = 0;
int settingsCount; int settingsCount = 0;
const SettingInfo* settingsList; const SettingInfo* settingsList = nullptr;
const std::function<void()> onGoHome; const std::function<void()> onGoHome;
static constexpr int categoryCount = 4; static constexpr int categoryCount = 4;

View File

@ -1,8 +1,8 @@
#include "KeyboardEntryActivity.h" #include "KeyboardEntryActivity.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "fontIds.h"
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h"
// Keyboard layouts - lowercase // Keyboard layouts - lowercase
const char* const KeyboardEntryActivity::keyboard[NUM_ROWS] = { const char* const KeyboardEntryActivity::keyboard[NUM_ROWS] = {

View File

@ -4,9 +4,9 @@
#include <memory> #include <memory>
#include "RecentBooksStore.h"
#include "components/themes/BaseTheme.h" #include "components/themes/BaseTheme.h"
#include "components/themes/lyra/LyraTheme.h" #include "components/themes/lyra/LyraTheme.h"
#include "RecentBooksStore.h"
std::unique_ptr<BaseTheme> currentTheme = nullptr; std::unique_ptr<BaseTheme> currentTheme = nullptr;
const ThemeMetrics* UITheme::currentMetrics = &BaseMetrics::values; const ThemeMetrics* UITheme::currentMetrics = &BaseMetrics::values;
@ -61,7 +61,8 @@ void UITheme::drawBattery(const GfxRenderer& renderer, Rect rect, bool showPerce
} }
} }
void UITheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3, const char* btn4) { void UITheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
const char* btn4) {
if (currentTheme != nullptr) { if (currentTheme != nullptr) {
currentTheme->drawButtonHints(renderer, btn1, btn2, btn3, btn4); currentTheme->drawButtonHints(renderer, btn1, btn2, btn3, btn4);
} }
@ -94,24 +95,24 @@ void UITheme::drawTabBar(const GfxRenderer& renderer, const Rect rect, const std
} }
} }
void UITheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vector<RecentBookInfo> recentBooks, const int selectorIndex, void UITheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer) { const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
bool& bufferRestored, std::function<bool()> storeCoverBuffer) {
if (currentTheme != nullptr) { if (currentTheme != nullptr) {
currentTheme->drawRecentBookCover(renderer, rect, recentBooks, selectorIndex, coverRendered, coverBufferStored, bufferRestored, storeCoverBuffer); currentTheme->drawRecentBookCover(renderer, rect, recentBooks, selectorIndex, coverRendered, coverBufferStored,
bufferRestored, storeCoverBuffer);
} }
} }
void UITheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex, void UITheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex,
const std::function<std::string(int index)>& buttonLabel, bool hasIcon, const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon) { const std::function<std::string(int index)>& rowIcon) {
if (currentTheme != nullptr) { if (currentTheme != nullptr) {
currentTheme->drawButtonMenu(renderer, rect, buttonCount, selectedIndex, currentTheme->drawButtonMenu(renderer, rect, buttonCount, selectedIndex, buttonLabel, hasIcon, rowIcon);
buttonLabel, hasIcon,
rowIcon);
} }
} }
PopupCallbacks UITheme::drawPopupWithProgress(GfxRenderer& renderer, std::string title) { PopupCallbacks UITheme::drawPopupWithProgress(GfxRenderer& renderer, const std::string& title) {
if (currentTheme != nullptr) { if (currentTheme != nullptr) {
return currentTheme->drawPopupWithProgress(renderer, title); return currentTheme->drawPopupWithProgress(renderer, title);
} }

View File

@ -36,7 +36,7 @@ struct ThemeMetrics {
int listRowHeight; int listRowHeight;
int menuRowHeight; int menuRowHeight;
int menuSpacing; int menuSpacing;
int tabSpacing; int tabSpacing;
int tabBarHeight; int tabBarHeight;
@ -71,7 +71,8 @@ class UITheme {
static void drawProgressBar(const GfxRenderer& renderer, Rect rect, size_t current, size_t total); static void drawProgressBar(const GfxRenderer& renderer, Rect rect, size_t current, size_t total);
static void drawBattery(const GfxRenderer& renderer, Rect rect, bool showPercentage = true); static void drawBattery(const GfxRenderer& renderer, Rect rect, bool showPercentage = true);
static void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3, const char* btn4); static void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
const char* btn4);
static void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn); static void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn);
static void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex, static void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
const std::function<std::string(int index)>& rowTitle, bool hasIcon, const std::function<std::string(int index)>& rowTitle, bool hasIcon,
@ -79,10 +80,11 @@ class UITheme {
const std::function<std::string(int index)>& rowValue); const std::function<std::string(int index)>& rowValue);
static void drawHeader(const GfxRenderer& renderer, Rect rect, const char* title); static void drawHeader(const GfxRenderer& renderer, Rect rect, const char* title);
static void drawTabBar(const GfxRenderer& renderer, Rect rect, const std::vector<TabInfo>& tabs); static void drawTabBar(const GfxRenderer& renderer, Rect rect, const std::vector<TabInfo>& tabs);
static void drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vector<RecentBookInfo> recentBooks, const int selectorIndex, static void drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer); const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
bool& bufferRestored, std::function<bool()> storeCoverBuffer);
static void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex, static void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex,
const std::function<std::string(int index)>& buttonLabel, bool hasIcon, const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon); const std::function<std::string(int index)>& rowIcon);
static PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, std::string title); static PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, const std::string& title);
}; };

View File

@ -1,29 +1,30 @@
#include "BaseTheme.h" #include "BaseTheme.h"
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include <SDCardManager.h>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include "Battery.h" #include "Battery.h"
#include "RecentBooksStore.h"
#include "fontIds.h" #include "fontIds.h"
#include "util/StringUtils.h" #include "util/StringUtils.h"
#include <SDCardManager.h>
#include "RecentBooksStore.h"
// Internal constants // Internal constants
namespace { namespace {
constexpr int batteryPercentSpacing = 4; constexpr int batteryPercentSpacing = 4;
constexpr int homeMenuMargin = 20; constexpr int homeMenuMargin = 20;
constexpr int homeMarginTop = 30; constexpr int homeMarginTop = 30;
} } // namespace
void BaseTheme::drawBattery(const GfxRenderer& renderer, Rect rect, const bool showPercentage) { void BaseTheme::drawBattery(const GfxRenderer& renderer, Rect rect, const bool showPercentage) {
// Left aligned battery icon and percentage // Left aligned battery icon and percentage
// TODO refactor this so the percentage doesnt change after we position it // TODO refactor this so the percentage doesnt change after we position it
const uint16_t percentage = battery.readPercentage(); const uint16_t percentage = battery.readPercentage();
const auto percentageText = showPercentage ? std::to_string(percentage) + "%" : ""; const auto percentageText = showPercentage ? std::to_string(percentage) + "%" : "";
renderer.drawText(SMALL_FONT_ID, rect.x + batteryPercentSpacing + BaseMetrics::values.batteryWidth, rect.y, percentageText.c_str()); renderer.drawText(SMALL_FONT_ID, rect.x + batteryPercentSpacing + BaseMetrics::values.batteryWidth, rect.y,
percentageText.c_str());
// 1 column on left, 2 columns on right, 5 columns of battery body // 1 column on left, 2 columns on right, 5 columns of battery body
const int x = rect.x; const int x = rect.x;
const int y = rect.y + 6; const int y = rect.y + 6;
@ -72,9 +73,8 @@ void BaseTheme::drawProgressBar(const GfxRenderer& renderer, Rect rect, const si
renderer.drawCenteredText(UI_10_FONT_ID, rect.y + rect.height + 15, percentText.c_str()); renderer.drawCenteredText(UI_10_FONT_ID, rect.y + rect.height + 15, percentText.c_str());
} }
void BaseTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3, void BaseTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
const char* btn4) { const char* btn4) {
// TODO: Fix rotated hints // TODO: Fix rotated hints
// const GfxRenderer::Orientation orig_orientation = renderer.getOrientation(); // const GfxRenderer::Orientation orig_orientation = renderer.getOrientation();
// renderer.setOrientation(GfxRenderer::Orientation::Portrait); // renderer.setOrientation(GfxRenderer::Orientation::Portrait);
@ -82,8 +82,8 @@ void BaseTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
const int pageHeight = renderer.getScreenHeight(); const int pageHeight = renderer.getScreenHeight();
constexpr int buttonWidth = 106; constexpr int buttonWidth = 106;
constexpr int buttonHeight = BaseMetrics::values.buttonHintsHeight; constexpr int buttonHeight = BaseMetrics::values.buttonHintsHeight;
constexpr int buttonY = BaseMetrics::values.buttonHintsHeight; // Distance from bottom constexpr int buttonY = BaseMetrics::values.buttonHintsHeight; // Distance from bottom
constexpr int textYOffset = 7; // Distance from top of button to text baseline constexpr int textYOffset = 7; // Distance from top of button to text baseline
constexpr int buttonPositions[] = {25, 130, 245, 350}; constexpr int buttonPositions[] = {25, 130, 245, 350};
const char* labels[] = {btn1, btn2, btn3, btn4}; const char* labels[] = {btn1, btn2, btn3, btn4};
@ -104,9 +104,9 @@ void BaseTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
void BaseTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) { void BaseTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) {
const int screenWidth = renderer.getScreenWidth(); const int screenWidth = renderer.getScreenWidth();
constexpr int buttonWidth = BaseMetrics::values.buttonHintsHeight; // Width on screen (height when rotated) constexpr int buttonWidth = BaseMetrics::values.buttonHintsHeight; // Width on screen (height when rotated)
constexpr int buttonHeight = 80; // Height on screen (width when rotated) constexpr int buttonHeight = 80; // Height on screen (width when rotated)
constexpr int buttonX = 5; // Distance from right edge constexpr int buttonX = 5; // Distance from right edge
// Position for the button group - buttons share a border so they're adjacent // Position for the button group - buttons share a border so they're adjacent
constexpr int topButtonY = 345; // Top button position constexpr int topButtonY = 345; // Top button position
@ -131,8 +131,9 @@ void BaseTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* top
if (bottomBtn != nullptr && bottomBtn[0] != '\0') { if (bottomBtn != nullptr && bottomBtn[0] != '\0') {
renderer.drawLine(x, topButtonY + buttonHeight, x, topButtonY + 2 * buttonHeight - 1); // Left renderer.drawLine(x, topButtonY + buttonHeight, x, topButtonY + 2 * buttonHeight - 1); // Left
renderer.drawLine(x + buttonWidth - 1, topButtonY + buttonHeight, x + buttonWidth - 1, renderer.drawLine(x + buttonWidth - 1, topButtonY + buttonHeight, x + buttonWidth - 1,
topButtonY + 2 * buttonHeight - 1); // Right topButtonY + 2 * buttonHeight - 1); // Right
renderer.drawLine(x, topButtonY + 2 * buttonHeight - 1, x + buttonWidth - 1, topButtonY + 2 * buttonHeight - 1); // Bottom renderer.drawLine(x, topButtonY + 2 * buttonHeight - 1, x + buttonWidth - 1,
topButtonY + 2 * buttonHeight - 1); // Bottom
} }
// Draw text for each button // Draw text for each button
@ -168,11 +169,14 @@ void BaseTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
const int scrollBarY = rect.y + ((rect.height - scrollBarHeight) * currentPage) / (totalPages - 1); const int scrollBarY = rect.y + ((rect.height - scrollBarHeight) * currentPage) / (totalPages - 1);
const int scrollBarX = rect.x + rect.width - BaseMetrics::values.scrollBarRightOffset; const int scrollBarX = rect.x + rect.width - BaseMetrics::values.scrollBarRightOffset;
renderer.drawLine(scrollBarX, rect.y, scrollBarX, rect.y + rect.height, true); renderer.drawLine(scrollBarX, rect.y, scrollBarX, rect.y + rect.height, true);
renderer.fillRect(scrollBarX - BaseMetrics::values.scrollBarWidth, scrollBarY, BaseMetrics::values.scrollBarWidth, scrollBarHeight, true); renderer.fillRect(scrollBarX - BaseMetrics::values.scrollBarWidth, scrollBarY, BaseMetrics::values.scrollBarWidth,
scrollBarHeight, true);
} }
// Draw selection // Draw selection
int contentWidth = rect.width - (totalPages > 1 ? (BaseMetrics::values.scrollBarWidth + BaseMetrics::values.scrollBarRightOffset) : 1); int contentWidth =
rect.width -
(totalPages > 1 ? (BaseMetrics::values.scrollBarWidth + BaseMetrics::values.scrollBarRightOffset) : 1);
renderer.fillRect(0, rect.y + selectedIndex % pageItems * rowHeight - 2, contentWidth, rowHeight); renderer.fillRect(0, rect.y + selectedIndex % pageItems * rowHeight - 2, contentWidth, rowHeight);
// Draw all items // Draw all items
const auto pageStartIndex = selectedIndex / pageItems * pageItems; const auto pageStartIndex = selectedIndex / pageItems * pageItems;
@ -182,27 +186,32 @@ void BaseTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
// Draw name // Draw name
auto itemName = rowTitle(i); auto itemName = rowTitle(i);
auto item = renderer.truncatedText(UI_10_FONT_ID, itemName.c_str(), auto item = renderer.truncatedText(UI_10_FONT_ID, itemName.c_str(),
contentWidth - BaseMetrics::values.contentSidePadding * 2 - (hasValue ? 60 : 0)); // TODO truncate according to value width? contentWidth - BaseMetrics::values.contentSidePadding * 2 -
renderer.drawText(UI_10_FONT_ID, rect.x + BaseMetrics::values.contentSidePadding, itemY, item.c_str(), i != selectedIndex); (hasValue ? 60 : 0)); // TODO truncate according to value width?
renderer.drawText(UI_10_FONT_ID, rect.x + BaseMetrics::values.contentSidePadding, itemY, item.c_str(),
i != selectedIndex);
if (hasValue) { if (hasValue) {
// Draw value // Draw value
std::string valueText = rowValue(i); std::string valueText = rowValue(i);
const auto textWidth = renderer.getTextWidth(UI_10_FONT_ID, valueText.c_str()); const auto textWidth = renderer.getTextWidth(UI_10_FONT_ID, valueText.c_str());
renderer.drawText(UI_10_FONT_ID, contentWidth - BaseMetrics::values.contentSidePadding - textWidth, itemY, valueText.c_str(), i != selectedIndex); renderer.drawText(UI_10_FONT_ID, contentWidth - BaseMetrics::values.contentSidePadding - textWidth, itemY,
valueText.c_str(), i != selectedIndex);
} }
} }
} }
void BaseTheme::drawHeader(const GfxRenderer& renderer, Rect rect, const char* title) { void BaseTheme::drawHeader(const GfxRenderer& renderer, Rect rect, const char* title) {
const bool showBatteryPercentage = SETTINGS.hideBatteryPercentage != CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_ALWAYS; const bool showBatteryPercentage =
SETTINGS.hideBatteryPercentage != CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_ALWAYS;
int batteryX = rect.x + rect.width - BaseMetrics::values.contentSidePadding - BaseMetrics::values.batteryWidth; int batteryX = rect.x + rect.width - BaseMetrics::values.contentSidePadding - BaseMetrics::values.batteryWidth;
if (showBatteryPercentage) { if (showBatteryPercentage) {
const uint16_t percentage = battery.readPercentage(); const uint16_t percentage = battery.readPercentage();
const auto percentageText = std::to_string(percentage) + "%"; const auto percentageText = std::to_string(percentage) + "%";
batteryX -= renderer.getTextWidth(SMALL_FONT_ID, percentageText.c_str()); batteryX -= renderer.getTextWidth(SMALL_FONT_ID, percentageText.c_str());
} }
drawBattery(renderer, Rect{batteryX, rect.y + 5, BaseMetrics::values.batteryWidth, BaseMetrics::values.batteryHeight}); drawBattery(renderer,
Rect{batteryX, rect.y + 5, BaseMetrics::values.batteryWidth, BaseMetrics::values.batteryHeight});
if (title) { if (title) {
renderer.drawCenteredText(UI_12_FONT_ID, rect.y + 5, title, true, EpdFontFamily::BOLD); renderer.drawCenteredText(UI_12_FONT_ID, rect.y + 5, title, true, EpdFontFamily::BOLD);
@ -236,10 +245,9 @@ void BaseTheme::drawTabBar(const GfxRenderer& renderer, const Rect rect, const s
// Draw the "Recent Book" cover card on the home screen // Draw the "Recent Book" cover card on the home screen
// TODO: Refactor method to make it cleaner, split into smaller methods // TODO: Refactor method to make it cleaner, split into smaller methods
void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
std::vector<RecentBookInfo> recentBooks, const int selectorIndex, const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer bool& bufferRestored, std::function<bool()> storeCoverBuffer) {
) {
// --- Top "book" card for the current title (selectorIndex == 0) --- // --- Top "book" card for the current title (selectorIndex == 0) ---
const int bookWidth = rect.width / 2; const int bookWidth = rect.width / 2;
const int bookHeight = rect.height; const int bookHeight = rect.height;
@ -349,8 +357,8 @@ void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect,
} }
if (hasContinueReading) { if (hasContinueReading) {
const std::string& lastBookTitle = recentBooks[0].title; const std::string& lastBookTitle = recentBooks[0].title;
const std::string& lastBookAuthor = recentBooks[0].author; const std::string& lastBookAuthor = recentBooks[0].author;
// Invert text colors based on selection state: // Invert text colors based on selection state:
// - With cover: selected = white text on black box, unselected = black text on white box // - With cover: selected = white text on black box, unselected = black text on white box
@ -530,27 +538,31 @@ void BaseTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount
const std::function<std::string(int index)>& buttonLabel, bool hasIcon, const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon) { const std::function<std::string(int index)>& rowIcon) {
for (int i = 0; i < buttonCount; ++i) { for (int i = 0; i < buttonCount; ++i) {
const int tileY = BaseMetrics::values.verticalSpacing + rect.y + static_cast<int>(i) * (BaseMetrics::values.menuRowHeight + BaseMetrics::values.menuSpacing); const int tileY = BaseMetrics::values.verticalSpacing + rect.y +
static_cast<int>(i) * (BaseMetrics::values.menuRowHeight + BaseMetrics::values.menuSpacing);
const bool selected = selectedIndex == i; const bool selected = selectedIndex == i;
if (selected) { if (selected) {
renderer.fillRect(rect.x + BaseMetrics::values.contentSidePadding, tileY, rect.width - BaseMetrics::values.contentSidePadding * 2, BaseMetrics::values.menuRowHeight); renderer.fillRect(rect.x + BaseMetrics::values.contentSidePadding, tileY,
rect.width - BaseMetrics::values.contentSidePadding * 2, BaseMetrics::values.menuRowHeight);
} else { } else {
renderer.drawRect(rect.x + BaseMetrics::values.contentSidePadding, tileY, rect.width - BaseMetrics::values.contentSidePadding * 2, BaseMetrics::values.menuRowHeight); renderer.drawRect(rect.x + BaseMetrics::values.contentSidePadding, tileY,
rect.width - BaseMetrics::values.contentSidePadding * 2, BaseMetrics::values.menuRowHeight);
} }
const char* label = buttonLabel(i).c_str(); const char* label = buttonLabel(i).c_str();
const int textWidth = renderer.getTextWidth(UI_10_FONT_ID, label); const int textWidth = renderer.getTextWidth(UI_10_FONT_ID, label);
const int textX = rect.x + (rect.width - textWidth) / 2; const int textX = rect.x + (rect.width - textWidth) / 2;
const int lineHeight = renderer.getLineHeight(UI_10_FONT_ID); const int lineHeight = renderer.getLineHeight(UI_10_FONT_ID);
const int textY = tileY + (BaseMetrics::values.menuRowHeight - lineHeight) / 2; // vertically centered assuming y is top of text const int textY =
tileY + (BaseMetrics::values.menuRowHeight - lineHeight) / 2; // vertically centered assuming y is top of text
// Invert text when the tile is selected, to contrast with the filled background // Invert text when the tile is selected, to contrast with the filled background
renderer.drawText(UI_10_FONT_ID, textX, textY, label, selectedIndex != i); renderer.drawText(UI_10_FONT_ID, textX, textY, label, selectedIndex != i);
} }
} }
PopupCallbacks BaseTheme::drawPopupWithProgress(GfxRenderer& renderer, std::string title) { PopupCallbacks BaseTheme::drawPopupWithProgress(GfxRenderer& renderer, const std::string& title) {
// Progress bar dimensions // Progress bar dimensions
constexpr int barWidth = 200; constexpr int barWidth = 200;
constexpr int barHeight = 10; constexpr int barHeight = 10;
@ -573,7 +585,8 @@ PopupCallbacks BaseTheme::drawPopupWithProgress(GfxRenderer& renderer, std::stri
renderer.displayBuffer(); renderer.displayBuffer();
// Setup callback - only called for chapters >= 50KB, redraws with progress bar // Setup callback - only called for chapters >= 50KB, redraws with progress bar
auto setup = [this, &renderer, boxXWithBar, boxWidthWithBar, boxHeightWithBar, boxMargin, title, barX, barY, barWidth, barHeight, boxY] { auto setup = [this, &renderer, boxXWithBar, boxWidthWithBar, boxHeightWithBar, boxMargin, title, barX, barY, barWidth,
barHeight, boxY] {
renderer.fillRect(boxXWithBar, boxY, boxWidthWithBar, boxHeightWithBar, false); renderer.fillRect(boxXWithBar, boxY, boxWidthWithBar, boxHeightWithBar, false);
renderer.drawText(UI_12_FONT_ID, boxXWithBar + boxMargin, boxY + boxMargin, title.c_str()); renderer.drawText(UI_12_FONT_ID, boxXWithBar + boxMargin, boxY + boxMargin, title.c_str());
renderer.drawRect(boxXWithBar + 5, boxY + 5, boxWidthWithBar - 10, boxHeightWithBar - 10); renderer.drawRect(boxXWithBar + 5, boxY + 5, boxWidthWithBar - 10, boxHeightWithBar - 10);

View File

@ -13,40 +13,38 @@ struct RecentBookInfo;
// Additional themes can inherit from this and override methods as needed // Additional themes can inherit from this and override methods as needed
namespace BaseMetrics { namespace BaseMetrics {
constexpr ThemeMetrics values = { constexpr ThemeMetrics values = {.batteryWidth = 15,
.batteryWidth = 15, .batteryHeight = 12,
.batteryHeight = 12, .topPadding = 5,
.topPadding = 5, .batteryBarHeight = 20,
.batteryBarHeight = 20, .headerHeight = 45,
.headerHeight = 45, .verticalSpacing = 10,
.verticalSpacing = 10, .contentSidePadding = 20,
.contentSidePadding = 20, .listRowHeight = 30,
.listRowHeight = 30, .menuRowHeight = 45,
.menuRowHeight = 45, .menuSpacing = 8,
.menuSpacing = 8, .tabSpacing = 10,
.tabSpacing = 10, .tabBarHeight = 50,
.tabBarHeight = 50, .scrollBarWidth = 4,
.scrollBarWidth = 4, .scrollBarRightOffset = 5,
.scrollBarRightOffset = 5, .homeTopPadding = 20,
.homeTopPadding = 20, .homeCoverHeight = 400,
.homeCoverHeight = 400, .homeRecentBooksCount = 1,
.homeRecentBooksCount = 1, .buttonHintsHeight = 40,
.buttonHintsHeight = 40, .sideButtonHintsWidth = 20,
.sideButtonHintsWidth = 20, .versionTextRightX = 20,
.versionTextRightX = 20, .versionTextY = 738};
.versionTextY = 738
};
} }
class BaseTheme { class BaseTheme {
public: public:
virtual ~BaseTheme() = default; virtual ~BaseTheme() = default;
// Component drawing methods // Component drawing methods
virtual void drawProgressBar(const GfxRenderer& renderer, Rect rect, size_t current, size_t total); virtual void drawProgressBar(const GfxRenderer& renderer, Rect rect, size_t current, size_t total);
virtual void drawBattery(const GfxRenderer& renderer, Rect rect, bool showPercentage = true); virtual void drawBattery(const GfxRenderer& renderer, Rect rect, bool showPercentage = true);
virtual void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3, const char* btn4); virtual void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
const char* btn4);
virtual void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn); virtual void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn);
virtual void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex, virtual void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
const std::function<std::string(int index)>& rowTitle, bool hasIcon, const std::function<std::string(int index)>& rowTitle, bool hasIcon,
@ -55,10 +53,11 @@ class BaseTheme {
virtual void drawHeader(const GfxRenderer& renderer, Rect rect, const char* title); virtual void drawHeader(const GfxRenderer& renderer, Rect rect, const char* title);
virtual void drawTabBar(const GfxRenderer& renderer, Rect rect, const std::vector<TabInfo>& tabs); virtual void drawTabBar(const GfxRenderer& renderer, Rect rect, const std::vector<TabInfo>& tabs);
virtual void drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vector<RecentBookInfo> recentBooks, const int selectorIndex, virtual void drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer); const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
bool& bufferRestored, std::function<bool()> storeCoverBuffer);
virtual void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex, virtual void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex,
const std::function<std::string(int index)>& buttonLabel, bool hasIcon, const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon); const std::function<std::string(int index)>& rowIcon);
virtual PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, std::string title); virtual PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, const std::string& title);
}; };

View File

@ -1,29 +1,30 @@
#include "LyraTheme.h" #include "LyraTheme.h"
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include <SDCardManager.h>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include "Battery.h" #include "Battery.h"
#include "RecentBooksStore.h"
#include "fontIds.h" #include "fontIds.h"
#include "util/StringUtils.h" #include "util/StringUtils.h"
#include <SDCardManager.h>
#include "RecentBooksStore.h"
// Internal constants // Internal constants
namespace { namespace {
constexpr int batteryPercentSpacing = 4; constexpr int batteryPercentSpacing = 4;
constexpr int hPaddingInSelection = 8; constexpr int hPaddingInSelection = 8;
constexpr int cornerRadius = 6; constexpr int cornerRadius = 6;
constexpr int topHintButtonY = 345; constexpr int topHintButtonY = 345;
} } // namespace
void LyraTheme::drawBattery(const GfxRenderer& renderer, Rect rect, const bool showPercentage) { void LyraTheme::drawBattery(const GfxRenderer& renderer, Rect rect, const bool showPercentage) {
// Left aligned battery icon and percentage // Left aligned battery icon and percentage
const uint16_t percentage = battery.readPercentage(); const uint16_t percentage = battery.readPercentage();
const auto percentageText = showPercentage ? std::to_string(percentage) + "%" : ""; const auto percentageText = showPercentage ? std::to_string(percentage) + "%" : "";
renderer.drawText(SMALL_FONT_ID, rect.x + batteryPercentSpacing + LyraMetrics::values.batteryWidth, rect.y, percentageText.c_str()); renderer.drawText(SMALL_FONT_ID, rect.x + batteryPercentSpacing + LyraMetrics::values.batteryWidth, rect.y,
percentageText.c_str());
// 1 column on left, 2 columns on right, 5 columns of battery body // 1 column on left, 2 columns on right, 5 columns of battery body
const int x = rect.x; const int x = rect.x;
const int y = rect.y + 6; const int y = rect.y + 6;
@ -54,17 +55,20 @@ void LyraTheme::drawBattery(const GfxRenderer& renderer, Rect rect, const bool s
} }
void LyraTheme::drawHeader(const GfxRenderer& renderer, Rect rect, const char* title) { void LyraTheme::drawHeader(const GfxRenderer& renderer, Rect rect, const char* title) {
const bool showBatteryPercentage = SETTINGS.hideBatteryPercentage != CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_ALWAYS; const bool showBatteryPercentage =
SETTINGS.hideBatteryPercentage != CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_ALWAYS;
int batteryX = rect.x + rect.width - LyraMetrics::values.contentSidePadding - LyraMetrics::values.batteryWidth; int batteryX = rect.x + rect.width - LyraMetrics::values.contentSidePadding - LyraMetrics::values.batteryWidth;
if (showBatteryPercentage) { if (showBatteryPercentage) {
const uint16_t percentage = battery.readPercentage(); const uint16_t percentage = battery.readPercentage();
const auto percentageText = std::to_string(percentage) + "%"; const auto percentageText = std::to_string(percentage) + "%";
batteryX -= renderer.getTextWidth(SMALL_FONT_ID, percentageText.c_str()); batteryX -= renderer.getTextWidth(SMALL_FONT_ID, percentageText.c_str());
} }
drawBattery(renderer, Rect{batteryX, rect.y + 10, LyraMetrics::values.batteryWidth, LyraMetrics::values.batteryHeight}); drawBattery(renderer,
Rect{batteryX, rect.y + 10, LyraMetrics::values.batteryWidth, LyraMetrics::values.batteryHeight});
if (title) { if (title) {
renderer.drawText(UI_12_FONT_ID, rect.x + LyraMetrics::values.contentSidePadding, rect.y + LyraMetrics::values.batteryBarHeight + 3, title, true, EpdFontFamily::BOLD); renderer.drawText(UI_12_FONT_ID, rect.x + LyraMetrics::values.contentSidePadding,
rect.y + LyraMetrics::values.batteryBarHeight + 3, title, true, EpdFontFamily::BOLD);
renderer.drawLine(rect.x, rect.y + rect.height - 3, rect.x + rect.width, rect.y + rect.height - 3, 3, true); renderer.drawLine(rect.x, rect.y + rect.height - 3, rect.x + rect.width, rect.y + rect.height - 3, 3, true);
} }
} }
@ -90,9 +94,9 @@ void LyraTheme::drawTabBar(const GfxRenderer& renderer, Rect rect, const std::ve
} }
void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex, void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
const std::function<std::string(int index)>& rowTitle, bool hasIcon, const std::function<std::string(int index)>& rowTitle, bool hasIcon,
const std::function<std::string(int index)>& rowIcon, bool hasValue, const std::function<std::string(int index)>& rowIcon, bool hasValue,
const std::function<std::string(int index)>& rowValue) { const std::function<std::string(int index)>& rowValue) {
int pageItems = rect.height / LyraMetrics::values.listRowHeight; int pageItems = rect.height / LyraMetrics::values.listRowHeight;
const int rowHeight = LyraMetrics::values.listRowHeight; const int rowHeight = LyraMetrics::values.listRowHeight;
@ -106,16 +110,17 @@ void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
const int scrollBarY = rect.y + ((scrollAreaHeight - scrollBarHeight) * currentPage) / (totalPages - 1); const int scrollBarY = rect.y + ((scrollAreaHeight - scrollBarHeight) * currentPage) / (totalPages - 1);
const int scrollBarX = rect.x + rect.width - LyraMetrics::values.scrollBarRightOffset; const int scrollBarX = rect.x + rect.width - LyraMetrics::values.scrollBarRightOffset;
renderer.drawLine(scrollBarX, rect.y, scrollBarX, rect.y + scrollAreaHeight, true); renderer.drawLine(scrollBarX, rect.y, scrollBarX, rect.y + scrollAreaHeight, true);
renderer.fillRect(scrollBarX - LyraMetrics::values.scrollBarWidth, scrollBarY, LyraMetrics::values.scrollBarWidth, scrollBarHeight, true); renderer.fillRect(scrollBarX - LyraMetrics::values.scrollBarWidth, scrollBarY, LyraMetrics::values.scrollBarWidth,
scrollBarHeight, true);
} }
// Draw selection // Draw selection
int contentWidth = rect.width - (totalPages > 1 ? (LyraMetrics::values.scrollBarWidth + LyraMetrics::values.scrollBarRightOffset) : 1); int contentWidth =
renderer.fillRoundedRect(LyraMetrics::values.contentSidePadding, rect.width -
rect.y + selectedIndex % pageItems * rowHeight, (totalPages > 1 ? (LyraMetrics::values.scrollBarWidth + LyraMetrics::values.scrollBarRightOffset) : 1);
contentWidth - LyraMetrics::values.contentSidePadding * 2, renderer.fillRoundedRect(LyraMetrics::values.contentSidePadding, rect.y + selectedIndex % pageItems * rowHeight,
rowHeight, cornerRadius, COLOR_LIGHT_GRAY); contentWidth - LyraMetrics::values.contentSidePadding * 2, rowHeight, cornerRadius,
COLOR_LIGHT_GRAY);
// Draw all items // Draw all items
const auto pageStartIndex = selectedIndex / pageItems * pageItems; const auto pageStartIndex = selectedIndex / pageItems * pageItems;
@ -124,10 +129,13 @@ void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
// Draw name // Draw name
auto itemName = rowTitle(i); auto itemName = rowTitle(i);
auto item = renderer.truncatedText(UI_10_FONT_ID, itemName.c_str(), auto item =
contentWidth - LyraMetrics::values.contentSidePadding * 2 - hPaddingInSelection * 2 - (hasValue ? 60 : 0)); // TODO truncate according to value width? renderer.truncatedText(UI_10_FONT_ID, itemName.c_str(),
renderer.drawText(UI_10_FONT_ID, rect.x + LyraMetrics::values.contentSidePadding + hPaddingInSelection * 2, itemY + 6, item.c_str(), true); contentWidth - LyraMetrics::values.contentSidePadding * 2 - hPaddingInSelection * 2 -
(hasValue ? 60 : 0)); // TODO truncate according to value width?
renderer.drawText(UI_10_FONT_ID, rect.x + LyraMetrics::values.contentSidePadding + hPaddingInSelection * 2,
itemY + 6, item.c_str(), true);
if (hasValue) { if (hasValue) {
// Draw value // Draw value
std::string valueText = rowValue(i); std::string valueText = rowValue(i);
@ -135,18 +143,21 @@ void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
const auto textWidth = renderer.getTextWidth(UI_10_FONT_ID, valueText.c_str()); const auto textWidth = renderer.getTextWidth(UI_10_FONT_ID, valueText.c_str());
if (i == selectedIndex) { if (i == selectedIndex) {
renderer.fillRoundedRect(contentWidth - LyraMetrics::values.contentSidePadding - hPaddingInSelection * 2 - textWidth, renderer.fillRoundedRect(
itemY, textWidth + hPaddingInSelection * 2, rowHeight, cornerRadius, COLOR_BLACK); contentWidth - LyraMetrics::values.contentSidePadding - hPaddingInSelection * 2 - textWidth, itemY,
textWidth + hPaddingInSelection * 2, rowHeight, cornerRadius, COLOR_BLACK);
} }
renderer.drawText(UI_10_FONT_ID, contentWidth - LyraMetrics::values.contentSidePadding - hPaddingInSelection - textWidth, itemY + 6, valueText.c_str(), i != selectedIndex); renderer.drawText(UI_10_FONT_ID,
contentWidth - LyraMetrics::values.contentSidePadding - hPaddingInSelection - textWidth,
itemY + 6, valueText.c_str(), i != selectedIndex);
} }
} }
} }
} }
void LyraTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3, void LyraTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
const char* btn4) { const char* btn4) {
// TODO: Fix rotated hints // TODO: Fix rotated hints
// const GfxRenderer::Orientation orig_orientation = renderer.getOrientation(); // const GfxRenderer::Orientation orig_orientation = renderer.getOrientation();
// renderer.setOrientation(GfxRenderer::Orientation::Portrait); // renderer.setOrientation(GfxRenderer::Orientation::Portrait);
@ -154,8 +165,8 @@ void LyraTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
const int pageHeight = renderer.getScreenHeight(); const int pageHeight = renderer.getScreenHeight();
constexpr int buttonWidth = 80; constexpr int buttonWidth = 80;
constexpr int buttonHeight = LyraMetrics::values.buttonHintsHeight; constexpr int buttonHeight = LyraMetrics::values.buttonHintsHeight;
constexpr int buttonY = LyraMetrics::values.buttonHintsHeight; // Distance from bottom constexpr int buttonY = LyraMetrics::values.buttonHintsHeight; // Distance from bottom
constexpr int textYOffset = 7; // Distance from top of button to text baseline constexpr int textYOffset = 7; // Distance from top of button to text baseline
constexpr int buttonPositions[] = {68, 156, 244, 332}; constexpr int buttonPositions[] = {68, 156, 244, 332};
const char* labels[] = {btn1, btn2, btn3, btn4}; const char* labels[] = {btn1, btn2, btn3, btn4};
@ -164,7 +175,8 @@ void LyraTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
if (labels[i] != nullptr && labels[i][0] != '\0') { if (labels[i] != nullptr && labels[i][0] != '\0') {
const int x = buttonPositions[i]; const int x = buttonPositions[i];
renderer.fillRect(x, pageHeight - buttonY, buttonWidth, buttonHeight, false); renderer.fillRect(x, pageHeight - buttonY, buttonWidth, buttonHeight, false);
renderer.drawRoundedRect(x, pageHeight - buttonY, buttonWidth, buttonHeight, 1, cornerRadius, true, true, false, false, true); renderer.drawRoundedRect(x, pageHeight - buttonY, buttonWidth, buttonHeight, 1, cornerRadius, true, true, false,
false, true);
const int textWidth = renderer.getTextWidth(SMALL_FONT_ID, labels[i]); const int textWidth = renderer.getTextWidth(SMALL_FONT_ID, labels[i]);
const int textX = x + (buttonWidth - 1 - textWidth) / 2; const int textX = x + (buttonWidth - 1 - textWidth) / 2;
renderer.drawText(SMALL_FONT_ID, textX, pageHeight - buttonY + textYOffset, labels[i]); renderer.drawText(SMALL_FONT_ID, textX, pageHeight - buttonY + textYOffset, labels[i]);
@ -176,8 +188,8 @@ void LyraTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
void LyraTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) { void LyraTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) {
const int screenWidth = renderer.getScreenWidth(); const int screenWidth = renderer.getScreenWidth();
constexpr int buttonWidth = LyraMetrics::values.sideButtonHintsWidth; // Width on screen (height when rotated) constexpr int buttonWidth = LyraMetrics::values.sideButtonHintsWidth; // Width on screen (height when rotated)
constexpr int buttonHeight = 80; // Height on screen (width when rotated) constexpr int buttonHeight = 80; // Height on screen (width when rotated)
// Position for the button group - buttons share a border so they're adjacent // Position for the button group - buttons share a border so they're adjacent
const char* labels[] = {topBtn, bottomBtn}; const char* labels[] = {topBtn, bottomBtn};
@ -187,12 +199,14 @@ void LyraTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* top
// Draw top button outline // Draw top button outline
if (topBtn != nullptr && topBtn[0] != '\0') { if (topBtn != nullptr && topBtn[0] != '\0') {
renderer.drawRoundedRect(x, topHintButtonY, buttonWidth, buttonHeight, 1, cornerRadius, true, false, true, false, true); renderer.drawRoundedRect(x, topHintButtonY, buttonWidth, buttonHeight, 1, cornerRadius, true, false, true, false,
true);
} }
// Draw bottom button outline // Draw bottom button outline
if (bottomBtn != nullptr && bottomBtn[0] != '\0') { if (bottomBtn != nullptr && bottomBtn[0] != '\0') {
renderer.drawRoundedRect(x, topHintButtonY + buttonHeight + 5, buttonWidth, buttonHeight, 1, cornerRadius, true, false, true, false, true); renderer.drawRoundedRect(x, topHintButtonY + buttonHeight + 5, buttonWidth, buttonHeight, 1, cornerRadius, true,
false, true, false, true);
} }
// Draw text for each button // Draw text for each button
@ -202,32 +216,30 @@ void LyraTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* top
// Draw rotated text centered in the button // Draw rotated text centered in the button
const int textWidth = renderer.getTextWidth(SMALL_FONT_ID, labels[i]); const int textWidth = renderer.getTextWidth(SMALL_FONT_ID, labels[i]);
const int textHeight = renderer.getTextHeight(SMALL_FONT_ID);
renderer.drawTextRotated90CW(SMALL_FONT_ID, x, y + (buttonHeight + textWidth) / 2, labels[i]); renderer.drawTextRotated90CW(SMALL_FONT_ID, x, y + (buttonHeight + textWidth) / 2, labels[i]);
} }
} }
} }
void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vector<RecentBookInfo> recentBooks, const int selectorIndex, void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
) { bool& bufferRestored, std::function<bool()> storeCoverBuffer) {
const int tileWidth = (rect.width - 2 * LyraMetrics::values.contentSidePadding) / 3; const int tileWidth = (rect.width - 2 * LyraMetrics::values.contentSidePadding) / 3;
const int tileHeight = rect.height; const int tileHeight = rect.height;
const int bookTitleHeight = 53; const int bookTitleHeight = 53;
const int tileY = rect.y; const int tileY = rect.y;
const bool hasContinueReading = !recentBooks.empty(); const bool hasContinueReading = !recentBooks.empty();
// Draw book card regardless, fill with message based on `hasContinueReading` // Draw book card regardless, fill with message based on `hasContinueReading`
// Draw cover image as background if available (inside the box) // Draw cover image as background if available (inside the box)
// Only load from SD on first render, then use stored buffer // Only load from SD on first render, then use stored buffer
if (hasContinueReading) { if (hasContinueReading) {
if (!coverRendered) { if (!coverRendered) {
for (int i = 0; i < std::min(static_cast<int>(recentBooks.size()), LyraMetrics::values.homeRecentBooksCount); i++) { for (int i = 0; i < std::min(static_cast<int>(recentBooks.size()), LyraMetrics::values.homeRecentBooksCount);
std::string& coverBmpPath = recentBooks[i].coverBmpPath; i++) {
Serial.printf("Recent book %d cover path: %s\n", i, coverBmpPath.c_str()); const std::string& coverBmpPath = recentBooks[i].coverBmpPath;
if (coverBmpPath.empty()) { if (coverBmpPath.empty()) {
continue; continue;
} }
@ -239,7 +251,9 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vecto
if (SdMan.openFileForRead("HOME", coverBmpPath, file)) { if (SdMan.openFileForRead("HOME", coverBmpPath, file)) {
Bitmap bitmap(file); Bitmap bitmap(file);
if (bitmap.parseHeaders() == BmpReaderError::Ok) { if (bitmap.parseHeaders() == BmpReaderError::Ok) {
renderer.drawBitmap(bitmap, tileX + hPaddingInSelection, tileY + hPaddingInSelection, tileWidth - 2 * hPaddingInSelection, tileHeight - bookTitleHeight - hPaddingInSelection); renderer.drawBitmap(bitmap, tileX + hPaddingInSelection, tileY + hPaddingInSelection,
tileWidth - 2 * hPaddingInSelection,
tileHeight - bookTitleHeight - hPaddingInSelection);
} }
file.close(); file.close();
} }
@ -253,18 +267,23 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vecto
bool bookSelected = (selectorIndex == i); bool bookSelected = (selectorIndex == i);
int tileX = LyraMetrics::values.contentSidePadding + tileWidth * i; int tileX = LyraMetrics::values.contentSidePadding + tileWidth * i;
auto title = renderer.truncatedText(UI_10_FONT_ID, recentBooks[i].title.c_str(), tileWidth - 2 * hPaddingInSelection); auto title =
renderer.truncatedText(UI_10_FONT_ID, recentBooks[i].title.c_str(), tileWidth - 2 * hPaddingInSelection);
if (bookSelected) { if (bookSelected) {
// Draw selection box // Draw selection box
renderer.fillRoundedRect(tileX, tileY, tileWidth, hPaddingInSelection, cornerRadius, true, true, false, false, COLOR_LIGHT_GRAY); renderer.fillRoundedRect(tileX, tileY, tileWidth, hPaddingInSelection, cornerRadius, true, true, false, false,
renderer.fillRectDither(tileX, tileY + hPaddingInSelection, hPaddingInSelection, tileHeight - hPaddingInSelection, COLOR_LIGHT_GRAY); COLOR_LIGHT_GRAY);
renderer.fillRectDither(tileX + tileWidth - hPaddingInSelection, tileY + hPaddingInSelection, hPaddingInSelection, tileHeight - hPaddingInSelection, COLOR_LIGHT_GRAY); renderer.fillRectDither(tileX, tileY + hPaddingInSelection, hPaddingInSelection,
renderer.fillRoundedRect(tileX, tileY + tileHeight + hPaddingInSelection - bookTitleHeight, tileWidth, bookTitleHeight, cornerRadius, false, false, true, true, COLOR_LIGHT_GRAY); tileHeight - hPaddingInSelection, COLOR_LIGHT_GRAY);
renderer.fillRectDither(tileX + tileWidth - hPaddingInSelection, tileY + hPaddingInSelection,
hPaddingInSelection, tileHeight - hPaddingInSelection, COLOR_LIGHT_GRAY);
renderer.fillRoundedRect(tileX, tileY + tileHeight + hPaddingInSelection - bookTitleHeight, tileWidth,
bookTitleHeight, cornerRadius, false, false, true, true, COLOR_LIGHT_GRAY);
} }
renderer.drawText(UI_10_FONT_ID, tileX + hPaddingInSelection, tileY + tileHeight - bookTitleHeight + hPaddingInSelection + 5, title.c_str(), true); renderer.drawText(UI_10_FONT_ID, tileX + hPaddingInSelection,
tileY + tileHeight - bookTitleHeight + hPaddingInSelection + 5, title.c_str(), true);
} }
} }
} }
@ -273,12 +292,10 @@ void LyraTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount
const std::function<std::string(int index)>& rowIcon) { const std::function<std::string(int index)>& rowIcon) {
for (int i = 0; i < buttonCount; ++i) { for (int i = 0; i < buttonCount; ++i) {
int tileWidth = (rect.width - LyraMetrics::values.contentSidePadding * 2 - LyraMetrics::values.menuSpacing) / 2; int tileWidth = (rect.width - LyraMetrics::values.contentSidePadding * 2 - LyraMetrics::values.menuSpacing) / 2;
Rect tileRect = Rect{ Rect tileRect =
rect.x + LyraMetrics::values.contentSidePadding + (LyraMetrics::values.menuSpacing + tileWidth) * (i % 2), Rect{rect.x + LyraMetrics::values.contentSidePadding + (LyraMetrics::values.menuSpacing + tileWidth) * (i % 2),
rect.y + static_cast<int>(i / 2) * (LyraMetrics::values.menuRowHeight + LyraMetrics::values.menuSpacing), rect.y + static_cast<int>(i / 2) * (LyraMetrics::values.menuRowHeight + LyraMetrics::values.menuSpacing),
tileWidth, tileWidth, LyraMetrics::values.menuRowHeight};
LyraMetrics::values.menuRowHeight
};
const bool selected = selectedIndex == i; const bool selected = selectedIndex == i;

View File

@ -6,47 +6,47 @@ class GfxRenderer;
// Lyra theme metrics (zero runtime cost) // Lyra theme metrics (zero runtime cost)
namespace LyraMetrics { namespace LyraMetrics {
constexpr ThemeMetrics values = { constexpr ThemeMetrics values = {.batteryWidth = 16,
.batteryWidth = 16, .batteryHeight = 12,
.batteryHeight = 12, .topPadding = 5,
.topPadding = 5, .batteryBarHeight = 40,
.batteryBarHeight = 40, .headerHeight = 84,
.headerHeight = 84, .verticalSpacing = 16,
.verticalSpacing = 16, .contentSidePadding = 20,
.contentSidePadding = 20, .listRowHeight = 40,
.listRowHeight = 40, .menuRowHeight = 64,
.menuRowHeight = 64, .menuSpacing = 8,
.menuSpacing = 8, .tabSpacing = 20,
.tabSpacing = 20, .tabBarHeight = 40,
.tabBarHeight = 40, .scrollBarWidth = 4,
.scrollBarWidth = 4, .scrollBarRightOffset = 5,
.scrollBarRightOffset = 5, .homeTopPadding = 56,
.homeTopPadding = 56, .homeCoverHeight = 266,
.homeCoverHeight = 266, .homeRecentBooksCount = 3,
.homeRecentBooksCount = 3, .buttonHintsHeight = 40,
.buttonHintsHeight = 40, .sideButtonHintsWidth = 19,
.sideButtonHintsWidth = 19, .versionTextRightX = 20,
.versionTextRightX = 20, .versionTextY = 55};
.versionTextY = 55
};
} }
class LyraTheme : public BaseTheme { class LyraTheme : public BaseTheme {
public: public:
// Component drawing methods // Component drawing methods
// void drawProgressBar(const GfxRenderer& renderer, Rect rect, size_t current, size_t total) override; // void drawProgressBar(const GfxRenderer& renderer, Rect rect, size_t current, size_t total) override;
void drawBattery(const GfxRenderer& renderer, Rect rect, bool showPercentage = true) override; void drawBattery(const GfxRenderer& renderer, Rect rect, bool showPercentage = true) override;
void drawHeader(const GfxRenderer& renderer, Rect rect, const char* title) override; void drawHeader(const GfxRenderer& renderer, Rect rect, const char* title) override;
void drawTabBar(const GfxRenderer& renderer, Rect rect, const std::vector<TabInfo>& tabs) override; void drawTabBar(const GfxRenderer& renderer, Rect rect, const std::vector<TabInfo>& tabs) override;
void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex, void drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
const std::function<std::string(int index)>& rowTitle, bool hasIcon, const std::function<std::string(int index)>& rowTitle, bool hasIcon,
const std::function<std::string(int index)>& rowIcon, bool hasValue, const std::function<std::string(int index)>& rowIcon, bool hasValue,
const std::function<std::string(int index)>& rowValue) override; const std::function<std::string(int index)>& rowValue) override;
void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3, const char* btn4) override; void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3,
const char* btn4) override;
void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) override; void drawSideButtonHints(const GfxRenderer& renderer, const char* topBtn, const char* bottomBtn) override;
void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex, void drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex,
const std::function<std::string(int index)>& buttonLabel, bool hasIcon, const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon) override; const std::function<std::string(int index)>& rowIcon) override;
void drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vector<RecentBookInfo> recentBooks, const int selectorIndex, void drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer) override; const int selectorIndex, bool& coverRendered, bool& coverBufferStored, bool& bufferRestored,
std::function<bool()> storeCoverBuffer) override;
}; };