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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user