feat: split status bar setting (#733)
## 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>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "MappedInputManager.h"
|
||||
#include "OtaUpdateActivity.h"
|
||||
#include "SettingsList.h"
|
||||
#include "StatusBarSettingsActivity.h"
|
||||
#include "activities/network/WifiSelectionActivity.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
@@ -51,6 +52,7 @@ void SettingsActivity::onEnter() {
|
||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLEAR_READING_CACHE, SettingAction::ClearCache));
|
||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_CHECK_UPDATES, SettingAction::CheckForUpdates));
|
||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_LANGUAGE, SettingAction::Language));
|
||||
readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));
|
||||
|
||||
// Reset selection to first category
|
||||
selectedCategoryIndex = 0;
|
||||
@@ -181,6 +183,9 @@ void SettingsActivity::toggleCurrentSetting() {
|
||||
case SettingAction::RemapFrontButtons:
|
||||
enterSubActivity(new ButtonRemapActivity(renderer, mappedInput, onComplete));
|
||||
break;
|
||||
case SettingAction::CustomiseStatusBar:
|
||||
enterSubActivity(new StatusBarSettingsActivity(renderer, mappedInput, onComplete));
|
||||
break;
|
||||
case SettingAction::KOReaderSync:
|
||||
enterSubActivity(new KOReaderSettingsActivity(renderer, mappedInput, onComplete));
|
||||
break;
|
||||
@@ -259,4 +264,4 @@ void SettingsActivity::render(Activity::RenderLock&&) {
|
||||
|
||||
// Always use standard refresh for settings screen
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ enum class SettingType { TOGGLE, ENUM, ACTION, VALUE, STRING };
|
||||
enum class SettingAction {
|
||||
None,
|
||||
RemapFrontButtons,
|
||||
CustomiseStatusBar,
|
||||
KOReaderSync,
|
||||
OPDSBrowser,
|
||||
Network,
|
||||
|
||||
174
src/activities/settings/StatusBarSettingsActivity.cpp
Normal file
174
src/activities/settings/StatusBarSettingsActivity.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
#include "StatusBarSettingsActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <I18n.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
namespace {
|
||||
constexpr int MENU_ITEMS = 6;
|
||||
const StrId menuNames[MENU_ITEMS] = {StrId::STR_CHAPTER_PAGE_COUNT,
|
||||
StrId::STR_BOOK_PROGRESS_PERCENTAGE,
|
||||
StrId::STR_PROGRESS_BAR,
|
||||
StrId::STR_PROGRESS_BAR_THICKNESS,
|
||||
StrId::STR_TITLE,
|
||||
StrId::STR_BATTERY};
|
||||
constexpr int PROGRESS_BAR_ITEMS = 3;
|
||||
const StrId progressBarNames[PROGRESS_BAR_ITEMS] = {StrId::STR_BOOK, StrId::STR_CHAPTER, StrId::STR_HIDE};
|
||||
|
||||
constexpr int PROGRESS_BAR_THICKNESS_ITEMS = 3;
|
||||
const StrId progressBarThicknessNames[PROGRESS_BAR_THICKNESS_ITEMS] = {
|
||||
StrId::STR_PROGRESS_BAR_THIN, StrId::STR_PROGRESS_BAR_MEDIUM, StrId::STR_PROGRESS_BAR_THICK};
|
||||
|
||||
constexpr int TITLE_ITEMS = 3;
|
||||
const StrId titleNames[TITLE_ITEMS] = {StrId::STR_BOOK, StrId::STR_CHAPTER, StrId::STR_HIDE};
|
||||
|
||||
const char* translatedShow = tr(STR_SHOW);
|
||||
const char* translatedHide = tr(STR_HIDE);
|
||||
|
||||
const int widthMargin = 10;
|
||||
const int verticalPreviewPadding = 50;
|
||||
const int verticalPreviewTextPadding = 40;
|
||||
} // namespace
|
||||
|
||||
void StatusBarSettingsActivity::onEnter() {
|
||||
Activity::onEnter();
|
||||
|
||||
selectedIndex = 0;
|
||||
|
||||
// Clamp statusBarProgressBar and statusBarTitle in case of corrupt/migrated data
|
||||
if (SETTINGS.statusBarProgressBar >= PROGRESS_BAR_ITEMS) {
|
||||
SETTINGS.statusBarProgressBar = CrossPointSettings::STATUS_BAR_PROGRESS_BAR::HIDE_PROGRESS;
|
||||
}
|
||||
|
||||
if (SETTINGS.statusBarTitle >= PROGRESS_BAR_THICKNESS_ITEMS) {
|
||||
SETTINGS.statusBarTitle = CrossPointSettings::STATUS_BAR_PROGRESS_BAR_THICKNESS::PROGRESS_BAR_NORMAL;
|
||||
}
|
||||
|
||||
if (SETTINGS.statusBarTitle >= TITLE_ITEMS) {
|
||||
SETTINGS.statusBarTitle = CrossPointSettings::STATUS_BAR_TITLE::HIDE_TITLE;
|
||||
}
|
||||
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
void StatusBarSettingsActivity::onExit() { Activity::onExit(); }
|
||||
|
||||
void StatusBarSettingsActivity::loop() {
|
||||
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
|
||||
onBack();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
|
||||
handleSelection();
|
||||
requestUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle navigation
|
||||
buttonNavigator.onNextRelease([this] {
|
||||
selectedIndex = ButtonNavigator::nextIndex(selectedIndex, MENU_ITEMS);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onPreviousRelease([this] {
|
||||
selectedIndex = ButtonNavigator::previousIndex(selectedIndex, MENU_ITEMS);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onNextContinuous([this] {
|
||||
selectedIndex = ButtonNavigator::nextIndex(selectedIndex, MENU_ITEMS);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onPreviousContinuous([this] {
|
||||
selectedIndex = ButtonNavigator::previousIndex(selectedIndex, MENU_ITEMS);
|
||||
requestUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
void StatusBarSettingsActivity::handleSelection() {
|
||||
if (selectedIndex == 0) {
|
||||
// Chapter Page Count
|
||||
SETTINGS.statusBarChapterPageCount = (SETTINGS.statusBarChapterPageCount + 1) % 2;
|
||||
} else if (selectedIndex == 1) {
|
||||
// Book Progress %
|
||||
SETTINGS.statusBarBookProgressPercentage = (SETTINGS.statusBarBookProgressPercentage + 1) % 2;
|
||||
} else if (selectedIndex == 2) {
|
||||
// Progress Bar
|
||||
SETTINGS.statusBarProgressBar = (SETTINGS.statusBarProgressBar + 1) % PROGRESS_BAR_ITEMS;
|
||||
} else if (selectedIndex == 3) {
|
||||
// Progress Bar Thickness
|
||||
SETTINGS.statusBarProgressBarThickness =
|
||||
(SETTINGS.statusBarProgressBarThickness + 1) % PROGRESS_BAR_THICKNESS_ITEMS;
|
||||
} else if (selectedIndex == 4) {
|
||||
// Chapter Title
|
||||
SETTINGS.statusBarTitle = (SETTINGS.statusBarTitle + 1) % TITLE_ITEMS;
|
||||
} else if (selectedIndex == 5) {
|
||||
// Show Battery
|
||||
SETTINGS.statusBarBattery = (SETTINGS.statusBarBattery + 1) % 2;
|
||||
}
|
||||
SETTINGS.saveToFile();
|
||||
}
|
||||
|
||||
void StatusBarSettingsActivity::render(Activity::RenderLock&&) {
|
||||
renderer.clearScreen();
|
||||
|
||||
auto metrics = UITheme::getInstance().getMetrics();
|
||||
const auto pageWidth = renderer.getScreenWidth();
|
||||
const auto pageHeight = renderer.getScreenHeight();
|
||||
|
||||
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_CUSTOMISE_STATUS_BAR));
|
||||
|
||||
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
|
||||
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2;
|
||||
GUI.drawList(
|
||||
renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast<int>(MENU_ITEMS),
|
||||
static_cast<int>(selectedIndex), [](int index) { return std::string(I18N.get(menuNames[index])); }, nullptr,
|
||||
nullptr,
|
||||
[this](int index) {
|
||||
// Draw status for each setting
|
||||
if (index == 0) {
|
||||
return SETTINGS.statusBarChapterPageCount ? translatedShow : translatedHide;
|
||||
} else if (index == 1) {
|
||||
return SETTINGS.statusBarBookProgressPercentage ? translatedShow : translatedHide;
|
||||
} else if (index == 2) {
|
||||
return I18N.get(progressBarNames[SETTINGS.statusBarProgressBar]);
|
||||
} else if (index == 3) {
|
||||
return I18N.get(progressBarThicknessNames[SETTINGS.statusBarProgressBarThickness]);
|
||||
} else if (index == 4) {
|
||||
return I18N.get(titleNames[SETTINGS.statusBarTitle]);
|
||||
} else if (index == 5) {
|
||||
return SETTINGS.statusBarBattery ? translatedShow : translatedHide;
|
||||
} else {
|
||||
return translatedHide;
|
||||
}
|
||||
},
|
||||
true);
|
||||
|
||||
// Draw button hints
|
||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_TOGGLE), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
||||
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
|
||||
std::string title;
|
||||
if (SETTINGS.statusBarTitle == CrossPointSettings::STATUS_BAR_TITLE::BOOK_TITLE) {
|
||||
title = tr(STR_EXAMPLE_BOOK);
|
||||
} else {
|
||||
title = tr(STR_EXAMPLE_CHAPTER);
|
||||
}
|
||||
|
||||
GUI.drawStatusBar(renderer, 75, 8, 32, title, verticalPreviewPadding);
|
||||
|
||||
renderer.drawText(UI_10_FONT_ID, metrics.contentSidePadding,
|
||||
renderer.getScreenHeight() - UITheme::getInstance().getStatusBarHeight() - verticalPreviewPadding -
|
||||
verticalPreviewTextPadding,
|
||||
tr(STR_PREVIEW));
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
30
src/activities/settings/StatusBarSettingsActivity.h
Normal file
30
src/activities/settings/StatusBarSettingsActivity.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
// Reader status bar configuration activity
|
||||
class StatusBarSettingsActivity final : public Activity {
|
||||
public:
|
||||
explicit StatusBarSettingsActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
||||
const std::function<void()>& onBack)
|
||||
: Activity("StatusBarSettings", renderer, mappedInput), onBack(onBack) {}
|
||||
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void loop() override;
|
||||
void render(Activity::RenderLock&&) override;
|
||||
|
||||
private:
|
||||
ButtonNavigator buttonNavigator;
|
||||
|
||||
int selectedIndex = 0;
|
||||
|
||||
const std::function<void()> onBack;
|
||||
|
||||
static void taskTrampoline(void* param);
|
||||
void handleSelection();
|
||||
};
|
||||
Reference in New Issue
Block a user