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;
} }

View File

@ -80,11 +80,13 @@ class GfxRenderer {
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);
@ -258,12 +258,9 @@ 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...");
@ -279,10 +276,12 @@ void HomeActivity::render() {
} }
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

@ -42,10 +42,11 @@ class HomeActivity final : public Activity {
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();
@ -255,21 +256,17 @@ 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);
} }
} }

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"};
@ -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) {
@ -278,7 +277,9 @@ void SettingsActivity::render() const {
}); });
// 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,8 +47,8 @@ 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;

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,10 +95,12 @@ 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);
} }
} }
@ -105,13 +108,11 @@ void UITheme::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) {
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

@ -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,7 +73,6 @@ 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
@ -132,7 +132,8 @@ void BaseTheme::drawSideButtonHints(const GfxRenderer& renderer, const char* top
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;
@ -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,8 +13,7 @@ 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,
@ -34,19 +33,18 @@ namespace BaseMetrics {
.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,15 +1,15 @@
#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 {
@ -17,13 +17,14 @@ namespace {
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);
} }
} }
@ -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,9 +129,12 @@ 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
@ -135,11 +143,14 @@ 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);
} }
} }
} }
@ -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]);
@ -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,16 +216,15 @@ 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;
@ -222,11 +235,10 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, std::vecto
// 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,8 +6,7 @@ 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,
@ -27,8 +26,7 @@ namespace LyraMetrics {
.buttonHintsHeight = 40, .buttonHintsHeight = 40,
.sideButtonHintsWidth = 19, .sideButtonHintsWidth = 19,
.versionTextRightX = 20, .versionTextRightX = 20,
.versionTextY = 55 .versionTextY = 55};
};
} }
class LyraTheme : public BaseTheme { class LyraTheme : public BaseTheme {
@ -42,11 +40,13 @@ class LyraTheme : public BaseTheme {
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;
}; };