Stage 2
This commit is contained in:
@@ -25,6 +25,11 @@ EpubReaderMenuActivity::EpubReaderMenuActivity(GfxRenderer& renderer, MappedInpu
|
|||||||
totalPages(totalPages),
|
totalPages(totalPages),
|
||||||
bookProgressPercent(bookProgressPercent) {}
|
bookProgressPercent(bookProgressPercent) {}
|
||||||
|
|
||||||
|
std::string EpubReaderMenuActivity::MenuItem::getTitle() const {
|
||||||
|
const auto t = I18N.get(labelId);
|
||||||
|
return isSeparator ? UITheme::makeSeparatorTitle(t) : t;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<EpubReaderMenuActivity::MenuItem> EpubReaderMenuActivity::buildMenuItems(bool hasFootnotes) {
|
std::vector<EpubReaderMenuActivity::MenuItem> EpubReaderMenuActivity::buildMenuItems(bool hasFootnotes) {
|
||||||
std::vector<MenuItem> items;
|
std::vector<MenuItem> items;
|
||||||
items.reserve(18);
|
items.reserve(18);
|
||||||
@@ -63,11 +68,7 @@ std::vector<EpubReaderMenuActivity::MenuItem> EpubReaderMenuActivity::buildMenuI
|
|||||||
void EpubReaderMenuActivity::onEnter() {
|
void EpubReaderMenuActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
const auto pred = UITheme::makeSelectablePredicate(
|
const auto pred = UITheme::makeSelectablePredicate(
|
||||||
static_cast<int>(menuItems.size()), [this](int i) {
|
static_cast<int>(menuItems.size()), [this](int i) { return menuItems[i].getTitle(); });
|
||||||
const auto& item = menuItems[i];
|
|
||||||
const auto t = I18N.get(item.labelId);
|
|
||||||
return item.isSeparator ? UITheme::makeSeparatorTitle(t) : t;
|
|
||||||
});
|
|
||||||
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
||||||
if (!pred(selectedIndex)) {
|
if (!pred(selectedIndex)) {
|
||||||
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
||||||
@@ -187,11 +188,7 @@ void EpubReaderMenuActivity::render(RenderLock&&) {
|
|||||||
GUI.drawList(
|
GUI.drawList(
|
||||||
renderer, Rect{contentRect.x, startY, contentRect.width, listHeight}, static_cast<int>(menuItems.size()),
|
renderer, Rect{contentRect.x, startY, contentRect.width, listHeight}, static_cast<int>(menuItems.size()),
|
||||||
selectedIndex,
|
selectedIndex,
|
||||||
[this](int index) {
|
[this](int index) { return menuItems[index].getTitle(); },
|
||||||
const auto& item = menuItems[index];
|
|
||||||
const auto title = I18N.get(item.labelId);
|
|
||||||
return item.isSeparator ? UITheme::makeSeparatorTitle(title) : title;
|
|
||||||
},
|
|
||||||
nullptr, nullptr,
|
nullptr, nullptr,
|
||||||
[this](int index) {
|
[this](int index) {
|
||||||
const auto& item = menuItems[index];
|
const auto& item = menuItems[index];
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class EpubReaderMenuActivity final : public Activity {
|
|||||||
StrId labelId;
|
StrId labelId;
|
||||||
bool isSeparator = false;
|
bool isSeparator = false;
|
||||||
static MenuItem separator(StrId label) { return {MenuAction::NONE, label, true}; }
|
static MenuItem separator(StrId label) { return {MenuAction::NONE, label, true}; }
|
||||||
|
[[nodiscard]] std::string getTitle() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<MenuItem> buildMenuItems(bool hasFootnotes);
|
static std::vector<MenuItem> buildMenuItems(bool hasFootnotes);
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ const StrId timeZoneNames[CrossPointSettings::TIMEZONE_COUNT] = {
|
|||||||
StrId::STR_TZ_EST, StrId::STR_TZ_CST, StrId::STR_TZ_MST, StrId::STR_TZ_PST};
|
StrId::STR_TZ_EST, StrId::STR_TZ_CST, StrId::STR_TZ_MST, StrId::STR_TZ_PST};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
std::string ClockSettingsActivity::MenuItem::getTitle() const {
|
||||||
|
const auto t = I18N.get(labelId);
|
||||||
|
return isSeparator ? UITheme::makeSeparatorTitle(t) : t;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ClockSettingsActivity::MenuItem> ClockSettingsActivity::buildMenuItems() {
|
std::vector<ClockSettingsActivity::MenuItem> ClockSettingsActivity::buildMenuItems() {
|
||||||
std::vector<MenuItem> items;
|
std::vector<MenuItem> items;
|
||||||
items.reserve(7);
|
items.reserve(7);
|
||||||
@@ -38,10 +43,7 @@ std::vector<ClockSettingsActivity::MenuItem> ClockSettingsActivity::buildMenuIte
|
|||||||
void ClockSettingsActivity::onEnter() {
|
void ClockSettingsActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
const auto pred = UITheme::makeSelectablePredicate(
|
const auto pred = UITheme::makeSelectablePredicate(
|
||||||
static_cast<int>(menuItems.size()), [this](int i) {
|
static_cast<int>(menuItems.size()), [this](int i) { return menuItems[i].getTitle(); });
|
||||||
const auto t = I18N.get(menuItems[i].labelId);
|
|
||||||
return menuItems[i].isSeparator ? UITheme::makeSeparatorTitle(t) : t;
|
|
||||||
});
|
|
||||||
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
||||||
if (!pred(selectedIndex)) {
|
if (!pred(selectedIndex)) {
|
||||||
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
||||||
@@ -124,10 +126,7 @@ void ClockSettingsActivity::render(RenderLock&&) {
|
|||||||
|
|
||||||
GUI.drawList(
|
GUI.drawList(
|
||||||
renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast<int>(menuItems.size()), selectedIndex,
|
renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast<int>(menuItems.size()), selectedIndex,
|
||||||
[this](int index) {
|
[this](int index) { return menuItems[index].getTitle(); },
|
||||||
const auto title = I18N.get(menuItems[index].labelId);
|
|
||||||
return menuItems[index].isSeparator ? UITheme::makeSeparatorTitle(title) : title;
|
|
||||||
},
|
|
||||||
nullptr, nullptr,
|
nullptr, nullptr,
|
||||||
[this](int index) {
|
[this](int index) {
|
||||||
const auto action = menuItems[index].action;
|
const auto action = menuItems[index].action;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class ClockSettingsActivity final : public Activity {
|
|||||||
StrId labelId;
|
StrId labelId;
|
||||||
bool isSeparator = false;
|
bool isSeparator = false;
|
||||||
static MenuItem separator(StrId label) { return {Action::NONE, label, true}; }
|
static MenuItem separator(StrId label) { return {Action::NONE, label, true}; }
|
||||||
|
[[nodiscard]] std::string getTitle() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
ButtonNavigator buttonNavigator;
|
ButtonNavigator buttonNavigator;
|
||||||
|
|||||||
@@ -36,22 +36,19 @@ class UITheme {
|
|||||||
// struct MenuItem {
|
// struct MenuItem {
|
||||||
// Action action; StrId labelId; bool isSeparator = false;
|
// Action action; StrId labelId; bool isSeparator = false;
|
||||||
// static MenuItem separator(StrId label) { return {Action::NONE, label, true}; }
|
// static MenuItem separator(StrId label) { return {Action::NONE, label, true}; }
|
||||||
|
// std::string getTitle() const; // implemented in .cpp: makeSeparatorTitle when isSeparator
|
||||||
// };
|
// };
|
||||||
// const std::vector<MenuItem> items = buildMenuItems();
|
// const std::vector<MenuItem> items = buildMenuItems();
|
||||||
// // In buildMenuItems, use MenuItem::separator(StrId) for section headers.
|
// // 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:
|
// // onEnter: wire navigation so separators are skipped:
|
||||||
// const auto pred = UITheme::makeSelectablePredicate(items.size(), titleGetter);
|
// const auto pred = UITheme::makeSelectablePredicate(items.size(),
|
||||||
|
// [this](int i) { return items[i].getTitle(); });
|
||||||
// buttonNavigator.setSelectablePredicate(pred, items.size());
|
// buttonNavigator.setSelectablePredicate(pred, items.size());
|
||||||
//
|
//
|
||||||
// // render: pass the same getter to drawList; separator rows are drawn automatically:
|
// // render: pass the same getter to drawList; separator rows are drawn automatically:
|
||||||
// GUI.drawList(renderer, rect, items.size(), selectedIndex, titleGetter, ...);
|
// GUI.drawList(renderer, rect, items.size(), selectedIndex,
|
||||||
|
// [this](int i) { return items[i].getTitle(); }, ...);
|
||||||
static std::function<bool(int)> makeSelectablePredicate(int total, std::function<std::string(int)> 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.
|
// Returns the drawable content Rect accounting for screen orientation and visible button hints.
|
||||||
|
|||||||
Reference in New Issue
Block a user