Refacrored the separator component to be more flexible and reusable across different activities. Updated the EpubReaderMenuActivity and ClockSettingsActivity to utilize the new separator component for better UI consistency and maintainability. This change also involved updating the UITheme component to support the new separator styles.
This commit is contained in:
1 parent
e9e39e91ac
commit
e72ad0d2a9
6 files changed
+57
-26
No files matched your search
@@ -23,28 +23,27 @@ std::vector<ClockSettingsActivity::MenuItem> ClockSettingsActivity::buildMenuIte
|
||||
std::vector<MenuItem> items;
|
||||
items.reserve(7);
|
||||
// Settings
|
||||
items.push_back({Action::NONE, StrId::STR_SETTINGS_TITLE, true});
|
||||
items.push_back(MenuItem::separator(StrId::STR_SETTINGS_TITLE));
|
||||
items.push_back({Action::USE_CLOCK, StrId::STR_USE_CLOCK});
|
||||
items.push_back({Action::CLOCK_FORMAT, StrId::STR_CLOCK_FORMAT});
|
||||
items.push_back({Action::TIMEZONE, StrId::STR_TIMEZONE});
|
||||
|
||||
// Tools
|
||||
items.push_back({Action::NONE, StrId::STR_READER_TOOLS, true});
|
||||
items.push_back(MenuItem::separator(StrId::STR_READER_TOOLS));
|
||||
items.push_back({Action::DETECT_TIMEZONE, StrId::STR_DETECT_TIMEZONE});
|
||||
items.push_back({Action::SYNC_TIME, StrId::STR_SYNC_TIME});
|
||||
return items;
|
||||
}
|
||||
|
||||
std::function<bool(int)> ClockSettingsActivity::buildSelectablePredicate() const {
|
||||
return [this](int index) {
|
||||
return index >= 0 && index < static_cast<int>(menuItems.size()) && !menuItems[index].isSeparator;
|
||||
};
|
||||
}
|
||||
|
||||
void ClockSettingsActivity::onEnter() {
|
||||
Activity::onEnter();
|
||||
buttonNavigator.setSelectablePredicate(buildSelectablePredicate(), static_cast<int>(menuItems.size()));
|
||||
if (!buildSelectablePredicate()(selectedIndex)) {
|
||||
const auto pred = UITheme::makeSelectablePredicate(
|
||||
static_cast<int>(menuItems.size()), [this](int i) {
|
||||
const auto t = I18N.get(menuItems[i].labelId);
|
||||
return menuItems[i].isSeparator ? UITheme::makeSeparatorTitle(t) : t;
|
||||
});
|
||||
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
||||
if (!pred(selectedIndex)) {
|
||||
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
||||
}
|
||||
requestUpdate();
|
||||
|
||||
@@ -14,6 +14,7 @@ class ClockSettingsActivity final : public Activity {
|
||||
Action action;
|
||||
StrId labelId;
|
||||
bool isSeparator = false;
|
||||
static MenuItem separator(StrId label) { return {Action::NONE, label, true}; }
|
||||
};
|
||||
|
||||
ButtonNavigator buttonNavigator;
|
||||
@@ -22,7 +23,6 @@ class ClockSettingsActivity final : public Activity {
|
||||
|
||||
static std::vector<MenuItem> buildMenuItems();
|
||||
void handleSelection();
|
||||
std::function<bool(int)> buildSelectablePredicate() const;
|
||||
|
||||
public:
|
||||
explicit ClockSettingsActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)
|
||||
|
||||
Reference in new issue
Block a user