feat: Add status bar option "Full w/ Progress Bar" (#438)
## Summary * **What is the goal of this PR?** This PR introduces a new "Status Bar" mode that displays a visual progress bar at the bottom of the screen, providing readers with a graphical indication of their position within the book. * **What changes are included?** * **Settings**: Updated SettingsActivity to expand the "Status Bar" configuration with a new option: Full w/ Progress Bar. * **EPUB Reader**: Modified EpubReaderActivity to calculate the global book progress and render a progress bar at the bottom of the viewable area when the new setting is active. * **TXT Reader**: Modified TxtReaderActivity to implement similar progress bar rendering logic based on the current page and total page count. ## Additional Context * The progress bar is rendered with a height of 4 pixels at the very bottom of the screen (adjusted for margins). * The feature reuses the existing renderStatusBar logic but conditionally draws the bar instead of (or in addition to) other elements depending on the specific implementation details in each reader. * Renamed existing 'Full' mode to 'Full w/ Percentage' * Added new 'Full w/ Progress Bar' option <img src="https://github.com/user-attachments/assets/08c0dd49-c64c-4d4d-9fbb-f576c02d05d9" width="500"> --- ### 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**_
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
namespace {
|
||||
constexpr unsigned long goHomeMs = 1000;
|
||||
constexpr int statusBarMargin = 25;
|
||||
constexpr int progressBarMarginTop = 1;
|
||||
constexpr size_t CHUNK_SIZE = 8 * 1024; // 8KB chunk for reading
|
||||
|
||||
// Cache file magic and version
|
||||
@@ -158,7 +159,16 @@ void TxtReaderActivity::initializeReader() {
|
||||
orientedMarginTop += cachedScreenMargin;
|
||||
orientedMarginLeft += cachedScreenMargin;
|
||||
orientedMarginRight += cachedScreenMargin;
|
||||
orientedMarginBottom += statusBarMargin;
|
||||
orientedMarginBottom += cachedScreenMargin;
|
||||
|
||||
// Add status bar margin
|
||||
if (SETTINGS.statusBar != CrossPointSettings::STATUS_BAR_MODE::NONE) {
|
||||
// Add additional margin for status bar if progress bar is shown
|
||||
const bool showProgressBar = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL_WITH_PROGRESS_BAR ||
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::ONLY_PROGRESS_BAR;
|
||||
orientedMarginBottom += statusBarMargin - cachedScreenMargin +
|
||||
(showProgressBar ? (ScreenComponents::BOOK_PROGRESS_BAR_HEIGHT + progressBarMarginTop) : 0);
|
||||
}
|
||||
|
||||
viewportWidth = renderer.getScreenWidth() - orientedMarginLeft - orientedMarginRight;
|
||||
const int viewportHeight = renderer.getScreenHeight() - orientedMarginTop - orientedMarginBottom;
|
||||
@@ -499,27 +509,46 @@ void TxtReaderActivity::renderPage() {
|
||||
|
||||
void TxtReaderActivity::renderStatusBar(const int orientedMarginRight, const int orientedMarginBottom,
|
||||
const int orientedMarginLeft) const {
|
||||
const bool showProgress = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL;
|
||||
const bool showProgressPercentage = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL;
|
||||
const bool showProgressBar = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL_WITH_PROGRESS_BAR ||
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::ONLY_PROGRESS_BAR;
|
||||
const bool showProgressText = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL ||
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL_WITH_PROGRESS_BAR;
|
||||
const bool showBattery = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::NO_PROGRESS ||
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL;
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL ||
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL_WITH_PROGRESS_BAR;
|
||||
const bool showTitle = SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::NO_PROGRESS ||
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL;
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL ||
|
||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL_WITH_PROGRESS_BAR;
|
||||
const bool showBatteryPercentage =
|
||||
SETTINGS.hideBatteryPercentage == CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_NEVER;
|
||||
|
||||
const auto screenHeight = renderer.getScreenHeight();
|
||||
const auto textY = screenHeight - orientedMarginBottom - 4;
|
||||
int progressTextWidth = 0;
|
||||
|
||||
if (showProgress) {
|
||||
const int progress = totalPages > 0 ? (currentPage + 1) * 100 / totalPages : 0;
|
||||
const std::string progressStr =
|
||||
std::to_string(currentPage + 1) + "/" + std::to_string(totalPages) + " " + std::to_string(progress) + "%";
|
||||
progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progressStr.c_str());
|
||||
const float progress = totalPages > 0 ? (currentPage + 1) * 100.0f / totalPages : 0;
|
||||
|
||||
if (showProgressText || showProgressPercentage) {
|
||||
char progressStr[32];
|
||||
if (showProgressPercentage) {
|
||||
snprintf(progressStr, sizeof(progressStr), "%d/%d %.0f%%", currentPage + 1, totalPages, progress);
|
||||
} else {
|
||||
snprintf(progressStr, sizeof(progressStr), "%d/%d", currentPage + 1, totalPages);
|
||||
}
|
||||
|
||||
progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progressStr);
|
||||
renderer.drawText(SMALL_FONT_ID, renderer.getScreenWidth() - orientedMarginRight - progressTextWidth, textY,
|
||||
progressStr.c_str());
|
||||
progressStr);
|
||||
}
|
||||
|
||||
if (showProgressBar) {
|
||||
// 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));
|
||||
}
|
||||
|
||||
if (showBattery) {
|
||||
ScreenComponents::drawBattery(renderer, orientedMarginLeft, textY);
|
||||
ScreenComponents::drawBattery(renderer, orientedMarginLeft, textY, showBatteryPercentage);
|
||||
}
|
||||
|
||||
if (showTitle) {
|
||||
|
||||
Reference in New Issue
Block a user