mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 15:17:42 +03:00
Moved progress functions to epub, showing integer percentages.
This commit is contained in:
parent
1208663f55
commit
714f386558
@ -316,3 +316,16 @@ int Epub::getTocIndexForSpineIndex(const int spineIndex) const {
|
||||
Serial.printf("[%lu] [EBP] TOC item not found\n", millis());
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t Epub::getBookSize() const {
|
||||
return getCumulativeSpineItemSize(getSpineItemsCount() - 1);
|
||||
}
|
||||
|
||||
// Calculate progress in book
|
||||
uint8_t Epub::calculateProgress(const int currentSpineIndex, const float currentSpineRead){
|
||||
size_t prevChapterSize = getCumulativeSpineItemSize(currentSpineIndex - 1);
|
||||
size_t curChapterSize = getCumulativeSpineItemSize(currentSpineIndex) - prevChapterSize;
|
||||
size_t bookSize = getBookSize();
|
||||
size_t sectionProgSize = currentSpineRead * curChapterSize;
|
||||
return round(static_cast<float>(prevChapterSize + sectionProgSize) / bookSize * 100.0);
|
||||
}
|
||||
|
||||
@ -58,4 +58,7 @@ class Epub {
|
||||
int getTocItemsCount() const;
|
||||
int getSpineIndexForTocIndex(int tocIndex) const;
|
||||
int getTocIndexForSpineIndex(int spineIndex) const;
|
||||
|
||||
size_t getBookSize() const;
|
||||
uint8_t calculateProgress(const int currentSpineIndex, const float currentSpineRead);
|
||||
};
|
||||
|
||||
@ -326,22 +326,12 @@ void EpubReaderScreen::renderStatusBar() const {
|
||||
constexpr auto textY = 776;
|
||||
|
||||
// Calculate progress in book
|
||||
size_t prevChapterSize = epub->getCumulativeSpineItemSize(currentSpineIndex - 1);
|
||||
size_t curChapterSize = epub->getCumulativeSpineItemSize(currentSpineIndex) - prevChapterSize;
|
||||
size_t bookSize = epub->getCumulativeSpineItemSize(epub->getSpineItemsCount() - 1);
|
||||
size_t sectionProgSize =
|
||||
static_cast<size_t>(static_cast<float>(section->currentPage) / section->pageCount * curChapterSize);
|
||||
float bookProgress = static_cast<float>(prevChapterSize + sectionProgSize) / bookSize * 100.0;
|
||||
char bookProgressStr[6] = "--.-";
|
||||
std:
|
||||
snprintf(bookProgressStr, 6, "%.1f", bookProgress);
|
||||
// Serial.printf("[%lu] [EBP] prevChapterSize: %u bookSize: %u sectionProgSize: %u bookSize:%u Book progress: %s
|
||||
// %%\n", millis(),
|
||||
// prevChapterSize, bookSize, sectionProgSize, bookSize, bookProgressStr);
|
||||
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) +
|
||||
" " + bookProgressStr + "%";
|
||||
" " + 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());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user