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
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);
}
// 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) {
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;
for (int dy = 0; dy <= maxRadius; ++dy) {
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);
}
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) {
return;
}
@ -330,21 +337,21 @@ void GfxRenderer::fillRoundedRect(const int x, const int y, const int width, con
if (roundTopRight) {
fillArc(maxRadius, x + width - maxRadius - 1, y + maxRadius, 1, -1, color);
} else {
fillRectDither(x + width - maxRadius, y, maxRadius, maxRadius, color);
fillRectDither(x + width - maxRadius, y, maxRadius, maxRadius, color);
}
if (roundBottomRight) {
fillArc(maxRadius, x + width - maxRadius - 1, y + height - maxRadius - 1, 1, 1, color);
} else {
fillRectDither(x + width - maxRadius, y + height - maxRadius, maxRadius, maxRadius, color);
fillRectDither(x + width - maxRadius, y + height - maxRadius, maxRadius, maxRadius, color);
}
if (roundBottomLeft) {
fillArc(maxRadius, x + maxRadius, y + height - maxRadius - 1, -1, 1, color);
} 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 {
// TODO: Rotate bits

View File

@ -11,11 +11,11 @@
// 0 = transparent, 1-16 = gray levels (white to black)
using Color = uint8_t;
constexpr Color COLOR_CLEAR = 0x00;
constexpr Color COLOR_WHITE = 0x01;
constexpr Color COLOR_LIGHT_GRAY = 0x05;
constexpr Color COLOR_DARK_GRAY = 0x0A;
constexpr Color COLOR_BLACK = 0x10;
constexpr Color COLOR_CLEAR = 0x00;
constexpr Color COLOR_WHITE = 0x01;
constexpr Color COLOR_LIGHT_GRAY = 0x05;
constexpr Color COLOR_DARK_GRAY = 0x0A;
constexpr Color COLOR_BLACK = 0x10;
class GfxRenderer {
public:
@ -78,13 +78,15 @@ class GfxRenderer {
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 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 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 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, 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 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,

View File

@ -13,10 +13,10 @@
#include "CrossPointSettings.h"
#include "CrossPointState.h"
#include "MappedInputManager.h"
#include "RecentBooksStore.h"
#include "components/UITheme.h"
#include "fontIds.h"
#include "util/StringUtils.h"
#include "RecentBooksStore.h"
void HomeActivity::taskTrampoline(void* param) {
auto* self = static_cast<HomeActivity*>(param);
@ -26,7 +26,7 @@ void HomeActivity::taskTrampoline(void* param) {
int HomeActivity::getMenuItemCount() const {
int count = 3; // My Library, File transfer, Settings
if (!recentBooks.empty()) {
count+= recentBooks.size();
count += recentBooks.size();
}
if (hasOpdsUrl) {
count++;
@ -34,7 +34,7 @@ int HomeActivity::getMenuItemCount() const {
return count;
}
void HomeActivity::loadRecentBooks(int maxBooks) { //}, PopupCallbacks& popupCallbacks) {
void HomeActivity::loadRecentBooks(int maxBooks) { //}, PopupCallbacks& popupCallbacks) {
recentsLoading = true;
recentBooks.clear();
@ -44,10 +44,10 @@ void HomeActivity::loadRecentBooks(int maxBooks) { //}, PopupCallbacks& popupCal
// if (books.size() > 0) {
// popupCallbacks.setup();
// }
for (const auto& path : books) {
// popupCallbacks.update(recentBooks.size() * 30); // TODO improve progress calculation
// Limit to maximum number of recent books
if (recentBooks.size() >= maxBooks) {
break;
@ -245,7 +245,7 @@ void HomeActivity::displayTaskLoop() {
void HomeActivity::render() {
auto metrics = UITheme::getMetrics();
bool bufferRestored = coverBufferStored && restoreCoverBuffer();
if (!bufferRestored || !firstRenderDone) {
renderer.clearScreen();
@ -258,16 +258,13 @@ void HomeActivity::render() {
if (hasContinueReading) {
if (recentsLoaded) {
UITheme::drawRecentBookCover(renderer,
Rect{0, metrics.homeTopPadding, pageWidth, metrics.homeCoverHeight},
recentBooks, selectorIndex,
coverRendered, coverBufferStored, bufferRestored,
std::bind(&HomeActivity::storeCoverBuffer, this)
);
UITheme::drawRecentBookCover(renderer, Rect{0, metrics.homeTopPadding, pageWidth, metrics.homeCoverHeight},
recentBooks, selectorIndex, coverRendered, coverBufferStored, bufferRestored,
std::bind(&HomeActivity::storeCoverBuffer, this));
} else if (!recentsLoading && firstRenderDone) {
recentsLoading = true;
// 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
menuItems.insert(menuItems.begin() + 1, "Calibre Library");
}
UITheme::drawButtonMenu(
renderer, Rect{0, metrics.homeTopPadding + metrics.homeCoverHeight + metrics.verticalSpacing, pageWidth, pageHeight - (metrics.headerHeight + metrics.homeTopPadding + metrics.verticalSpacing * 2 + metrics.buttonHintsHeight)},
static_cast<int>(menuItems.size()),
selectorIndex - recentBooks.size(), [&menuItems](int index) { return std::string(menuItems[index]); },
false, nullptr);
renderer,
Rect{0, metrics.homeTopPadding + metrics.homeCoverHeight + metrics.verticalSpacing, pageWidth,
pageHeight - (metrics.headerHeight + metrics.homeTopPadding + metrics.verticalSpacing * 2 +
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");
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()> onFileTransferOpen;
const std::function<void()> onOpdsBrowserOpen;
static void taskTrampoline(void* param);
[[noreturn]] void displayTaskLoop();
void render();
int getMenuItemCount() const;
bool storeCoverBuffer(); // Store frame buffer for cover image
bool restoreCoverBuffer(); // Restore frame buffer from stored cover
void freeCoverBuffer(); // Free the stored cover buffer
void loadRecentBooks(int maxBooks); //, PopupCallbacks& popupCallbacks);
bool storeCoverBuffer(); // Store frame buffer for cover image
bool restoreCoverBuffer(); // Restore frame buffer from stored cover
void freeCoverBuffer(); // Free the stored cover buffer
void loadRecentBooks(int maxBooks); //, PopupCallbacks& popupCallbacks);
public:
explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void(const std::string& path, MyLibraryActivity::Tab fromTab)>& onSelectBook, const std::function<void()>& onMyLibraryOpen,
const std::function<void()>& onSettingsOpen, const std::function<void()>& onFileTransferOpen,
const std::function<void()>& onOpdsBrowserOpen)
explicit HomeActivity(
GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void(const std::string& path, MyLibraryActivity::Tab fromTab)>& onSelectBook,
const std::function<void()>& onMyLibraryOpen, const std::function<void()>& onSettingsOpen,
const std::function<void()>& onFileTransferOpen, const std::function<void()>& onOpdsBrowserOpen)
: Activity("Home", renderer, mappedInput),
onSelectBook(onSelectBook),
onMyLibraryOpen(onMyLibraryOpen),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -328,7 +328,8 @@ void EpubReaderActivity::renderScreen() {
if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(),
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());
section.reset();
return;
@ -460,7 +461,8 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in
}
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) {

View File

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

View File

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

View File

@ -520,7 +520,8 @@ void TxtReaderActivity::renderStatusBar(const int orientedMarginRight, const int
}
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) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,16 +3,14 @@
#include <GfxRenderer.h>
#include <HardwareSerial.h>
#include "CrossPointSettings.h"
#include "MappedInputManager.h"
#include "fontIds.h"
#include "components/UITheme.h"
#include "CalibreSettingsActivity.h"
#include "ClearCacheActivity.h"
#include "CrossPointSettings.h"
#include "KOReaderSettingsActivity.h"
#include "MappedInputManager.h"
#include "OtaUpdateActivity.h"
#include "components/UITheme.h"
#include "fontIds.h"
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("Refresh Frequency", &CrossPointSettings::refreshFrequency,
{"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;
@ -70,9 +68,9 @@ void SettingsActivity::onEnter() {
renderingMutex = xSemaphoreCreateMutex();
// Reset selection to first category
selectedCategoryIndex = 0;
selectedCategoryIndex = 0;
selectedSettingIndex = 0;
// Initialize with first category (Display)
settingsList = displaySettings;
settingsCount = displaySettingsCount;
@ -256,13 +254,14 @@ void SettingsActivity::render() const {
UITheme::drawTabBar(renderer, Rect{0, metrics.topPadding + metrics.headerHeight, pageWidth, metrics.tabBarHeight},
tabs);
UITheme::drawList(renderer,
Rect{0, metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing, pageWidth, pageHeight - (metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.buttonHintsHeight + metrics.verticalSpacing * 2)},
settingsCount, selectedSettingIndex,
[this](int index) { return std::string(settingsList[index].name); },
false, nullptr,
true, [this](int i) {
UITheme::drawList(
renderer,
Rect{0, metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing, pageWidth,
pageHeight - (metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.buttonHintsHeight +
metrics.verticalSpacing * 2)},
settingsCount, selectedSettingIndex, [this](int index) { return std::string(settingsList[index].name); }, false,
nullptr, true,
[this](int i) {
const auto& setting = settingsList[i];
std::string valueText = "";
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));
}
return valueText;
});
});
// 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
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");

View File

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

View File

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

View File

@ -4,9 +4,9 @@
#include <memory>
#include "RecentBooksStore.h"
#include "components/themes/BaseTheme.h"
#include "components/themes/lyra/LyraTheme.h"
#include "RecentBooksStore.h"
std::unique_ptr<BaseTheme> currentTheme = nullptr;
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) {
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,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer) {
void UITheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
bool& bufferRestored, std::function<bool()> storeCoverBuffer) {
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,
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)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon) {
if (currentTheme != nullptr) {
currentTheme->drawButtonMenu(renderer, rect, buttonCount, selectedIndex,
buttonLabel, hasIcon,
rowIcon);
currentTheme->drawButtonMenu(renderer, rect, buttonCount, selectedIndex, buttonLabel, hasIcon, rowIcon);
}
}
PopupCallbacks UITheme::drawPopupWithProgress(GfxRenderer& renderer, std::string title) {
PopupCallbacks UITheme::drawPopupWithProgress(GfxRenderer& renderer, const std::string& title) {
if (currentTheme != nullptr) {
return currentTheme->drawPopupWithProgress(renderer, title);
}

View File

@ -36,7 +36,7 @@ struct ThemeMetrics {
int listRowHeight;
int menuRowHeight;
int menuSpacing;
int tabSpacing;
int tabBarHeight;
@ -71,7 +71,8 @@ class UITheme {
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 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 drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
const std::function<std::string(int index)>& rowTitle, bool hasIcon,
@ -79,10 +80,11 @@ class UITheme {
const std::function<std::string(int index)>& rowValue);
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 drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vector<RecentBookInfo> recentBooks, const int selectorIndex,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer);
static void drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
bool& bufferRestored, std::function<bool()> storeCoverBuffer);
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)>& rowIcon);
static PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, std::string title);
const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon);
static PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, const std::string& title);
};

View File

@ -1,29 +1,30 @@
#include "BaseTheme.h"
#include <GfxRenderer.h>
#include <SDCardManager.h>
#include <cstdint>
#include <string>
#include "Battery.h"
#include "RecentBooksStore.h"
#include "fontIds.h"
#include "util/StringUtils.h"
#include <SDCardManager.h>
#include "RecentBooksStore.h"
// Internal constants
namespace {
constexpr int batteryPercentSpacing = 4;
constexpr int homeMenuMargin = 20;
constexpr int homeMarginTop = 30;
}
constexpr int batteryPercentSpacing = 4;
constexpr int homeMenuMargin = 20;
constexpr int homeMarginTop = 30;
} // namespace
void BaseTheme::drawBattery(const GfxRenderer& renderer, Rect rect, const bool showPercentage) {
// Left aligned battery icon and percentage
// TODO refactor this so the percentage doesnt change after we position it
// Left aligned battery icon and percentage
// TODO refactor this so the percentage doesnt change after we position it
const uint16_t percentage = battery.readPercentage();
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
const int x = rect.x;
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());
}
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
// const GfxRenderer::Orientation orig_orientation = renderer.getOrientation();
// renderer.setOrientation(GfxRenderer::Orientation::Portrait);
@ -82,8 +82,8 @@ void BaseTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
const int pageHeight = renderer.getScreenHeight();
constexpr int buttonWidth = 106;
constexpr int buttonHeight = BaseMetrics::values.buttonHintsHeight;
constexpr int buttonY = BaseMetrics::values.buttonHintsHeight; // Distance from bottom
constexpr int textYOffset = 7; // Distance from top of button to text baseline
constexpr int buttonY = BaseMetrics::values.buttonHintsHeight; // Distance from bottom
constexpr int textYOffset = 7; // Distance from top of button to text baseline
constexpr int buttonPositions[] = {25, 130, 245, 350};
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) {
const int screenWidth = renderer.getScreenWidth();
constexpr int buttonWidth = BaseMetrics::values.buttonHintsHeight; // Width on screen (height when rotated)
constexpr int buttonHeight = 80; // Height on screen (width when rotated)
constexpr int buttonX = 5; // Distance from right edge
constexpr int buttonWidth = BaseMetrics::values.buttonHintsHeight; // Width on screen (height when rotated)
constexpr int buttonHeight = 80; // Height on screen (width when rotated)
constexpr int buttonX = 5; // Distance from right edge
// Position for the button group - buttons share a border so they're adjacent
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') {
renderer.drawLine(x, topButtonY + buttonHeight, x, topButtonY + 2 * buttonHeight - 1); // Left
renderer.drawLine(x + buttonWidth - 1, topButtonY + buttonHeight, x + buttonWidth - 1,
topButtonY + 2 * buttonHeight - 1); // Right
renderer.drawLine(x, topButtonY + 2 * buttonHeight - 1, x + buttonWidth - 1, topButtonY + 2 * buttonHeight - 1); // Bottom
topButtonY + 2 * buttonHeight - 1); // Right
renderer.drawLine(x, topButtonY + 2 * buttonHeight - 1, x + buttonWidth - 1,
topButtonY + 2 * buttonHeight - 1); // Bottom
}
// 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 scrollBarX = rect.x + rect.width - BaseMetrics::values.scrollBarRightOffset;
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
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);
// Draw all items
const auto pageStartIndex = selectedIndex / pageItems * pageItems;
@ -182,27 +186,32 @@ void BaseTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
// Draw name
auto itemName = rowTitle(i);
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?
renderer.drawText(UI_10_FONT_ID, rect.x + BaseMetrics::values.contentSidePadding, itemY, item.c_str(), i != selectedIndex);
contentWidth - BaseMetrics::values.contentSidePadding * 2 -
(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) {
// Draw value
std::string valueText = rowValue(i);
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) {
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;
if (showBatteryPercentage) {
const uint16_t percentage = battery.readPercentage();
const auto percentageText = std::to_string(percentage) + "%";
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) {
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
// TODO: Refactor method to make it cleaner, split into smaller methods
void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect,
std::vector<RecentBookInfo> recentBooks, const int selectorIndex,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer
) {
void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
bool& bufferRestored, std::function<bool()> storeCoverBuffer) {
// --- Top "book" card for the current title (selectorIndex == 0) ---
const int bookWidth = rect.width / 2;
const int bookHeight = rect.height;
@ -349,8 +357,8 @@ void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect,
}
if (hasContinueReading) {
const std::string& lastBookTitle = recentBooks[0].title;
const std::string& lastBookAuthor = recentBooks[0].author;
const std::string& lastBookTitle = recentBooks[0].title;
const std::string& lastBookAuthor = recentBooks[0].author;
// Invert text colors based on selection state:
// - 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)>& rowIcon) {
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;
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 {
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 int textWidth = renderer.getTextWidth(UI_10_FONT_ID, label);
const int textX = rect.x + (rect.width - textWidth) / 2;
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
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
constexpr int barWidth = 200;
constexpr int barHeight = 10;
@ -573,7 +585,8 @@ PopupCallbacks BaseTheme::drawPopupWithProgress(GfxRenderer& renderer, std::stri
renderer.displayBuffer();
// 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.drawText(UI_12_FONT_ID, boxXWithBar + boxMargin, boxY + boxMargin, title.c_str());
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
namespace BaseMetrics {
constexpr ThemeMetrics values = {
.batteryWidth = 15,
.batteryHeight = 12,
.topPadding = 5,
.batteryBarHeight = 20,
.headerHeight = 45,
.verticalSpacing = 10,
.contentSidePadding = 20,
.listRowHeight = 30,
.menuRowHeight = 45,
.menuSpacing = 8,
.tabSpacing = 10,
.tabBarHeight = 50,
.scrollBarWidth = 4,
.scrollBarRightOffset = 5,
.homeTopPadding = 20,
.homeCoverHeight = 400,
.homeRecentBooksCount = 1,
.buttonHintsHeight = 40,
.sideButtonHintsWidth = 20,
.versionTextRightX = 20,
.versionTextY = 738
};
constexpr ThemeMetrics values = {.batteryWidth = 15,
.batteryHeight = 12,
.topPadding = 5,
.batteryBarHeight = 20,
.headerHeight = 45,
.verticalSpacing = 10,
.contentSidePadding = 20,
.listRowHeight = 30,
.menuRowHeight = 45,
.menuSpacing = 8,
.tabSpacing = 10,
.tabBarHeight = 50,
.scrollBarWidth = 4,
.scrollBarRightOffset = 5,
.homeTopPadding = 20,
.homeCoverHeight = 400,
.homeRecentBooksCount = 1,
.buttonHintsHeight = 40,
.sideButtonHintsWidth = 20,
.versionTextRightX = 20,
.versionTextY = 738};
}
class BaseTheme {
public:
virtual ~BaseTheme() = default;
// Component drawing methods
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 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 drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
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 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,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer);
virtual void drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
const int selectorIndex, bool& coverRendered, bool& coverBufferStored,
bool& bufferRestored, std::function<bool()> storeCoverBuffer);
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)>& rowIcon);
virtual PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, std::string title);
const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon);
virtual PopupCallbacks drawPopupWithProgress(GfxRenderer& renderer, const std::string& title);
};

View File

@ -1,29 +1,30 @@
#include "LyraTheme.h"
#include <GfxRenderer.h>
#include <SDCardManager.h>
#include <cstdint>
#include <string>
#include "Battery.h"
#include "RecentBooksStore.h"
#include "fontIds.h"
#include "util/StringUtils.h"
#include <SDCardManager.h>
#include "RecentBooksStore.h"
// Internal constants
namespace {
constexpr int batteryPercentSpacing = 4;
constexpr int hPaddingInSelection = 8;
constexpr int cornerRadius = 6;
constexpr int topHintButtonY = 345;
}
constexpr int batteryPercentSpacing = 4;
constexpr int hPaddingInSelection = 8;
constexpr int cornerRadius = 6;
constexpr int topHintButtonY = 345;
} // namespace
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 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
const int x = rect.x;
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) {
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;
if (showBatteryPercentage) {
const uint16_t percentage = battery.readPercentage();
const auto percentageText = std::to_string(percentage) + "%";
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) {
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);
}
}
@ -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,
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)>& rowValue) {
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)>& rowValue) {
int pageItems = rect.height / 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 scrollBarX = rect.x + rect.width - LyraMetrics::values.scrollBarRightOffset;
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
int contentWidth = rect.width - (totalPages > 1 ? (LyraMetrics::values.scrollBarWidth + LyraMetrics::values.scrollBarRightOffset) : 1);
renderer.fillRoundedRect(LyraMetrics::values.contentSidePadding,
rect.y + selectedIndex % pageItems * rowHeight,
contentWidth - LyraMetrics::values.contentSidePadding * 2,
rowHeight, cornerRadius, COLOR_LIGHT_GRAY);
int contentWidth =
rect.width -
(totalPages > 1 ? (LyraMetrics::values.scrollBarWidth + LyraMetrics::values.scrollBarRightOffset) : 1);
renderer.fillRoundedRect(LyraMetrics::values.contentSidePadding, rect.y + selectedIndex % pageItems * rowHeight,
contentWidth - LyraMetrics::values.contentSidePadding * 2, rowHeight, cornerRadius,
COLOR_LIGHT_GRAY);
// Draw all items
const auto pageStartIndex = selectedIndex / pageItems * pageItems;
@ -124,10 +129,13 @@ void LyraTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount,
// Draw name
auto itemName = rowTitle(i);
auto item = renderer.truncatedText(UI_10_FONT_ID, itemName.c_str(),
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);
auto item =
renderer.truncatedText(UI_10_FONT_ID, itemName.c_str(),
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) {
// Draw value
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());
if (i == selectedIndex) {
renderer.fillRoundedRect(contentWidth - LyraMetrics::values.contentSidePadding - hPaddingInSelection * 2 - textWidth,
itemY, textWidth + hPaddingInSelection * 2, rowHeight, cornerRadius, COLOR_BLACK);
renderer.fillRoundedRect(
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,
const char* btn4) {
const char* btn4) {
// TODO: Fix rotated hints
// const GfxRenderer::Orientation orig_orientation = renderer.getOrientation();
// renderer.setOrientation(GfxRenderer::Orientation::Portrait);
@ -154,8 +165,8 @@ void LyraTheme::drawButtonHints(const GfxRenderer& renderer, const char* btn1, c
const int pageHeight = renderer.getScreenHeight();
constexpr int buttonWidth = 80;
constexpr int buttonHeight = LyraMetrics::values.buttonHintsHeight;
constexpr int buttonY = LyraMetrics::values.buttonHintsHeight; // Distance from bottom
constexpr int textYOffset = 7; // Distance from top of button to text baseline
constexpr int buttonY = LyraMetrics::values.buttonHintsHeight; // Distance from bottom
constexpr int textYOffset = 7; // Distance from top of button to text baseline
constexpr int buttonPositions[] = {68, 156, 244, 332};
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') {
const int x = buttonPositions[i];
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 textX = x + (buttonWidth - 1 - textWidth) / 2;
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) {
const int screenWidth = renderer.getScreenWidth();
constexpr int buttonWidth = LyraMetrics::values.sideButtonHintsWidth; // Width on screen (height when rotated)
constexpr int buttonHeight = 80; // Height on screen (width when rotated)
constexpr int buttonWidth = LyraMetrics::values.sideButtonHintsWidth; // Width on screen (height 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
const char* labels[] = {topBtn, bottomBtn};
@ -187,12 +199,14 @@ void LyraTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* top
// Draw top button outline
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
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
@ -202,32 +216,30 @@ void LyraTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* top
// Draw rotated text centered in the button
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]);
}
}
}
void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vector<RecentBookInfo> recentBooks, const int selectorIndex,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer
) {
void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
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 tileHeight = rect.height;
const int bookTitleHeight = 53;
const int tileY = rect.y;
const bool hasContinueReading = !recentBooks.empty();
// Draw book card regardless, fill with message based on `hasContinueReading`
// Draw cover image as background if available (inside the box)
// Only load from SD on first render, then use stored buffer
if (hasContinueReading) {
if (!coverRendered) {
for (int i = 0; i < std::min(static_cast<int>(recentBooks.size()), LyraMetrics::values.homeRecentBooksCount); i++) {
std::string& coverBmpPath = recentBooks[i].coverBmpPath;
Serial.printf("Recent book %d cover path: %s\n", i, coverBmpPath.c_str());
for (int i = 0; i < std::min(static_cast<int>(recentBooks.size()), LyraMetrics::values.homeRecentBooksCount);
i++) {
const std::string& coverBmpPath = recentBooks[i].coverBmpPath;
if (coverBmpPath.empty()) {
continue;
}
@ -239,7 +251,9 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vecto
if (SdMan.openFileForRead("HOME", coverBmpPath, file)) {
Bitmap bitmap(file);
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();
}
@ -253,18 +267,23 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vecto
bool bookSelected = (selectorIndex == 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) {
// Draw selection box
renderer.fillRoundedRect(tileX, tileY, tileWidth, hPaddingInSelection, cornerRadius, true, true, false, false, COLOR_LIGHT_GRAY);
renderer.fillRectDither(tileX, tileY + hPaddingInSelection, hPaddingInSelection, 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.fillRoundedRect(tileX, tileY, tileWidth, hPaddingInSelection, cornerRadius, true, true, false, false,
COLOR_LIGHT_GRAY);
renderer.fillRectDither(tileX, tileY + hPaddingInSelection, hPaddingInSelection,
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) {
for (int i = 0; i < buttonCount; ++i) {
int tileWidth = (rect.width - LyraMetrics::values.contentSidePadding * 2 - LyraMetrics::values.menuSpacing) / 2;
Rect tileRect = 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),
tileWidth,
LyraMetrics::values.menuRowHeight
};
Rect tileRect =
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),
tileWidth, LyraMetrics::values.menuRowHeight};
const bool selected = selectedIndex == i;

View File

@ -6,47 +6,47 @@ class GfxRenderer;
// Lyra theme metrics (zero runtime cost)
namespace LyraMetrics {
constexpr ThemeMetrics values = {
.batteryWidth = 16,
.batteryHeight = 12,
.topPadding = 5,
.batteryBarHeight = 40,
.headerHeight = 84,
.verticalSpacing = 16,
.contentSidePadding = 20,
.listRowHeight = 40,
.menuRowHeight = 64,
.menuSpacing = 8,
.tabSpacing = 20,
.tabBarHeight = 40,
.scrollBarWidth = 4,
.scrollBarRightOffset = 5,
.homeTopPadding = 56,
.homeCoverHeight = 266,
.homeRecentBooksCount = 3,
.buttonHintsHeight = 40,
.sideButtonHintsWidth = 19,
.versionTextRightX = 20,
.versionTextY = 55
};
constexpr ThemeMetrics values = {.batteryWidth = 16,
.batteryHeight = 12,
.topPadding = 5,
.batteryBarHeight = 40,
.headerHeight = 84,
.verticalSpacing = 16,
.contentSidePadding = 20,
.listRowHeight = 40,
.menuRowHeight = 64,
.menuSpacing = 8,
.tabSpacing = 20,
.tabBarHeight = 40,
.scrollBarWidth = 4,
.scrollBarRightOffset = 5,
.homeTopPadding = 56,
.homeCoverHeight = 266,
.homeRecentBooksCount = 3,
.buttonHintsHeight = 40,
.sideButtonHintsWidth = 19,
.versionTextRightX = 20,
.versionTextY = 55};
}
class LyraTheme : public BaseTheme {
public:
// 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 drawHeader(const GfxRenderer& renderer, Rect rect, const char* title) 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,
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)>& rowValue) override;
void drawButtonHints(const GfxRenderer& renderer, const char* btn1, const char* btn2, const char* btn3, const char* btn4) override;
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)>& rowValue) 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 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)>& rowIcon) override;
void drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vector<RecentBookInfo> recentBooks, const int selectorIndex,
bool& coverRendered, bool& coverBufferStored, bool& bufferRestored, std::function<bool()> storeCoverBuffer) override;
const std::function<std::string(int index)>& buttonLabel, bool hasIcon,
const std::function<std::string(int index)>& rowIcon) override;
void drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std::vector<RecentBookInfo>& recentBooks,
const int selectorIndex, bool& coverRendered, bool& coverBufferStored, bool& bufferRestored,
std::function<bool()> storeCoverBuffer) override;
};