feat: Add per-book letterbox fill override
Introduce BookSettings utility for per-book settings stored in the book's cache directory (book_settings.bin). Add "Letterbox Fill" option to the EPUB reader menu that cycles Default/Dithered/Solid/None. At sleep time, the per-book override is loaded and takes precedence over the global setting for all book types (EPUB, XTC, TXT). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "../ActivityWithSubactivity.h"
|
||||
#include "util/BookSettings.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
@@ -20,6 +21,7 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
LOOKUP,
|
||||
LOOKED_UP_WORDS,
|
||||
ROTATE_SCREEN,
|
||||
LETTERBOX_FILL,
|
||||
SELECT_CHAPTER,
|
||||
GO_TO_BOOKMARK,
|
||||
GO_TO_PERCENT,
|
||||
@@ -32,18 +34,23 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title,
|
||||
const int currentPage, const int totalPages, const int bookProgressPercent,
|
||||
const uint8_t currentOrientation, const bool hasDictionary,
|
||||
const bool isBookmarked,
|
||||
const bool isBookmarked, const std::string& bookCachePath,
|
||||
const std::function<void(uint8_t)>& onBack,
|
||||
const std::function<void(MenuAction)>& onAction)
|
||||
: ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput),
|
||||
menuItems(buildMenuItems(hasDictionary, isBookmarked)),
|
||||
title(title),
|
||||
pendingOrientation(currentOrientation),
|
||||
bookCachePath(bookCachePath),
|
||||
currentPage(currentPage),
|
||||
totalPages(totalPages),
|
||||
bookProgressPercent(bookProgressPercent),
|
||||
onBack(onBack),
|
||||
onAction(onAction) {}
|
||||
onAction(onAction) {
|
||||
// Load per-book settings to initialize the letterbox fill override
|
||||
auto bookSettings = BookSettings::load(bookCachePath);
|
||||
pendingLetterboxFill = bookSettings.letterboxFillOverride;
|
||||
}
|
||||
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
@@ -65,6 +72,11 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
std::string title = "Reader Menu";
|
||||
uint8_t pendingOrientation = 0;
|
||||
const std::vector<const char*> orientationLabels = {"Portrait", "Landscape CW", "Inverted", "Landscape CCW"};
|
||||
std::string bookCachePath;
|
||||
// Letterbox fill override: 0xFF = Default (use global), 0 = Dithered, 1 = Solid, 2 = None
|
||||
uint8_t pendingLetterboxFill = BookSettings::USE_GLOBAL;
|
||||
static constexpr int LETTERBOX_FILL_OPTION_COUNT = 4; // Default + 3 modes
|
||||
const std::vector<const char*> letterboxFillLabels = {"Default", "Dithered", "Solid", "None"};
|
||||
int currentPage = 0;
|
||||
int totalPages = 0;
|
||||
int bookProgressPercent = 0;
|
||||
@@ -72,6 +84,25 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
const std::function<void(uint8_t)> onBack;
|
||||
const std::function<void(MenuAction)> onAction;
|
||||
|
||||
// Map the internal override value to an index into letterboxFillLabels.
|
||||
int letterboxFillToIndex() const {
|
||||
if (pendingLetterboxFill == BookSettings::USE_GLOBAL) return 0; // "Default"
|
||||
return pendingLetterboxFill + 1; // 0->1 (Dithered), 1->2 (Solid), 2->3 (None)
|
||||
}
|
||||
|
||||
// Map an index from letterboxFillLabels back to an override value.
|
||||
static uint8_t indexToLetterboxFill(int index) {
|
||||
if (index == 0) return BookSettings::USE_GLOBAL;
|
||||
return static_cast<uint8_t>(index - 1);
|
||||
}
|
||||
|
||||
// Save the current letterbox fill override to the book's settings file.
|
||||
void saveLetterboxFill() const {
|
||||
auto bookSettings = BookSettings::load(bookCachePath);
|
||||
bookSettings.letterboxFillOverride = pendingLetterboxFill;
|
||||
BookSettings::save(bookCachePath, bookSettings);
|
||||
}
|
||||
|
||||
static std::vector<MenuItem> buildMenuItems(bool hasDictionary, bool isBookmarked) {
|
||||
std::vector<MenuItem> items;
|
||||
if (isBookmarked) {
|
||||
@@ -84,6 +115,7 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
items.push_back({MenuAction::LOOKED_UP_WORDS, "Lookup Word History"});
|
||||
}
|
||||
items.push_back({MenuAction::ROTATE_SCREEN, "Reading Orientation"});
|
||||
items.push_back({MenuAction::LETTERBOX_FILL, "Letterbox Fill"});
|
||||
items.push_back({MenuAction::SELECT_CHAPTER, "Table of Contents"});
|
||||
items.push_back({MenuAction::GO_TO_BOOKMARK, "Go to Bookmark"});
|
||||
items.push_back({MenuAction::GO_TO_PERCENT, "Go to %"});
|
||||
|
||||
Reference in New Issue
Block a user