Files
crosspoint-reader-mod/src/activities/reader/DictionaryMenuActivity.cpp
cottongin 0493f300be feat: restructure reader menu with submenus and long-press TOC
- Replace scattered book management actions (Archive, Delete, Reindex,
  Delete Cache) with single "Manage Book" entry that opens
  BookManageMenuActivity as a submenu.
- Replace scattered dictionary actions (Lookup Word, Lookup History,
  Delete Dict Cache) with single "Dictionary" entry that opens new
  DictionaryMenuActivity submenu.
- Add long-press Confirm (700ms) to open Table of Contents directly
  from the reader, bypassing the menu.
- Add STR_DICTIONARY i18n key and regenerate I18nKeys.h/I18nStrings.h.

Made-with: Cursor
2026-03-07 21:12:09 -05:00

95 lines
3.0 KiB
C++

#include "DictionaryMenuActivity.h"
#include <GfxRenderer.h>
#include <I18n.h>
#include "activities/ActivityResult.h"
#include "MappedInputManager.h"
#include "components/UITheme.h"
#include "fontIds.h"
void DictionaryMenuActivity::buildMenuItems() {
menuItems.clear();
menuItems.reserve(3);
menuItems.push_back({Action::LOOKUP_WORD, StrId::STR_LOOKUP_WORD});
menuItems.push_back({Action::LOOKUP_HISTORY, StrId::STR_LOOKUP_HISTORY});
menuItems.push_back({Action::DELETE_DICT_CACHE, StrId::STR_DELETE_DICT_CACHE});
}
void DictionaryMenuActivity::onEnter() {
Activity::onEnter();
selectedIndex = 0;
requestUpdate();
}
void DictionaryMenuActivity::onExit() { Activity::onExit(); }
void DictionaryMenuActivity::loop() {
buttonNavigator.onNext([this] {
selectedIndex = ButtonNavigator::nextIndex(selectedIndex, static_cast<int>(menuItems.size()));
requestUpdate();
});
buttonNavigator.onPrevious([this] {
selectedIndex = ButtonNavigator::previousIndex(selectedIndex, static_cast<int>(menuItems.size()));
requestUpdate();
});
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
if (selectedIndex < static_cast<int>(menuItems.size())) {
setResult(MenuResult{.action = static_cast<int>(menuItems[selectedIndex].action)});
finish();
return;
}
}
if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
ActivityResult r;
r.isCancelled = true;
setResult(std::move(r));
finish();
return;
}
}
void DictionaryMenuActivity::render(RenderLock&&) {
renderer.clearScreen();
const auto pageWidth = renderer.getScreenWidth();
const auto pageHeight = renderer.getScreenHeight();
constexpr int popupMargin = 20;
constexpr int lineHeight = 30;
constexpr int titleHeight = 40;
const int optionCount = static_cast<int>(menuItems.size());
const int popupH = titleHeight + popupMargin + lineHeight * optionCount + popupMargin;
const int popupW = pageWidth - 60;
const int popupX = (pageWidth - popupW) / 2;
const int popupY = (pageHeight - popupH) / 2;
renderer.fillRect(popupX - 2, popupY - 2, popupW + 4, popupH + 4, true);
renderer.fillRect(popupX, popupY, popupW, popupH, false);
renderer.drawText(UI_12_FONT_ID, popupX + popupMargin, popupY + 8, tr(STR_DICTIONARY), true, EpdFontFamily::BOLD);
const int dividerY = popupY + titleHeight;
renderer.fillRect(popupX + 4, dividerY, popupW - 8, 1, true);
const int startY = dividerY + popupMargin / 2;
for (int i = 0; i < optionCount; ++i) {
const int itemY = startY + i * lineHeight;
const bool isSelected = (i == selectedIndex);
if (isSelected) {
renderer.fillRect(popupX + 2, itemY, popupW - 4, lineHeight, true);
}
renderer.drawText(UI_10_FONT_ID, popupX + popupMargin, itemY, I18N.get(menuItems[i].labelId), !isSelected);
}
const auto labels = mappedInput.mapLabels(tr(STR_CANCEL), tr(STR_SELECT), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
}