## Summary This PR aims to reduce the complexity of the status bar by splitting the setting into 5: - Chapter Page Count - Book Progress % - Progress Bar - Chapter Title - Battery Indicator These are located within the new StausBarSettings activity, which also shows a preview of the bar the user has created <img width="513" height="806" alt="image" src="https://github.com/user-attachments/assets/cdf852fb-15d8-4da2-a74f-fd69294d7b05" /> <img width="483" height="797" alt="image" src="https://github.com/user-attachments/assets/66fc0c0d-ee51-4d31-b70d-e2bc043205d1" /> When updating from a previous version, the user's past settings are honoured. ## Additional Context The PR aims to remove any duplication of status bar code where possible, and extracts the status bar rendering into a new component - StatusBar It also adds a new (optional) padding option to the progress bar to allow the status bar to be shifted upwards - this is only intended for use in the settings. --- ### 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? No - although did help to decode some C++ errors --------- Co-authored-by: Arthur Tazhitdinov <lisnake@gmail.com>
59 lines
1.8 KiB
C++
59 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <Txt.h>
|
|
|
|
#include <vector>
|
|
|
|
#include "CrossPointSettings.h"
|
|
#include "activities/ActivityWithSubactivity.h"
|
|
|
|
class TxtReaderActivity final : public ActivityWithSubactivity {
|
|
std::unique_ptr<Txt> txt;
|
|
|
|
int currentPage = 0;
|
|
int totalPages = 1;
|
|
int pagesUntilFullRefresh = 0;
|
|
|
|
const std::function<void()> onGoBack;
|
|
const std::function<void()> onGoHome;
|
|
|
|
// Streaming text reader - stores file offsets for each page
|
|
std::vector<size_t> pageOffsets; // File offset for start of each page
|
|
std::vector<std::string> currentPageLines;
|
|
int linesPerPage = 0;
|
|
int viewportWidth = 0;
|
|
bool initialized = false;
|
|
|
|
// Cached settings for cache validation (different fonts/margins require re-indexing)
|
|
int cachedFontId = 0;
|
|
uint8_t cachedScreenMargin = 0;
|
|
uint8_t cachedParagraphAlignment = CrossPointSettings::LEFT_ALIGN;
|
|
int cachedOrientedMarginTop = 0;
|
|
int cachedOrientedMarginRight = 0;
|
|
int cachedOrientedMarginBottom = 0;
|
|
int cachedOrientedMarginLeft = 0;
|
|
|
|
void renderPage();
|
|
void renderStatusBar() const;
|
|
|
|
void initializeReader();
|
|
bool loadPageAtOffset(size_t offset, std::vector<std::string>& outLines, size_t& nextOffset);
|
|
void buildPageIndex();
|
|
bool loadPageIndexCache();
|
|
void savePageIndexCache() const;
|
|
void saveProgress() const;
|
|
void loadProgress();
|
|
|
|
public:
|
|
explicit TxtReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::unique_ptr<Txt> txt,
|
|
const std::function<void()>& onGoBack, const std::function<void()>& onGoHome)
|
|
: ActivityWithSubactivity("TxtReader", renderer, mappedInput),
|
|
txt(std::move(txt)),
|
|
onGoBack(onGoBack),
|
|
onGoHome(onGoHome) {}
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
void render(Activity::RenderLock&&) override;
|
|
};
|