Make Reader menu theme aware

This commit is contained in:
jpirnay
2026-04-09 14:51:39 +02:00
parent 8bb32d464d
commit 64b6818eeb
2 changed files with 33 additions and 54 deletions
@@ -158,60 +158,39 @@ void EpubReaderMenuActivity::render(RenderLock&&) {
// Menu Items
const int startY = 75 + contentRect.y;
constexpr int lineHeight = 30;
const int listHeight = contentRect.height - (startY - contentRect.y);
for (size_t i = 0; i < menuItems.size(); ++i) {
const int displayY = startY + (i * lineHeight);
const bool isSelected = (static_cast<int>(i) == selectedIndex);
if (isSelected) {
// Highlight only the content area so we don't paint over hint gutters.
renderer.fillRect(contentRect.x, displayY, contentRect.width - 1, lineHeight, true);
}
renderer.drawText(UI_10_FONT_ID, contentRect.x + 20, displayY, I18N.get(menuItems[i].labelId), !isSelected);
if (menuItems[i].action == MenuAction::ROTATE_SCREEN) {
// Render current orientation value on the right edge of the content area.
const char* value = I18N.get(orientationLabels[pendingOrientation]);
const auto width = renderer.getTextWidth(UI_10_FONT_ID, value);
renderer.drawText(UI_10_FONT_ID, contentRect.x + contentRect.width - 20 - width, displayY, value, !isSelected);
}
if (menuItems[i].action == MenuAction::AUTO_PAGE_TURN) {
// Render current page turn value on the right edge of the content area.
const auto value = pageTurnLabels[selectedPageTurnOption];
const auto width = renderer.getTextWidth(UI_10_FONT_ID, value);
renderer.drawText(UI_10_FONT_ID, contentRect.x + contentRect.width - 20 - width, displayY, value, !isSelected);
}
if (menuItems[i].action == MenuAction::EMBEDDED_STYLE) {
const char* value = tr(STR_DEFAULT_VALUE);
if (pendingEmbeddedStyleOverride == 1) {
value = tr(STR_STATE_ON);
} else if (pendingEmbeddedStyleOverride == 0) {
value = tr(STR_STATE_OFF);
}
const auto width = renderer.getTextWidth(UI_10_FONT_ID, value);
renderer.drawText(UI_10_FONT_ID, contentRect.x + contentRect.width - 20 - width, displayY, value, !isSelected);
}
if (menuItems[i].action == MenuAction::IMAGE_RENDERING) {
const char* value = tr(STR_DEFAULT_VALUE);
if (pendingImageRenderingOverride >= 0 && pendingImageRenderingOverride < imageRenderingLabels.size()) {
value = I18N.get(imageRenderingLabels[pendingImageRenderingOverride]);
}
const auto width = renderer.getTextWidth(UI_10_FONT_ID, value);
renderer.drawText(UI_10_FONT_ID, contentRect.x + contentRect.width - 20 - width, displayY, value, !isSelected);
}
if (menuItems[i].action == MenuAction::TEXT_DARKNESS) {
const uint8_t idx = (pendingTextDarkness < textDarknessLabels.size()) ? pendingTextDarkness : 0;
const char* value = I18N.get(textDarknessLabels[idx]);
const auto width = renderer.getTextWidth(UI_10_FONT_ID, value);
renderer.drawText(UI_10_FONT_ID, contentRect.x + contentRect.width - 20 - width, displayY, value, !isSelected);
}
}
GUI.drawList(
renderer, Rect{contentRect.x, startY, contentRect.width, listHeight}, static_cast<int>(menuItems.size()),
selectedIndex, [this](int index) { return I18N.get(menuItems[index].labelId); }, nullptr, nullptr,
[this](int index) {
const auto& item = menuItems[index];
switch (item.action) {
case MenuAction::ROTATE_SCREEN:
return std::string(I18N.get(orientationLabels[pendingOrientation]));
case MenuAction::AUTO_PAGE_TURN:
return std::string(pageTurnLabels[selectedPageTurnOption]);
case MenuAction::EMBEDDED_STYLE:
if (pendingEmbeddedStyleOverride == 1) {
return std::string(tr(STR_STATE_ON));
} else if (pendingEmbeddedStyleOverride == 0) {
return std::string(tr(STR_STATE_OFF));
}
return std::string(tr(STR_DEFAULT_VALUE));
case MenuAction::IMAGE_RENDERING:
if (pendingImageRenderingOverride >= 0 && pendingImageRenderingOverride < imageRenderingLabels.size()) {
return std::string(I18N.get(imageRenderingLabels[pendingImageRenderingOverride]));
}
return std::string(tr(STR_DEFAULT_VALUE));
case MenuAction::TEXT_DARKNESS: {
const uint8_t idx = (pendingTextDarkness < textDarknessLabels.size()) ? pendingTextDarkness : 0;
return std::string(I18N.get(textDarknessLabels[idx]));
}
default:
return std::string();
}
},
true);
// Footer / Hints
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_DIR_UP), tr(STR_DIR_DOWN));