2026-01-14 19:36:40 +09:00
|
|
|
#include "TxtReaderActivity.h"
|
|
|
|
|
|
|
|
|
|
#include <GfxRenderer.h>
|
2026-02-08 21:29:14 +01:00
|
|
|
#include <HalStorage.h>
|
feat: User-Interface I18n System (#728)
**What is the goal of this PR?**
This PR introduces Internationalization (i18n) support, enabling users
to switch the UI language dynamically.
**What changes are included?**
- Core Logic: Added I18n class (`lib/I18n/I18n.h/cpp`) to manage
language state and string retrieval.
- Data Structures:
- `lib/I18n/I18nStrings.h/cpp`: Static string arrays for each supported
language.
- `lib/I18n/I18nKeys.h`: Enum definitions for type-safe string access.
- `lib/I18n/translations.csv`: single source of truth.
- Documentation: Added `docs/i18n.md` detailing the workflow for
developers and translators.
- New Settings activity:
`src/activities/settings/LanguageSelectActivity.h/cpp`
This implementation (building on concepts from #505) prioritizes
performance and memory efficiency.
The core approach is to store all localized strings for each language in
dedicated arrays and access them via enums. This provides O(1) access
with zero runtime overhead, and avoids the heap allocations, hashing,
and collision handling required by `std::map` or `std::unordered_map`.
The main trade-off is that enums and string arrays must remain perfectly
synchronized—any mismatch would result in incorrect strings being
displayed in the UI.
To eliminate this risk, I added a Python script that automatically
generates `I18nStrings.h/.cpp` and `I18nKeys.h` from a CSV file, which
will serve as the single source of truth for all translations. The full
design and workflow are documented in `docs/i18n.md`.
- [x] Python script `generate_i18n.py` to auto-generate C++ files from
CSV
- [x] Populate translations.csv with initial translations.
Currently available translations: English, Español, Français, Deutsch,
Čeština, Português (Brasil), Русский, Svenska.
Thanks, community!
**Status:** EDIT: ready to be merged.
As a proof of concept, the SPANISH strings currently mirror the English
ones, but are fully uppercased.
---
Did you use AI tools to help write this code? _**< PARTIALLY >**_
I used AI for the black work of replacing strings with I18n references
across the project, and for generating the documentation. EDIT: also
some help with merging changes from master.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: yeyeto2788 <juanernestobiondi@gmail.com>
2026-02-16 15:28:42 +02:00
|
|
|
#include <I18n.h>
|
2026-01-14 19:36:40 +09:00
|
|
|
#include <Serialization.h>
|
|
|
|
|
#include <Utf8.h>
|
|
|
|
|
|
2026-02-14 23:38:47 -05:00
|
|
|
#include <PlaceholderCoverGenerator.h>
|
|
|
|
|
|
2026-01-14 19:36:40 +09:00
|
|
|
#include "CrossPointSettings.h"
|
|
|
|
|
#include "CrossPointState.h"
|
|
|
|
|
#include "MappedInputManager.h"
|
2026-01-27 18:53:31 +07:00
|
|
|
#include "RecentBooksStore.h"
|
feat: UI themes, Lyra (#528)
## Summary
### What is the goal of this PR?
- Visual UI overhaul
- UI theme selection
### What changes are included?
- Added a setting "UI Theme": Classic, Lyra
- The classic theme is the current Crosspoint theme
- The Lyra theme implements these mockups:
https://www.figma.com/design/UhxoV4DgUnfrDQgMPPTXog/Lyra-Theme?node-id=2003-7596&t=4CSOZqf0n9uQMxDt-0
by Discord users yagofarias, ruby and gan_shu
- New functions in GFXRenderer to render rounded rectangles, greyscale
fills (using dithering) and thick lines
- Basic UI components are factored into BaseTheme methods which can be
overridden by each additional theme. Methods that are not overridden
will fallback to BaseTheme behavior. This means any new
features/components in CrossPoint only need to be developed for the
"Classic" BaseTheme.
- Additional themes can easily be developed by the community using this
foundation



## Additional Context
- Only the Home, Library and main Settings screens have been implemented
so far, this will be extended to the transfer screens and chapter
selection screen later on, but we need to get the ball rolling somehow
:)
- Loading extra covers on the home screen in the Lyra theme takes a
little more time (about 2 seconds), I added a loading bar popup (reusing
the Indexing progress bar from the reader view, factored into a neat UI
component) but the popup adds ~400ms to the loading time.
- ~~Home screen thumbnails will need to be generated separately for each
theme, because they are displayed in different sizes. Because we're
using dithering, displaying a thumb with the wrong size causes the
picture to look janky or dark as it does on the screenshots above. No
worries this will be fixed in a future PR.~~ Thumbs are now generated
with a size parameter
- UI Icons will need to be implemented in a future PR.
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**PARTIALLY**_
This is not a vibe coded PR. Copilot was used for autocompletion to save
time but I reviewed, understood and edited all generated code.
---------
Co-authored-by: Dave Allie <dave@daveallie.com>
2026-02-05 17:50:11 +07:00
|
|
|
#include "components/UITheme.h"
|
2026-01-14 19:36:40 +09:00
|
|
|
#include "fontIds.h"
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
constexpr unsigned long goHomeMs = 1000;
|
|
|
|
|
constexpr int statusBarMargin = 25;
|
2026-01-27 12:25:44 +00:00
|
|
|
constexpr int progressBarMarginTop = 1;
|
2026-01-14 19:36:40 +09:00
|
|
|
constexpr size_t CHUNK_SIZE = 8 * 1024; // 8KB chunk for reading
|
|
|
|
|
|
|
|
|
|
// Cache file magic and version
|
|
|
|
|
constexpr uint32_t CACHE_MAGIC = 0x54585449; // "TXTI"
|
|
|
|
|
constexpr uint8_t CACHE_VERSION = 2; // Increment when cache format changes
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::onEnter() {
|
|
|
|
|
ActivityWithSubactivity::onEnter();
|
|
|
|
|
|
|
|
|
|
if (!txt) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configure screen orientation based on settings
|
|
|
|
|
switch (SETTINGS.orientation) {
|
|
|
|
|
case CrossPointSettings::ORIENTATION::PORTRAIT:
|
|
|
|
|
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
|
|
|
|
|
break;
|
|
|
|
|
case CrossPointSettings::ORIENTATION::LANDSCAPE_CW:
|
|
|
|
|
renderer.setOrientation(GfxRenderer::Orientation::LandscapeClockwise);
|
|
|
|
|
break;
|
|
|
|
|
case CrossPointSettings::ORIENTATION::INVERTED:
|
|
|
|
|
renderer.setOrientation(GfxRenderer::Orientation::PortraitInverted);
|
|
|
|
|
break;
|
|
|
|
|
case CrossPointSettings::ORIENTATION::LANDSCAPE_CCW:
|
|
|
|
|
renderer.setOrientation(GfxRenderer::Orientation::LandscapeCounterClockwise);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
txt->setupCacheDir();
|
|
|
|
|
|
2026-02-14 23:38:47 -05:00
|
|
|
// Prerender covers and thumbnails on first open so Home and Sleep screens are instant.
|
|
|
|
|
// Each generate* call is a no-op if the file already exists, so this only does work once.
|
|
|
|
|
{
|
|
|
|
|
int totalSteps = 0;
|
|
|
|
|
if (!Storage.exists(txt->getCoverBmpPath().c_str())) totalSteps++;
|
|
|
|
|
for (int i = 0; i < PRERENDER_THUMB_HEIGHTS_COUNT; i++) {
|
|
|
|
|
if (!Storage.exists(txt->getThumbBmpPath(PRERENDER_THUMB_HEIGHTS[i]).c_str())) totalSteps++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (totalSteps > 0) {
|
|
|
|
|
Rect popupRect = GUI.drawPopup(renderer, "Preparing book...");
|
|
|
|
|
int completedSteps = 0;
|
|
|
|
|
|
|
|
|
|
auto updateProgress = [&]() {
|
|
|
|
|
completedSteps++;
|
|
|
|
|
GUI.fillPopupProgress(renderer, popupRect, completedSteps * 100 / totalSteps);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!Storage.exists(txt->getCoverBmpPath().c_str())) {
|
|
|
|
|
const bool coverGenerated = txt->generateCoverBmp();
|
|
|
|
|
// Fallback: generate placeholder if no cover image was found
|
|
|
|
|
if (!coverGenerated) {
|
|
|
|
|
PlaceholderCoverGenerator::generate(txt->getCoverBmpPath(), txt->getTitle(), "", 480, 800);
|
|
|
|
|
}
|
|
|
|
|
updateProgress();
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < PRERENDER_THUMB_HEIGHTS_COUNT; i++) {
|
|
|
|
|
if (!Storage.exists(txt->getThumbBmpPath(PRERENDER_THUMB_HEIGHTS[i]).c_str())) {
|
|
|
|
|
// TXT has no native thumbnail generation, always use placeholder
|
|
|
|
|
const int thumbHeight = PRERENDER_THUMB_HEIGHTS[i];
|
|
|
|
|
const int thumbWidth = static_cast<int>(thumbHeight * 0.6);
|
|
|
|
|
PlaceholderCoverGenerator::generate(txt->getThumbBmpPath(thumbHeight), txt->getTitle(), "", thumbWidth,
|
|
|
|
|
thumbHeight);
|
|
|
|
|
updateProgress();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-12 16:13:55 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-27 18:53:31 +07:00
|
|
|
// Save current txt as last opened file and add to recent books
|
feat: UI themes, Lyra (#528)
## Summary
### What is the goal of this PR?
- Visual UI overhaul
- UI theme selection
### What changes are included?
- Added a setting "UI Theme": Classic, Lyra
- The classic theme is the current Crosspoint theme
- The Lyra theme implements these mockups:
https://www.figma.com/design/UhxoV4DgUnfrDQgMPPTXog/Lyra-Theme?node-id=2003-7596&t=4CSOZqf0n9uQMxDt-0
by Discord users yagofarias, ruby and gan_shu
- New functions in GFXRenderer to render rounded rectangles, greyscale
fills (using dithering) and thick lines
- Basic UI components are factored into BaseTheme methods which can be
overridden by each additional theme. Methods that are not overridden
will fallback to BaseTheme behavior. This means any new
features/components in CrossPoint only need to be developed for the
"Classic" BaseTheme.
- Additional themes can easily be developed by the community using this
foundation



## Additional Context
- Only the Home, Library and main Settings screens have been implemented
so far, this will be extended to the transfer screens and chapter
selection screen later on, but we need to get the ball rolling somehow
:)
- Loading extra covers on the home screen in the Lyra theme takes a
little more time (about 2 seconds), I added a loading bar popup (reusing
the Indexing progress bar from the reader view, factored into a neat UI
component) but the popup adds ~400ms to the loading time.
- ~~Home screen thumbnails will need to be generated separately for each
theme, because they are displayed in different sizes. Because we're
using dithering, displaying a thumb with the wrong size causes the
picture to look janky or dark as it does on the screenshots above. No
worries this will be fixed in a future PR.~~ Thumbs are now generated
with a size parameter
- UI Icons will need to be implemented in a future PR.
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**PARTIALLY**_
This is not a vibe coded PR. Copilot was used for autocompletion to save
time but I reviewed, understood and edited all generated code.
---------
Co-authored-by: Dave Allie <dave@daveallie.com>
2026-02-05 17:50:11 +07:00
|
|
|
auto filePath = txt->getPath();
|
|
|
|
|
auto fileName = filePath.substr(filePath.rfind('/') + 1);
|
|
|
|
|
APP_STATE.openEpubPath = filePath;
|
2026-01-14 19:36:40 +09:00
|
|
|
APP_STATE.saveToFile();
|
2026-02-14 23:38:47 -05:00
|
|
|
RECENT_BOOKS.addBook(filePath, fileName, "", txt->getThumbBmpPath());
|
2026-01-14 19:36:40 +09:00
|
|
|
|
|
|
|
|
// Trigger first update
|
refactor: move render() to Activity super class, use freeRTOS notification (#774)
Currently, each activity has to manage their own `displayTaskLoop` which
adds redundant boilerplate code. The loop is a wait loop which is also
not the best practice, as the `updateRequested` boolean is not protected
by a mutex.
In this PR:
- Move `displayTaskLoop` to the super `Activity` class
- Replace `updateRequested` with freeRTOS's [direct to task
notification](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/03-Direct-to-task-notifications/01-Task-notifications)
- For `ActivityWithSubactivity`, whenever a sub-activity is present, the
parent's `render()` automatically goes inactive
With this change, activities now only need to expose `render()`
function, and anywhere in the code base can call `requestUpdate()` to
request a new rendering pass.
In theory, this change may also make the battery life a bit better,
since one wait loop is removed. Although the equipment in my home lab
wasn't been able to verify it (the electric current is too noisy and
small). Would appreciate if anyone has any insights on this subject.
Update: I managed to hack [a small piece of
code](https://github.com/ngxson/crosspoint-reader/tree/xsn/measure_cpu_usage)
that allow tracking CPU idle time.
The CPU load does decrease a bit (1.47% down to 1.39%), which make
sense, because the display task is now sleeping most of the time unless
notified. This should translate to a slightly increase in battery life
in the long run.
```
PR:
[40012] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[40012] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[50017] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[50017] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[60022] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[60022] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
master:
[20012] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[20012] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[30017] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[30017] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[40022] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[40022] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
```
---
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? **NO**
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
* **Refactor**
* Streamlined rendering architecture by consolidating update mechanisms
across all activities, improving efficiency and consistency.
* Modernized synchronization patterns for display updates to ensure
reliable, conflict-free rendering.
* **Bug Fixes**
* Enhanced rendering stability through improved locking mechanisms and
explicit update requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: znelson <znelson@users.noreply.github.com>
2026-02-16 11:11:15 +01:00
|
|
|
requestUpdate();
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::onExit() {
|
|
|
|
|
ActivityWithSubactivity::onExit();
|
|
|
|
|
|
|
|
|
|
// Reset orientation back to portrait for the rest of the UI
|
|
|
|
|
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
|
|
|
|
|
|
|
|
|
|
pageOffsets.clear();
|
|
|
|
|
currentPageLines.clear();
|
2026-02-05 19:45:09 +08:00
|
|
|
APP_STATE.readerActivityLoadCount = 0;
|
|
|
|
|
APP_STATE.saveToFile();
|
2026-01-14 19:36:40 +09:00
|
|
|
txt.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::loop() {
|
|
|
|
|
if (subActivity) {
|
|
|
|
|
subActivity->loop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-07 18:17:00 +03:00
|
|
|
// Long press BACK (1s+) goes to file selection
|
2026-01-14 19:36:40 +09:00
|
|
|
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) {
|
2026-02-07 18:17:00 +03:00
|
|
|
onGoBack();
|
2026-01-14 19:36:40 +09:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-07 18:17:00 +03:00
|
|
|
// Short press BACK goes directly to home
|
2026-01-14 19:36:40 +09:00
|
|
|
if (mappedInput.wasReleased(MappedInputManager::Button::Back) && mappedInput.getHeldTime() < goHomeMs) {
|
2026-02-07 18:17:00 +03:00
|
|
|
onGoHome();
|
2026-01-14 19:36:40 +09:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 17:53:13 +05:00
|
|
|
// When long-press chapter skip is disabled, turn pages on press instead of release.
|
|
|
|
|
const bool usePressForPageTurn = !SETTINGS.longPressChapterSkip;
|
|
|
|
|
const bool prevTriggered = usePressForPageTurn ? (mappedInput.wasPressed(MappedInputManager::Button::PageBack) ||
|
|
|
|
|
mappedInput.wasPressed(MappedInputManager::Button::Left))
|
|
|
|
|
: (mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
|
|
|
|
|
mappedInput.wasReleased(MappedInputManager::Button::Left));
|
|
|
|
|
const bool powerPageTurn = SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::PAGE_TURN &&
|
|
|
|
|
mappedInput.wasReleased(MappedInputManager::Button::Power);
|
|
|
|
|
const bool nextTriggered = usePressForPageTurn
|
|
|
|
|
? (mappedInput.wasPressed(MappedInputManager::Button::PageForward) || powerPageTurn ||
|
|
|
|
|
mappedInput.wasPressed(MappedInputManager::Button::Right))
|
|
|
|
|
: (mappedInput.wasReleased(MappedInputManager::Button::PageForward) || powerPageTurn ||
|
|
|
|
|
mappedInput.wasReleased(MappedInputManager::Button::Right));
|
|
|
|
|
|
|
|
|
|
if (!prevTriggered && !nextTriggered) {
|
2026-01-14 19:36:40 +09:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 17:53:13 +05:00
|
|
|
if (prevTriggered && currentPage > 0) {
|
2026-01-14 19:36:40 +09:00
|
|
|
currentPage--;
|
refactor: move render() to Activity super class, use freeRTOS notification (#774)
Currently, each activity has to manage their own `displayTaskLoop` which
adds redundant boilerplate code. The loop is a wait loop which is also
not the best practice, as the `updateRequested` boolean is not protected
by a mutex.
In this PR:
- Move `displayTaskLoop` to the super `Activity` class
- Replace `updateRequested` with freeRTOS's [direct to task
notification](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/03-Direct-to-task-notifications/01-Task-notifications)
- For `ActivityWithSubactivity`, whenever a sub-activity is present, the
parent's `render()` automatically goes inactive
With this change, activities now only need to expose `render()`
function, and anywhere in the code base can call `requestUpdate()` to
request a new rendering pass.
In theory, this change may also make the battery life a bit better,
since one wait loop is removed. Although the equipment in my home lab
wasn't been able to verify it (the electric current is too noisy and
small). Would appreciate if anyone has any insights on this subject.
Update: I managed to hack [a small piece of
code](https://github.com/ngxson/crosspoint-reader/tree/xsn/measure_cpu_usage)
that allow tracking CPU idle time.
The CPU load does decrease a bit (1.47% down to 1.39%), which make
sense, because the display task is now sleeping most of the time unless
notified. This should translate to a slightly increase in battery life
in the long run.
```
PR:
[40012] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[40012] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[50017] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[50017] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[60022] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[60022] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
master:
[20012] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[20012] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[30017] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[30017] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[40022] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[40022] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
```
---
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? **NO**
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
* **Refactor**
* Streamlined rendering architecture by consolidating update mechanisms
across all activities, improving efficiency and consistency.
* Modernized synchronization patterns for display updates to ensure
reliable, conflict-free rendering.
* **Bug Fixes**
* Enhanced rendering stability through improved locking mechanisms and
explicit update requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: znelson <znelson@users.noreply.github.com>
2026-02-16 11:11:15 +01:00
|
|
|
requestUpdate();
|
2026-01-27 17:53:13 +05:00
|
|
|
} else if (nextTriggered && currentPage < totalPages - 1) {
|
2026-01-14 19:36:40 +09:00
|
|
|
currentPage++;
|
refactor: move render() to Activity super class, use freeRTOS notification (#774)
Currently, each activity has to manage their own `displayTaskLoop` which
adds redundant boilerplate code. The loop is a wait loop which is also
not the best practice, as the `updateRequested` boolean is not protected
by a mutex.
In this PR:
- Move `displayTaskLoop` to the super `Activity` class
- Replace `updateRequested` with freeRTOS's [direct to task
notification](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/03-Direct-to-task-notifications/01-Task-notifications)
- For `ActivityWithSubactivity`, whenever a sub-activity is present, the
parent's `render()` automatically goes inactive
With this change, activities now only need to expose `render()`
function, and anywhere in the code base can call `requestUpdate()` to
request a new rendering pass.
In theory, this change may also make the battery life a bit better,
since one wait loop is removed. Although the equipment in my home lab
wasn't been able to verify it (the electric current is too noisy and
small). Would appreciate if anyone has any insights on this subject.
Update: I managed to hack [a small piece of
code](https://github.com/ngxson/crosspoint-reader/tree/xsn/measure_cpu_usage)
that allow tracking CPU idle time.
The CPU load does decrease a bit (1.47% down to 1.39%), which make
sense, because the display task is now sleeping most of the time unless
notified. This should translate to a slightly increase in battery life
in the long run.
```
PR:
[40012] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[40012] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[50017] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[50017] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[60022] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[60022] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
master:
[20012] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[20012] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[30017] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[30017] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[40022] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[40022] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
```
---
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? **NO**
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
* **Refactor**
* Streamlined rendering architecture by consolidating update mechanisms
across all activities, improving efficiency and consistency.
* Modernized synchronization patterns for display updates to ensure
reliable, conflict-free rendering.
* **Bug Fixes**
* Enhanced rendering stability through improved locking mechanisms and
explicit update requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: znelson <znelson@users.noreply.github.com>
2026-02-16 11:11:15 +01:00
|
|
|
requestUpdate();
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::initializeReader() {
|
|
|
|
|
if (initialized) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store current settings for cache validation
|
|
|
|
|
cachedFontId = SETTINGS.getReaderFontId();
|
|
|
|
|
cachedScreenMargin = SETTINGS.screenMargin;
|
|
|
|
|
cachedParagraphAlignment = SETTINGS.paragraphAlignment;
|
|
|
|
|
|
|
|
|
|
// Calculate viewport dimensions
|
|
|
|
|
int orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft;
|
|
|
|
|
renderer.getOrientedViewableTRBL(&orientedMarginTop, &orientedMarginRight, &orientedMarginBottom,
|
|
|
|
|
&orientedMarginLeft);
|
|
|
|
|
orientedMarginTop += cachedScreenMargin;
|
|
|
|
|
orientedMarginLeft += cachedScreenMargin;
|
|
|
|
|
orientedMarginRight += cachedScreenMargin;
|
2026-01-27 12:25:44 +00:00
|
|
|
orientedMarginBottom += cachedScreenMargin;
|
|
|
|
|
|
feat: UI themes, Lyra (#528)
## Summary
### What is the goal of this PR?
- Visual UI overhaul
- UI theme selection
### What changes are included?
- Added a setting "UI Theme": Classic, Lyra
- The classic theme is the current Crosspoint theme
- The Lyra theme implements these mockups:
https://www.figma.com/design/UhxoV4DgUnfrDQgMPPTXog/Lyra-Theme?node-id=2003-7596&t=4CSOZqf0n9uQMxDt-0
by Discord users yagofarias, ruby and gan_shu
- New functions in GFXRenderer to render rounded rectangles, greyscale
fills (using dithering) and thick lines
- Basic UI components are factored into BaseTheme methods which can be
overridden by each additional theme. Methods that are not overridden
will fallback to BaseTheme behavior. This means any new
features/components in CrossPoint only need to be developed for the
"Classic" BaseTheme.
- Additional themes can easily be developed by the community using this
foundation



## Additional Context
- Only the Home, Library and main Settings screens have been implemented
so far, this will be extended to the transfer screens and chapter
selection screen later on, but we need to get the ball rolling somehow
:)
- Loading extra covers on the home screen in the Lyra theme takes a
little more time (about 2 seconds), I added a loading bar popup (reusing
the Indexing progress bar from the reader view, factored into a neat UI
component) but the popup adds ~400ms to the loading time.
- ~~Home screen thumbnails will need to be generated separately for each
theme, because they are displayed in different sizes. Because we're
using dithering, displaying a thumb with the wrong size causes the
picture to look janky or dark as it does on the screenshots above. No
worries this will be fixed in a future PR.~~ Thumbs are now generated
with a size parameter
- UI Icons will need to be implemented in a future PR.
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**PARTIALLY**_
This is not a vibe coded PR. Copilot was used for autocompletion to save
time but I reviewed, understood and edited all generated code.
---------
Co-authored-by: Dave Allie <dave@daveallie.com>
2026-02-05 17:50:11 +07:00
|
|
|
auto metrics = UITheme::getInstance().getMetrics();
|
|
|
|
|
|
2026-01-27 12:25:44 +00:00
|
|
|
// Add status bar margin
|
|
|
|
|
if (SETTINGS.statusBar != CrossPointSettings::STATUS_BAR_MODE::NONE) {
|
|
|
|
|
// Add additional margin for status bar if progress bar is shown
|
2026-02-05 10:49:38 -05:00
|
|
|
const bool showProgressBar = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::BOOK_PROGRESS_BAR ||
|
|
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::ONLY_BOOK_PROGRESS_BAR ||
|
|
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::CHAPTER_PROGRESS_BAR;
|
2026-01-27 12:25:44 +00:00
|
|
|
orientedMarginBottom += statusBarMargin - cachedScreenMargin +
|
feat: UI themes, Lyra (#528)
## Summary
### What is the goal of this PR?
- Visual UI overhaul
- UI theme selection
### What changes are included?
- Added a setting "UI Theme": Classic, Lyra
- The classic theme is the current Crosspoint theme
- The Lyra theme implements these mockups:
https://www.figma.com/design/UhxoV4DgUnfrDQgMPPTXog/Lyra-Theme?node-id=2003-7596&t=4CSOZqf0n9uQMxDt-0
by Discord users yagofarias, ruby and gan_shu
- New functions in GFXRenderer to render rounded rectangles, greyscale
fills (using dithering) and thick lines
- Basic UI components are factored into BaseTheme methods which can be
overridden by each additional theme. Methods that are not overridden
will fallback to BaseTheme behavior. This means any new
features/components in CrossPoint only need to be developed for the
"Classic" BaseTheme.
- Additional themes can easily be developed by the community using this
foundation



## Additional Context
- Only the Home, Library and main Settings screens have been implemented
so far, this will be extended to the transfer screens and chapter
selection screen later on, but we need to get the ball rolling somehow
:)
- Loading extra covers on the home screen in the Lyra theme takes a
little more time (about 2 seconds), I added a loading bar popup (reusing
the Indexing progress bar from the reader view, factored into a neat UI
component) but the popup adds ~400ms to the loading time.
- ~~Home screen thumbnails will need to be generated separately for each
theme, because they are displayed in different sizes. Because we're
using dithering, displaying a thumb with the wrong size causes the
picture to look janky or dark as it does on the screenshots above. No
worries this will be fixed in a future PR.~~ Thumbs are now generated
with a size parameter
- UI Icons will need to be implemented in a future PR.
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**PARTIALLY**_
This is not a vibe coded PR. Copilot was used for autocompletion to save
time but I reviewed, understood and edited all generated code.
---------
Co-authored-by: Dave Allie <dave@daveallie.com>
2026-02-05 17:50:11 +07:00
|
|
|
(showProgressBar ? (metrics.bookProgressBarHeight + progressBarMarginTop) : 0);
|
2026-01-27 12:25:44 +00:00
|
|
|
}
|
2026-01-14 19:36:40 +09:00
|
|
|
|
|
|
|
|
viewportWidth = renderer.getScreenWidth() - orientedMarginLeft - orientedMarginRight;
|
|
|
|
|
const int viewportHeight = renderer.getScreenHeight() - orientedMarginTop - orientedMarginBottom;
|
|
|
|
|
const int lineHeight = renderer.getLineHeight(cachedFontId);
|
|
|
|
|
|
|
|
|
|
linesPerPage = viewportHeight / lineHeight;
|
|
|
|
|
if (linesPerPage < 1) linesPerPage = 1;
|
|
|
|
|
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Viewport: %dx%d, lines per page: %d", viewportWidth, viewportHeight, linesPerPage);
|
2026-01-14 19:36:40 +09:00
|
|
|
|
|
|
|
|
// Try to load cached page index first
|
|
|
|
|
if (!loadPageIndexCache()) {
|
|
|
|
|
// Cache not found, build page index
|
|
|
|
|
buildPageIndex();
|
|
|
|
|
// Save to cache for next time
|
|
|
|
|
savePageIndexCache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load saved progress
|
|
|
|
|
loadProgress();
|
|
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::buildPageIndex() {
|
|
|
|
|
pageOffsets.clear();
|
|
|
|
|
pageOffsets.push_back(0); // First page starts at offset 0
|
|
|
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
const size_t fileSize = txt->getFileSize();
|
|
|
|
|
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Building page index for %zu bytes...", fileSize);
|
2026-01-14 19:36:40 +09:00
|
|
|
|
feat: User-Interface I18n System (#728)
**What is the goal of this PR?**
This PR introduces Internationalization (i18n) support, enabling users
to switch the UI language dynamically.
**What changes are included?**
- Core Logic: Added I18n class (`lib/I18n/I18n.h/cpp`) to manage
language state and string retrieval.
- Data Structures:
- `lib/I18n/I18nStrings.h/cpp`: Static string arrays for each supported
language.
- `lib/I18n/I18nKeys.h`: Enum definitions for type-safe string access.
- `lib/I18n/translations.csv`: single source of truth.
- Documentation: Added `docs/i18n.md` detailing the workflow for
developers and translators.
- New Settings activity:
`src/activities/settings/LanguageSelectActivity.h/cpp`
This implementation (building on concepts from #505) prioritizes
performance and memory efficiency.
The core approach is to store all localized strings for each language in
dedicated arrays and access them via enums. This provides O(1) access
with zero runtime overhead, and avoids the heap allocations, hashing,
and collision handling required by `std::map` or `std::unordered_map`.
The main trade-off is that enums and string arrays must remain perfectly
synchronized—any mismatch would result in incorrect strings being
displayed in the UI.
To eliminate this risk, I added a Python script that automatically
generates `I18nStrings.h/.cpp` and `I18nKeys.h` from a CSV file, which
will serve as the single source of truth for all translations. The full
design and workflow are documented in `docs/i18n.md`.
- [x] Python script `generate_i18n.py` to auto-generate C++ files from
CSV
- [x] Populate translations.csv with initial translations.
Currently available translations: English, Español, Français, Deutsch,
Čeština, Português (Brasil), Русский, Svenska.
Thanks, community!
**Status:** EDIT: ready to be merged.
As a proof of concept, the SPANISH strings currently mirror the English
ones, but are fully uppercased.
---
Did you use AI tools to help write this code? _**< PARTIALLY >**_
I used AI for the black work of replacing strings with I18n references
across the project, and for generating the documentation. EDIT: also
some help with merging changes from master.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: yeyeto2788 <juanernestobiondi@gmail.com>
2026-02-16 15:28:42 +02:00
|
|
|
GUI.drawPopup(renderer, tr(STR_INDEXING));
|
2026-01-14 19:36:40 +09:00
|
|
|
|
|
|
|
|
while (offset < fileSize) {
|
|
|
|
|
std::vector<std::string> tempLines;
|
|
|
|
|
size_t nextOffset = offset;
|
|
|
|
|
|
|
|
|
|
if (!loadPageAtOffset(offset, tempLines, nextOffset)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nextOffset <= offset) {
|
|
|
|
|
// No progress made, avoid infinite loop
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset = nextOffset;
|
|
|
|
|
if (offset < fileSize) {
|
|
|
|
|
pageOffsets.push_back(offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Yield to other tasks periodically
|
|
|
|
|
if (pageOffsets.size() % 20 == 0) {
|
|
|
|
|
vTaskDelay(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalPages = pageOffsets.size();
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Built page index: %d pages", totalPages);
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TxtReaderActivity::loadPageAtOffset(size_t offset, std::vector<std::string>& outLines, size_t& nextOffset) {
|
|
|
|
|
outLines.clear();
|
|
|
|
|
const size_t fileSize = txt->getFileSize();
|
|
|
|
|
|
|
|
|
|
if (offset >= fileSize) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read a chunk from file
|
|
|
|
|
size_t chunkSize = std::min(CHUNK_SIZE, fileSize - offset);
|
|
|
|
|
auto* buffer = static_cast<uint8_t*>(malloc(chunkSize + 1));
|
|
|
|
|
if (!buffer) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_ERR("TRS", "Failed to allocate %zu bytes", chunkSize);
|
2026-01-14 19:36:40 +09:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!txt->readContent(buffer, offset, chunkSize)) {
|
|
|
|
|
free(buffer);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
buffer[chunkSize] = '\0';
|
|
|
|
|
|
|
|
|
|
// Parse lines from buffer
|
|
|
|
|
size_t pos = 0;
|
|
|
|
|
|
|
|
|
|
while (pos < chunkSize && static_cast<int>(outLines.size()) < linesPerPage) {
|
|
|
|
|
// Find end of line
|
|
|
|
|
size_t lineEnd = pos;
|
|
|
|
|
while (lineEnd < chunkSize && buffer[lineEnd] != '\n') {
|
|
|
|
|
lineEnd++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we have a complete line
|
|
|
|
|
bool lineComplete = (lineEnd < chunkSize) || (offset + lineEnd >= fileSize);
|
|
|
|
|
|
|
|
|
|
if (!lineComplete && static_cast<int>(outLines.size()) > 0) {
|
|
|
|
|
// Incomplete line and we already have some lines, stop here
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate the actual length of line content in the buffer (excluding newline)
|
|
|
|
|
size_t lineContentLen = lineEnd - pos;
|
|
|
|
|
|
|
|
|
|
// Check for carriage return
|
|
|
|
|
bool hasCR = (lineContentLen > 0 && buffer[pos + lineContentLen - 1] == '\r');
|
|
|
|
|
size_t displayLen = hasCR ? lineContentLen - 1 : lineContentLen;
|
|
|
|
|
|
|
|
|
|
// Extract line content for display (without CR/LF)
|
|
|
|
|
std::string line(reinterpret_cast<char*>(buffer + pos), displayLen);
|
|
|
|
|
|
|
|
|
|
// Track position within this source line (in bytes from pos)
|
|
|
|
|
size_t lineBytePos = 0;
|
|
|
|
|
|
|
|
|
|
// Word wrap if needed
|
|
|
|
|
while (!line.empty() && static_cast<int>(outLines.size()) < linesPerPage) {
|
|
|
|
|
int lineWidth = renderer.getTextWidth(cachedFontId, line.c_str());
|
|
|
|
|
|
|
|
|
|
if (lineWidth <= viewportWidth) {
|
|
|
|
|
outLines.push_back(line);
|
|
|
|
|
lineBytePos = displayLen; // Consumed entire display content
|
|
|
|
|
line.clear();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find break point
|
|
|
|
|
size_t breakPos = line.length();
|
|
|
|
|
while (breakPos > 0 && renderer.getTextWidth(cachedFontId, line.substr(0, breakPos).c_str()) > viewportWidth) {
|
|
|
|
|
// Try to break at space
|
|
|
|
|
size_t spacePos = line.rfind(' ', breakPos - 1);
|
|
|
|
|
if (spacePos != std::string::npos && spacePos > 0) {
|
|
|
|
|
breakPos = spacePos;
|
|
|
|
|
} else {
|
|
|
|
|
// Break at character boundary for UTF-8
|
|
|
|
|
breakPos--;
|
|
|
|
|
// Make sure we don't break in the middle of a UTF-8 sequence
|
|
|
|
|
while (breakPos > 0 && (line[breakPos] & 0xC0) == 0x80) {
|
|
|
|
|
breakPos--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (breakPos == 0) {
|
|
|
|
|
breakPos = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outLines.push_back(line.substr(0, breakPos));
|
|
|
|
|
|
|
|
|
|
// Skip space at break point
|
|
|
|
|
size_t skipChars = breakPos;
|
|
|
|
|
if (breakPos < line.length() && line[breakPos] == ' ') {
|
|
|
|
|
skipChars++;
|
|
|
|
|
}
|
|
|
|
|
lineBytePos += skipChars;
|
|
|
|
|
line = line.substr(skipChars);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Determine how much of the source buffer we consumed
|
|
|
|
|
if (line.empty()) {
|
|
|
|
|
// Fully consumed this source line, move past the newline
|
|
|
|
|
pos = lineEnd + 1;
|
|
|
|
|
} else {
|
|
|
|
|
// Partially consumed - page is full mid-line
|
|
|
|
|
// Move pos to where we stopped in the line (NOT past the line)
|
|
|
|
|
pos = pos + lineBytePos;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure we make progress even if calculations go wrong
|
|
|
|
|
if (pos == 0 && !outLines.empty()) {
|
|
|
|
|
// Fallback: at minimum, consume something to avoid infinite loop
|
|
|
|
|
pos = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nextOffset = offset + pos;
|
|
|
|
|
|
|
|
|
|
// Make sure we don't go past the file
|
|
|
|
|
if (nextOffset > fileSize) {
|
|
|
|
|
nextOffset = fileSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
|
|
return !outLines.empty();
|
|
|
|
|
}
|
|
|
|
|
|
refactor: move render() to Activity super class, use freeRTOS notification (#774)
Currently, each activity has to manage their own `displayTaskLoop` which
adds redundant boilerplate code. The loop is a wait loop which is also
not the best practice, as the `updateRequested` boolean is not protected
by a mutex.
In this PR:
- Move `displayTaskLoop` to the super `Activity` class
- Replace `updateRequested` with freeRTOS's [direct to task
notification](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/03-Direct-to-task-notifications/01-Task-notifications)
- For `ActivityWithSubactivity`, whenever a sub-activity is present, the
parent's `render()` automatically goes inactive
With this change, activities now only need to expose `render()`
function, and anywhere in the code base can call `requestUpdate()` to
request a new rendering pass.
In theory, this change may also make the battery life a bit better,
since one wait loop is removed. Although the equipment in my home lab
wasn't been able to verify it (the electric current is too noisy and
small). Would appreciate if anyone has any insights on this subject.
Update: I managed to hack [a small piece of
code](https://github.com/ngxson/crosspoint-reader/tree/xsn/measure_cpu_usage)
that allow tracking CPU idle time.
The CPU load does decrease a bit (1.47% down to 1.39%), which make
sense, because the display task is now sleeping most of the time unless
notified. This should translate to a slightly increase in battery life
in the long run.
```
PR:
[40012] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[40012] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[50017] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[50017] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
[60022] [MEM] Free: 185856 bytes, Total: 231004 bytes, Min Free: 123316 bytes
[60022] [IDLE] Idle time: 98.61% (CPU load: 1.39%)
master:
[20012] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[20012] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[30017] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[30017] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
[40022] [MEM] Free: 195016 bytes, Total: 231532 bytes, Min Free: 132460 bytes
[40022] [IDLE] Idle time: 98.53% (CPU load: 1.47%)
```
---
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? **NO**
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
* **Refactor**
* Streamlined rendering architecture by consolidating update mechanisms
across all activities, improving efficiency and consistency.
* Modernized synchronization patterns for display updates to ensure
reliable, conflict-free rendering.
* **Bug Fixes**
* Enhanced rendering stability through improved locking mechanisms and
explicit update requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: znelson <znelson@users.noreply.github.com>
2026-02-16 11:11:15 +01:00
|
|
|
void TxtReaderActivity::render(Activity::RenderLock&&) {
|
2026-01-14 19:36:40 +09:00
|
|
|
if (!txt) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize reader if not done
|
|
|
|
|
if (!initialized) {
|
|
|
|
|
initializeReader();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pageOffsets.empty()) {
|
|
|
|
|
renderer.clearScreen();
|
feat: User-Interface I18n System (#728)
**What is the goal of this PR?**
This PR introduces Internationalization (i18n) support, enabling users
to switch the UI language dynamically.
**What changes are included?**
- Core Logic: Added I18n class (`lib/I18n/I18n.h/cpp`) to manage
language state and string retrieval.
- Data Structures:
- `lib/I18n/I18nStrings.h/cpp`: Static string arrays for each supported
language.
- `lib/I18n/I18nKeys.h`: Enum definitions for type-safe string access.
- `lib/I18n/translations.csv`: single source of truth.
- Documentation: Added `docs/i18n.md` detailing the workflow for
developers and translators.
- New Settings activity:
`src/activities/settings/LanguageSelectActivity.h/cpp`
This implementation (building on concepts from #505) prioritizes
performance and memory efficiency.
The core approach is to store all localized strings for each language in
dedicated arrays and access them via enums. This provides O(1) access
with zero runtime overhead, and avoids the heap allocations, hashing,
and collision handling required by `std::map` or `std::unordered_map`.
The main trade-off is that enums and string arrays must remain perfectly
synchronized—any mismatch would result in incorrect strings being
displayed in the UI.
To eliminate this risk, I added a Python script that automatically
generates `I18nStrings.h/.cpp` and `I18nKeys.h` from a CSV file, which
will serve as the single source of truth for all translations. The full
design and workflow are documented in `docs/i18n.md`.
- [x] Python script `generate_i18n.py` to auto-generate C++ files from
CSV
- [x] Populate translations.csv with initial translations.
Currently available translations: English, Español, Français, Deutsch,
Čeština, Português (Brasil), Русский, Svenska.
Thanks, community!
**Status:** EDIT: ready to be merged.
As a proof of concept, the SPANISH strings currently mirror the English
ones, but are fully uppercased.
---
Did you use AI tools to help write this code? _**< PARTIALLY >**_
I used AI for the black work of replacing strings with I18n references
across the project, and for generating the documentation. EDIT: also
some help with merging changes from master.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: yeyeto2788 <juanernestobiondi@gmail.com>
2026-02-16 15:28:42 +02:00
|
|
|
renderer.drawCenteredText(UI_12_FONT_ID, 300, tr(STR_EMPTY_FILE), true, EpdFontFamily::BOLD);
|
2026-01-14 19:36:40 +09:00
|
|
|
renderer.displayBuffer();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bounds check
|
|
|
|
|
if (currentPage < 0) currentPage = 0;
|
|
|
|
|
if (currentPage >= totalPages) currentPage = totalPages - 1;
|
|
|
|
|
|
|
|
|
|
// Load current page content
|
|
|
|
|
size_t offset = pageOffsets[currentPage];
|
|
|
|
|
size_t nextOffset;
|
|
|
|
|
currentPageLines.clear();
|
|
|
|
|
loadPageAtOffset(offset, currentPageLines, nextOffset);
|
|
|
|
|
|
|
|
|
|
renderer.clearScreen();
|
|
|
|
|
renderPage();
|
|
|
|
|
|
|
|
|
|
// Save progress
|
|
|
|
|
saveProgress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::renderPage() {
|
|
|
|
|
int orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft;
|
|
|
|
|
renderer.getOrientedViewableTRBL(&orientedMarginTop, &orientedMarginRight, &orientedMarginBottom,
|
|
|
|
|
&orientedMarginLeft);
|
|
|
|
|
orientedMarginTop += cachedScreenMargin;
|
|
|
|
|
orientedMarginLeft += cachedScreenMargin;
|
|
|
|
|
orientedMarginRight += cachedScreenMargin;
|
|
|
|
|
orientedMarginBottom += statusBarMargin;
|
|
|
|
|
|
|
|
|
|
const int lineHeight = renderer.getLineHeight(cachedFontId);
|
|
|
|
|
const int contentWidth = viewportWidth;
|
|
|
|
|
|
|
|
|
|
// Render text lines with alignment
|
|
|
|
|
auto renderLines = [&]() {
|
|
|
|
|
int y = orientedMarginTop;
|
|
|
|
|
for (const auto& line : currentPageLines) {
|
|
|
|
|
if (!line.empty()) {
|
|
|
|
|
int x = orientedMarginLeft;
|
|
|
|
|
|
|
|
|
|
// Apply text alignment
|
|
|
|
|
switch (cachedParagraphAlignment) {
|
|
|
|
|
case CrossPointSettings::LEFT_ALIGN:
|
|
|
|
|
default:
|
|
|
|
|
// x already set to left margin
|
|
|
|
|
break;
|
|
|
|
|
case CrossPointSettings::CENTER_ALIGN: {
|
|
|
|
|
int textWidth = renderer.getTextWidth(cachedFontId, line.c_str());
|
|
|
|
|
x = orientedMarginLeft + (contentWidth - textWidth) / 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CrossPointSettings::RIGHT_ALIGN: {
|
|
|
|
|
int textWidth = renderer.getTextWidth(cachedFontId, line.c_str());
|
|
|
|
|
x = orientedMarginLeft + contentWidth - textWidth;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CrossPointSettings::JUSTIFIED:
|
|
|
|
|
// For plain text, justified is treated as left-aligned
|
|
|
|
|
// (true justification would require word spacing adjustments)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderer.drawText(cachedFontId, x, y, line.c_str());
|
|
|
|
|
}
|
|
|
|
|
y += lineHeight;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// First pass: BW rendering
|
|
|
|
|
renderLines();
|
|
|
|
|
renderStatusBar(orientedMarginRight, orientedMarginBottom, orientedMarginLeft);
|
|
|
|
|
|
|
|
|
|
if (pagesUntilFullRefresh <= 1) {
|
2026-01-27 18:50:15 +01:00
|
|
|
renderer.displayBuffer(HalDisplay::HALF_REFRESH);
|
2026-01-14 19:36:40 +09:00
|
|
|
pagesUntilFullRefresh = SETTINGS.getRefreshFrequency();
|
|
|
|
|
} else {
|
|
|
|
|
renderer.displayBuffer();
|
|
|
|
|
pagesUntilFullRefresh--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Grayscale rendering pass (for anti-aliased fonts)
|
|
|
|
|
if (SETTINGS.textAntiAliasing) {
|
|
|
|
|
// Save BW buffer for restoration after grayscale pass
|
|
|
|
|
renderer.storeBwBuffer();
|
|
|
|
|
|
|
|
|
|
renderer.clearScreen(0x00);
|
|
|
|
|
renderer.setRenderMode(GfxRenderer::GRAYSCALE_LSB);
|
|
|
|
|
renderLines();
|
|
|
|
|
renderer.copyGrayscaleLsbBuffers();
|
|
|
|
|
|
|
|
|
|
renderer.clearScreen(0x00);
|
|
|
|
|
renderer.setRenderMode(GfxRenderer::GRAYSCALE_MSB);
|
|
|
|
|
renderLines();
|
|
|
|
|
renderer.copyGrayscaleMsbBuffers();
|
|
|
|
|
|
|
|
|
|
renderer.displayGrayBuffer();
|
|
|
|
|
renderer.setRenderMode(GfxRenderer::BW);
|
|
|
|
|
|
|
|
|
|
// Restore BW buffer
|
|
|
|
|
renderer.restoreBwBuffer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::renderStatusBar(const int orientedMarginRight, const int orientedMarginBottom,
|
|
|
|
|
const int orientedMarginLeft) const {
|
2026-01-27 12:25:44 +00:00
|
|
|
const bool showProgressPercentage = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL;
|
2026-02-05 10:49:38 -05:00
|
|
|
const bool showProgressBar = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::BOOK_PROGRESS_BAR ||
|
|
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::ONLY_BOOK_PROGRESS_BAR;
|
|
|
|
|
const bool showChapterProgressBar = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::CHAPTER_PROGRESS_BAR;
|
2026-01-27 12:25:44 +00:00
|
|
|
const bool showProgressText = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL ||
|
2026-02-05 10:49:38 -05:00
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::BOOK_PROGRESS_BAR;
|
|
|
|
|
const bool showBookPercentage = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::CHAPTER_PROGRESS_BAR;
|
2026-01-14 19:36:40 +09:00
|
|
|
const bool showBattery = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::NO_PROGRESS ||
|
2026-01-27 12:25:44 +00:00
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL ||
|
2026-02-05 10:49:38 -05:00
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::BOOK_PROGRESS_BAR ||
|
|
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::CHAPTER_PROGRESS_BAR;
|
2026-01-14 19:36:40 +09:00
|
|
|
const bool showTitle = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::NO_PROGRESS ||
|
2026-01-27 12:25:44 +00:00
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL ||
|
2026-02-05 10:49:38 -05:00
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::BOOK_PROGRESS_BAR ||
|
|
|
|
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::CHAPTER_PROGRESS_BAR;
|
2026-01-27 12:25:44 +00:00
|
|
|
const bool showBatteryPercentage =
|
|
|
|
|
SETTINGS.hideBatteryPercentage == CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_NEVER;
|
2026-01-14 19:36:40 +09:00
|
|
|
|
feat: UI themes, Lyra (#528)
## Summary
### What is the goal of this PR?
- Visual UI overhaul
- UI theme selection
### What changes are included?
- Added a setting "UI Theme": Classic, Lyra
- The classic theme is the current Crosspoint theme
- The Lyra theme implements these mockups:
https://www.figma.com/design/UhxoV4DgUnfrDQgMPPTXog/Lyra-Theme?node-id=2003-7596&t=4CSOZqf0n9uQMxDt-0
by Discord users yagofarias, ruby and gan_shu
- New functions in GFXRenderer to render rounded rectangles, greyscale
fills (using dithering) and thick lines
- Basic UI components are factored into BaseTheme methods which can be
overridden by each additional theme. Methods that are not overridden
will fallback to BaseTheme behavior. This means any new
features/components in CrossPoint only need to be developed for the
"Classic" BaseTheme.
- Additional themes can easily be developed by the community using this
foundation



## Additional Context
- Only the Home, Library and main Settings screens have been implemented
so far, this will be extended to the transfer screens and chapter
selection screen later on, but we need to get the ball rolling somehow
:)
- Loading extra covers on the home screen in the Lyra theme takes a
little more time (about 2 seconds), I added a loading bar popup (reusing
the Indexing progress bar from the reader view, factored into a neat UI
component) but the popup adds ~400ms to the loading time.
- ~~Home screen thumbnails will need to be generated separately for each
theme, because they are displayed in different sizes. Because we're
using dithering, displaying a thumb with the wrong size causes the
picture to look janky or dark as it does on the screenshots above. No
worries this will be fixed in a future PR.~~ Thumbs are now generated
with a size parameter
- UI Icons will need to be implemented in a future PR.
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**PARTIALLY**_
This is not a vibe coded PR. Copilot was used for autocompletion to save
time but I reviewed, understood and edited all generated code.
---------
Co-authored-by: Dave Allie <dave@daveallie.com>
2026-02-05 17:50:11 +07:00
|
|
|
auto metrics = UITheme::getInstance().getMetrics();
|
2026-01-14 19:36:40 +09:00
|
|
|
const auto screenHeight = renderer.getScreenHeight();
|
2026-02-05 10:49:38 -05:00
|
|
|
// Adjust text position upward when progress bar is shown to avoid overlap
|
2026-01-14 19:36:40 +09:00
|
|
|
const auto textY = screenHeight - orientedMarginBottom - 4;
|
|
|
|
|
int progressTextWidth = 0;
|
|
|
|
|
|
2026-01-27 12:25:44 +00:00
|
|
|
const float progress = totalPages > 0 ? (currentPage + 1) * 100.0f / totalPages : 0;
|
|
|
|
|
|
2026-02-05 10:49:38 -05:00
|
|
|
if (showProgressText || showProgressPercentage || showBookPercentage) {
|
2026-01-27 12:25:44 +00:00
|
|
|
char progressStr[32];
|
|
|
|
|
if (showProgressPercentage) {
|
|
|
|
|
snprintf(progressStr, sizeof(progressStr), "%d/%d %.0f%%", currentPage + 1, totalPages, progress);
|
2026-02-05 10:49:38 -05:00
|
|
|
} else if (showBookPercentage) {
|
|
|
|
|
snprintf(progressStr, sizeof(progressStr), "%.0f%%", progress);
|
2026-01-27 12:25:44 +00:00
|
|
|
} else {
|
|
|
|
|
snprintf(progressStr, sizeof(progressStr), "%d/%d", currentPage + 1, totalPages);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progressStr);
|
2026-01-14 19:36:40 +09:00
|
|
|
renderer.drawText(SMALL_FONT_ID, renderer.getScreenWidth() - orientedMarginRight - progressTextWidth, textY,
|
2026-01-27 12:25:44 +00:00
|
|
|
progressStr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showProgressBar) {
|
|
|
|
|
// Draw progress bar at the very bottom of the screen, from edge to edge of viewable area
|
2026-02-05 10:49:38 -05:00
|
|
|
GUI.drawReadingProgressBar(renderer, static_cast<size_t>(progress));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showChapterProgressBar) {
|
|
|
|
|
// For text mode, treat the entire book as one chapter, so chapter progress == book progress
|
|
|
|
|
GUI.drawReadingProgressBar(renderer, static_cast<size_t>(progress));
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showBattery) {
|
feat: UI themes, Lyra (#528)
## Summary
### What is the goal of this PR?
- Visual UI overhaul
- UI theme selection
### What changes are included?
- Added a setting "UI Theme": Classic, Lyra
- The classic theme is the current Crosspoint theme
- The Lyra theme implements these mockups:
https://www.figma.com/design/UhxoV4DgUnfrDQgMPPTXog/Lyra-Theme?node-id=2003-7596&t=4CSOZqf0n9uQMxDt-0
by Discord users yagofarias, ruby and gan_shu
- New functions in GFXRenderer to render rounded rectangles, greyscale
fills (using dithering) and thick lines
- Basic UI components are factored into BaseTheme methods which can be
overridden by each additional theme. Methods that are not overridden
will fallback to BaseTheme behavior. This means any new
features/components in CrossPoint only need to be developed for the
"Classic" BaseTheme.
- Additional themes can easily be developed by the community using this
foundation



## Additional Context
- Only the Home, Library and main Settings screens have been implemented
so far, this will be extended to the transfer screens and chapter
selection screen later on, but we need to get the ball rolling somehow
:)
- Loading extra covers on the home screen in the Lyra theme takes a
little more time (about 2 seconds), I added a loading bar popup (reusing
the Indexing progress bar from the reader view, factored into a neat UI
component) but the popup adds ~400ms to the loading time.
- ~~Home screen thumbnails will need to be generated separately for each
theme, because they are displayed in different sizes. Because we're
using dithering, displaying a thumb with the wrong size causes the
picture to look janky or dark as it does on the screenshots above. No
worries this will be fixed in a future PR.~~ Thumbs are now generated
with a size parameter
- UI Icons will need to be implemented in a future PR.
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**PARTIALLY**_
This is not a vibe coded PR. Copilot was used for autocompletion to save
time but I reviewed, understood and edited all generated code.
---------
Co-authored-by: Dave Allie <dave@daveallie.com>
2026-02-05 17:50:11 +07:00
|
|
|
GUI.drawBattery(renderer, Rect{orientedMarginLeft, textY, metrics.batteryWidth, metrics.batteryHeight},
|
|
|
|
|
showBatteryPercentage);
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showTitle) {
|
|
|
|
|
const int titleMarginLeft = 50 + 30 + orientedMarginLeft;
|
|
|
|
|
const int titleMarginRight = progressTextWidth + 30 + orientedMarginRight;
|
|
|
|
|
const int availableTextWidth = renderer.getScreenWidth() - titleMarginLeft - titleMarginRight;
|
|
|
|
|
|
|
|
|
|
std::string title = txt->getTitle();
|
|
|
|
|
int titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
2026-02-01 16:23:48 +05:00
|
|
|
if (titleWidth > availableTextWidth) {
|
|
|
|
|
title = renderer.truncatedText(SMALL_FONT_ID, title.c_str(), availableTextWidth);
|
2026-01-14 19:36:40 +09:00
|
|
|
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderer.drawText(SMALL_FONT_ID, titleMarginLeft + (availableTextWidth - titleWidth) / 2, textY, title.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::saveProgress() const {
|
|
|
|
|
FsFile f;
|
2026-02-08 21:29:14 +01:00
|
|
|
if (Storage.openFileForWrite("TRS", txt->getCachePath() + "/progress.bin", f)) {
|
2026-01-14 19:36:40 +09:00
|
|
|
uint8_t data[4];
|
|
|
|
|
data[0] = currentPage & 0xFF;
|
|
|
|
|
data[1] = (currentPage >> 8) & 0xFF;
|
|
|
|
|
data[2] = 0;
|
|
|
|
|
data[3] = 0;
|
|
|
|
|
f.write(data, 4);
|
|
|
|
|
f.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::loadProgress() {
|
|
|
|
|
FsFile f;
|
2026-02-08 21:29:14 +01:00
|
|
|
if (Storage.openFileForRead("TRS", txt->getCachePath() + "/progress.bin", f)) {
|
2026-01-14 19:36:40 +09:00
|
|
|
uint8_t data[4];
|
|
|
|
|
if (f.read(data, 4) == 4) {
|
|
|
|
|
currentPage = data[0] + (data[1] << 8);
|
|
|
|
|
if (currentPage >= totalPages) {
|
|
|
|
|
currentPage = totalPages - 1;
|
|
|
|
|
}
|
|
|
|
|
if (currentPage < 0) {
|
|
|
|
|
currentPage = 0;
|
|
|
|
|
}
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Loaded progress: page %d/%d", currentPage, totalPages);
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|
|
|
|
|
f.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TxtReaderActivity::loadPageIndexCache() {
|
|
|
|
|
// Cache file format (using serialization module):
|
|
|
|
|
// - uint32_t: magic "TXTI"
|
|
|
|
|
// - uint8_t: cache version
|
|
|
|
|
// - uint32_t: file size (to validate cache)
|
|
|
|
|
// - int32_t: viewport width
|
|
|
|
|
// - int32_t: lines per page
|
|
|
|
|
// - int32_t: font ID (to invalidate cache on font change)
|
|
|
|
|
// - int32_t: screen margin (to invalidate cache on margin change)
|
|
|
|
|
// - uint8_t: paragraph alignment (to invalidate cache on alignment change)
|
|
|
|
|
// - uint32_t: total pages count
|
|
|
|
|
// - N * uint32_t: page offsets
|
|
|
|
|
|
|
|
|
|
std::string cachePath = txt->getCachePath() + "/index.bin";
|
|
|
|
|
FsFile f;
|
2026-02-08 21:29:14 +01:00
|
|
|
if (!Storage.openFileForRead("TRS", cachePath, f)) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "No page index cache found");
|
2026-01-14 19:36:40 +09:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read and validate header using serialization module
|
|
|
|
|
uint32_t magic;
|
|
|
|
|
serialization::readPod(f, magic);
|
|
|
|
|
if (magic != CACHE_MAGIC) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Cache magic mismatch, rebuilding");
|
2026-01-14 19:36:40 +09:00
|
|
|
f.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t version;
|
|
|
|
|
serialization::readPod(f, version);
|
|
|
|
|
if (version != CACHE_VERSION) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Cache version mismatch (%d != %d), rebuilding", version, CACHE_VERSION);
|
2026-01-14 19:36:40 +09:00
|
|
|
f.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t fileSize;
|
|
|
|
|
serialization::readPod(f, fileSize);
|
|
|
|
|
if (fileSize != txt->getFileSize()) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Cache file size mismatch, rebuilding");
|
2026-01-14 19:36:40 +09:00
|
|
|
f.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t cachedWidth;
|
|
|
|
|
serialization::readPod(f, cachedWidth);
|
|
|
|
|
if (cachedWidth != viewportWidth) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Cache viewport width mismatch, rebuilding");
|
2026-01-14 19:36:40 +09:00
|
|
|
f.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t cachedLines;
|
|
|
|
|
serialization::readPod(f, cachedLines);
|
|
|
|
|
if (cachedLines != linesPerPage) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Cache lines per page mismatch, rebuilding");
|
2026-01-14 19:36:40 +09:00
|
|
|
f.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t fontId;
|
|
|
|
|
serialization::readPod(f, fontId);
|
|
|
|
|
if (fontId != cachedFontId) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Cache font ID mismatch (%d != %d), rebuilding", fontId, cachedFontId);
|
2026-01-14 19:36:40 +09:00
|
|
|
f.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t margin;
|
|
|
|
|
serialization::readPod(f, margin);
|
|
|
|
|
if (margin != cachedScreenMargin) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Cache screen margin mismatch, rebuilding");
|
2026-01-14 19:36:40 +09:00
|
|
|
f.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t alignment;
|
|
|
|
|
serialization::readPod(f, alignment);
|
|
|
|
|
if (alignment != cachedParagraphAlignment) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Cache paragraph alignment mismatch, rebuilding");
|
2026-01-14 19:36:40 +09:00
|
|
|
f.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t numPages;
|
|
|
|
|
serialization::readPod(f, numPages);
|
|
|
|
|
|
|
|
|
|
// Read page offsets
|
|
|
|
|
pageOffsets.clear();
|
|
|
|
|
pageOffsets.reserve(numPages);
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < numPages; i++) {
|
|
|
|
|
uint32_t offset;
|
|
|
|
|
serialization::readPod(f, offset);
|
|
|
|
|
pageOffsets.push_back(offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f.close();
|
|
|
|
|
totalPages = pageOffsets.size();
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Loaded page index cache: %d pages", totalPages);
|
2026-01-14 19:36:40 +09:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TxtReaderActivity::savePageIndexCache() const {
|
|
|
|
|
std::string cachePath = txt->getCachePath() + "/index.bin";
|
|
|
|
|
FsFile f;
|
2026-02-08 21:29:14 +01:00
|
|
|
if (!Storage.openFileForWrite("TRS", cachePath, f)) {
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_ERR("TRS", "Failed to save page index cache");
|
2026-01-14 19:36:40 +09:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write header using serialization module
|
|
|
|
|
serialization::writePod(f, CACHE_MAGIC);
|
|
|
|
|
serialization::writePod(f, CACHE_VERSION);
|
|
|
|
|
serialization::writePod(f, static_cast<uint32_t>(txt->getFileSize()));
|
|
|
|
|
serialization::writePod(f, static_cast<int32_t>(viewportWidth));
|
|
|
|
|
serialization::writePod(f, static_cast<int32_t>(linesPerPage));
|
|
|
|
|
serialization::writePod(f, static_cast<int32_t>(cachedFontId));
|
|
|
|
|
serialization::writePod(f, static_cast<int32_t>(cachedScreenMargin));
|
|
|
|
|
serialization::writePod(f, cachedParagraphAlignment);
|
|
|
|
|
serialization::writePod(f, static_cast<uint32_t>(pageOffsets.size()));
|
|
|
|
|
|
|
|
|
|
// Write page offsets
|
|
|
|
|
for (size_t offset : pageOffsets) {
|
|
|
|
|
serialization::writePod(f, static_cast<uint32_t>(offset));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f.close();
|
2026-02-13 12:16:39 +01:00
|
|
|
LOG_DBG("TRS", "Saved page index cache: %d pages", totalPages);
|
2026-01-14 19:36:40 +09:00
|
|
|
}
|