Calculate the progress in the book by file sizes of each chapter. (#38)

## Summary

Addresses #35.

Maybe it could be wise to do some caching of the spine sizes (but
performance isn't too bad).
This commit is contained in:
Jonas Diemer
2025-12-17 13:05:24 +01:00
committed by GitHub
parent 11f01d3a41
commit c78f2a9840
3 changed files with 39 additions and 2 deletions

View File

@@ -324,8 +324,14 @@ void EpubReaderScreen::renderContents(std::unique_ptr<Page> page) {
void EpubReaderScreen::renderStatusBar() const {
constexpr auto textY = 776;
// Calculate progress in book
float sectionChapterProg = static_cast<float>(section->currentPage) / section->pageCount;
uint8_t bookProgress = epub->calculateProgress(currentSpineIndex, sectionChapterProg);
// Right aligned text for progress counter
const std::string progress = std::to_string(section->currentPage + 1) + " / " + std::to_string(section->pageCount);
const std::string progress = std::to_string(section->currentPage + 1) + "/" + std::to_string(section->pageCount) +
" " + std::to_string(bookProgress) + "%";
const auto progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progress.c_str());
renderer.drawText(SMALL_FONT_ID, GfxRenderer::getScreenWidth() - marginRight - progressTextWidth, textY,
progress.c_str());