Refactor duplicate progress bar functions into drawStatusProgressBar

Co-authored-by: lukestein <44452336+lukestein@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-02-01 22:13:39 +00:00
parent 58c2d8453e
commit 9b8d565b99
4 changed files with 7 additions and 19 deletions

View File

@ -74,25 +74,14 @@ void ScreenComponents::fillPopupProgress(const GfxRenderer& renderer, const Popu
renderer.displayBuffer(HalDisplay::FAST_REFRESH); renderer.displayBuffer(HalDisplay::FAST_REFRESH);
} }
void ScreenComponents::drawBookProgressBar(const GfxRenderer& renderer, const size_t bookProgress) { void ScreenComponents::drawStatusProgressBar(const GfxRenderer& renderer, const size_t progress) {
int vieweableMarginTop, vieweableMarginRight, vieweableMarginBottom, vieweableMarginLeft; int vieweableMarginTop, vieweableMarginRight, vieweableMarginBottom, vieweableMarginLeft;
renderer.getOrientedViewableTRBL(&vieweableMarginTop, &vieweableMarginRight, &vieweableMarginBottom, renderer.getOrientedViewableTRBL(&vieweableMarginTop, &vieweableMarginRight, &vieweableMarginBottom,
&vieweableMarginLeft); &vieweableMarginLeft);
const int progressBarMaxWidth = renderer.getScreenWidth() - vieweableMarginLeft - vieweableMarginRight; const int progressBarMaxWidth = renderer.getScreenWidth() - vieweableMarginLeft - vieweableMarginRight;
const int progressBarY = renderer.getScreenHeight() - vieweableMarginBottom - PROGRESS_BAR_HEIGHT; const int progressBarY = renderer.getScreenHeight() - vieweableMarginBottom - PROGRESS_BAR_HEIGHT;
const int barWidth = progressBarMaxWidth * bookProgress / 100; const int barWidth = progressBarMaxWidth * progress / 100;
renderer.fillRect(vieweableMarginLeft, progressBarY, barWidth, PROGRESS_BAR_HEIGHT, true);
}
void ScreenComponents::drawChapterProgressBar(const GfxRenderer& renderer, const size_t chapterProgress) {
int vieweableMarginTop, vieweableMarginRight, vieweableMarginBottom, vieweableMarginLeft;
renderer.getOrientedViewableTRBL(&vieweableMarginTop, &vieweableMarginRight, &vieweableMarginBottom,
&vieweableMarginLeft);
const int progressBarMaxWidth = renderer.getScreenWidth() - vieweableMarginLeft - vieweableMarginRight;
const int progressBarY = renderer.getScreenHeight() - vieweableMarginBottom - PROGRESS_BAR_HEIGHT;
const int barWidth = progressBarMaxWidth * chapterProgress / 100;
renderer.fillRect(vieweableMarginLeft, progressBarY, barWidth, PROGRESS_BAR_HEIGHT, true); renderer.fillRect(vieweableMarginLeft, progressBarY, barWidth, PROGRESS_BAR_HEIGHT, true);
} }

View File

@ -23,8 +23,7 @@ class ScreenComponents {
}; };
static void drawBattery(const GfxRenderer& renderer, int left, int top, bool showPercentage = true); static void drawBattery(const GfxRenderer& renderer, int left, int top, bool showPercentage = true);
static void drawBookProgressBar(const GfxRenderer& renderer, size_t bookProgress); static void drawStatusProgressBar(const GfxRenderer& renderer, size_t progress);
static void drawChapterProgressBar(const GfxRenderer& renderer, size_t chapterProgress);
static PopupLayout drawPopup(const GfxRenderer& renderer, const char* message); static PopupLayout drawPopup(const GfxRenderer& renderer, const char* message);

View File

@ -541,14 +541,14 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in
if (showBookProgressBar) { if (showBookProgressBar) {
// Draw progress bar at the very bottom of the screen, from edge to edge of viewable area // Draw progress bar at the very bottom of the screen, from edge to edge of viewable area
ScreenComponents::drawBookProgressBar(renderer, static_cast<size_t>(bookProgress)); ScreenComponents::drawStatusProgressBar(renderer, static_cast<size_t>(bookProgress));
} }
if (showChapterProgressBar) { if (showChapterProgressBar) {
// Draw chapter progress bar at the very bottom of the screen, from edge to edge of viewable area // Draw chapter progress bar at the very bottom of the screen, from edge to edge of viewable area
const float chapterProgress = const float chapterProgress =
(section->pageCount > 0) ? (static_cast<float>(section->currentPage + 1) / section->pageCount) * 100 : 0; (section->pageCount > 0) ? (static_cast<float>(section->currentPage + 1) / section->pageCount) * 100 : 0;
ScreenComponents::drawChapterProgressBar(renderer, static_cast<size_t>(chapterProgress)); ScreenComponents::drawStatusProgressBar(renderer, static_cast<size_t>(chapterProgress));
} }
if (showBattery) { if (showBattery) {

View File

@ -527,12 +527,12 @@ void TxtReaderActivity::renderStatusBar(const int orientedMarginRight, const int
if (showProgressBar) { if (showProgressBar) {
// Draw progress bar at the very bottom of the screen, from edge to edge of viewable area // Draw progress bar at the very bottom of the screen, from edge to edge of viewable area
ScreenComponents::drawBookProgressBar(renderer, static_cast<size_t>(progress)); ScreenComponents::drawStatusProgressBar(renderer, static_cast<size_t>(progress));
} }
if (showChapterProgressBar) { if (showChapterProgressBar) {
// For text mode, treat the entire book as one chapter, so chapter progress == book progress // For text mode, treat the entire book as one chapter, so chapter progress == book progress
ScreenComponents::drawChapterProgressBar(renderer, static_cast<size_t>(progress)); ScreenComponents::drawStatusProgressBar(renderer, static_cast<size_t>(progress));
} }
if (showBattery) { if (showBattery) {