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:
@@ -26,6 +26,33 @@ class UITheme {
|
||||
static std::string makeSeparatorTitle(StrId labelId);
|
||||
static bool isSeparatorTitle(const std::string& title);
|
||||
static std::string stripSeparatorTitle(const std::string& title);
|
||||
// Returns a selectable predicate for use with ButtonNavigator::setSelectablePredicate().
|
||||
// Items whose title is marked as a separator (via makeSeparatorTitle) are skipped during
|
||||
// navigation. Pass the same title getter you pass to drawList so rendering and navigation
|
||||
// always agree on which items are separators.
|
||||
//
|
||||
// Typical usage pattern for a menu with section headers:
|
||||
//
|
||||
// struct MenuItem {
|
||||
// Action action; StrId labelId; bool isSeparator = false;
|
||||
// static MenuItem separator(StrId label) { return {Action::NONE, label, true}; }
|
||||
// };
|
||||
// const std::vector<MenuItem> items = buildMenuItems();
|
||||
// // In buildMenuItems, use MenuItem::separator(StrId) for section headers.
|
||||
//
|
||||
// // Title getter — used by both drawList and makeSelectablePredicate:
|
||||
// auto titleGetter = [&](int i) {
|
||||
// const auto t = I18N.get(items[i].labelId);
|
||||
// return items[i].isSeparator ? UITheme::makeSeparatorTitle(t) : t;
|
||||
// };
|
||||
//
|
||||
// // onEnter: wire navigation so separators are skipped:
|
||||
// const auto pred = UITheme::makeSelectablePredicate(items.size(), titleGetter);
|
||||
// buttonNavigator.setSelectablePredicate(pred, items.size());
|
||||
//
|
||||
// // render: pass the same getter to drawList; separator rows are drawn automatically:
|
||||
// GUI.drawList(renderer, rect, items.size(), selectedIndex, titleGetter, ...);
|
||||
static std::function<bool(int)> makeSelectablePredicate(int total, std::function<std::string(int)> titleGetter);
|
||||
|
||||
// Returns the drawable content Rect accounting for screen orientation and visible button hints.
|
||||
// Bottom hints occupy the physical bottom edge; side hints occupy the physical right edge.
|
||||
|
||||
Reference in New Issue
Block a user