feat: Themed language screen (#1020)
## Summary Added theme support to the language screen  ## Additional Context --- ### AI Usage Did you use AI tools to help write this code? _**NO**_
This commit is contained in:
@@ -30,15 +30,16 @@ void LanguageSelectActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mappedInput.wasPressed(MappedInputManager::Button::Up) ||
|
// Handle navigation
|
||||||
mappedInput.wasPressed(MappedInputManager::Button::Left)) {
|
buttonNavigator.onNextRelease([this] {
|
||||||
selectedIndex = (selectedIndex + totalItems - 1) % totalItems;
|
selectedIndex = ButtonNavigator::nextIndex(static_cast<int>(selectedIndex), totalItems);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
} else if (mappedInput.wasPressed(MappedInputManager::Button::Down) ||
|
});
|
||||||
mappedInput.wasPressed(MappedInputManager::Button::Right)) {
|
|
||||||
selectedIndex = (selectedIndex + 1) % totalItems;
|
buttonNavigator.onPreviousRelease([this] {
|
||||||
|
selectedIndex = ButtonNavigator::previousIndex(static_cast<int>(selectedIndex), totalItems);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanguageSelectActivity::handleSelection() {
|
void LanguageSelectActivity::handleSelection() {
|
||||||
@@ -55,36 +56,18 @@ void LanguageSelectActivity::render(Activity::RenderLock&&) {
|
|||||||
renderer.clearScreen();
|
renderer.clearScreen();
|
||||||
|
|
||||||
const auto pageWidth = renderer.getScreenWidth();
|
const auto pageWidth = renderer.getScreenWidth();
|
||||||
constexpr int rowHeight = 30;
|
const auto pageHeight = renderer.getScreenHeight();
|
||||||
|
auto metrics = UITheme::getInstance().getMetrics();
|
||||||
|
|
||||||
// Title
|
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_LANGUAGE));
|
||||||
renderer.drawCenteredText(UI_12_FONT_ID, 15, tr(STR_LANGUAGE), true, EpdFontFamily::BOLD);
|
|
||||||
|
|
||||||
// Current language marker
|
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
|
||||||
|
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing;
|
||||||
const int currentLang = static_cast<int>(I18N.getLanguage());
|
const int currentLang = static_cast<int>(I18N.getLanguage());
|
||||||
|
GUI.drawList(
|
||||||
// Draw options
|
renderer, Rect{0, contentTop, pageWidth, contentHeight}, totalItems, selectedIndex,
|
||||||
for (int i = 0; i < totalItems; i++) {
|
[this](int index) { return I18N.getLanguageName(static_cast<Language>(index)); }, nullptr, nullptr,
|
||||||
const int itemY = 60 + i * rowHeight;
|
[this, currentLang](int index) { return index == currentLang ? tr(STR_SET) : ""; }, true);
|
||||||
const bool isSelected = (i == selectedIndex);
|
|
||||||
const bool isCurrent = (i == currentLang);
|
|
||||||
|
|
||||||
// Draw selection highlight
|
|
||||||
if (isSelected) {
|
|
||||||
renderer.fillRect(0, itemY - 2, pageWidth - 1, rowHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw language name - get it from i18n system
|
|
||||||
const char* langName = I18N.getLanguageName(static_cast<Language>(i));
|
|
||||||
renderer.drawText(UI_10_FONT_ID, 20, itemY, langName, !isSelected);
|
|
||||||
|
|
||||||
// Draw current selection marker
|
|
||||||
if (isCurrent) {
|
|
||||||
const char* marker = tr(STR_ON_MARKER);
|
|
||||||
const auto width = renderer.getTextWidth(UI_10_FONT_ID, marker);
|
|
||||||
renderer.drawText(UI_10_FONT_ID, pageWidth - 20 - width, itemY, marker, !isSelected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Button hints
|
// Button hints
|
||||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "../ActivityWithSubactivity.h"
|
#include "../ActivityWithSubactivity.h"
|
||||||
#include "components/UITheme.h"
|
#include "components/UITheme.h"
|
||||||
|
#include "util/ButtonNavigator.h"
|
||||||
|
|
||||||
class MappedInputManager;
|
class MappedInputManager;
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ class LanguageSelectActivity final : public Activity {
|
|||||||
void handleSelection();
|
void handleSelection();
|
||||||
|
|
||||||
std::function<void()> onBack;
|
std::function<void()> onBack;
|
||||||
|
ButtonNavigator buttonNavigator;
|
||||||
int selectedIndex = 0;
|
int selectedIndex = 0;
|
||||||
int totalItems = 0;
|
int totalItems = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user