Rearrange menus + fixes

This commit is contained in:
jpirnay
2026-05-14 23:44:30 +02:00
parent fc02ec67d9
commit 3dfcdd002f
5 changed files with 58 additions and 50 deletions
@@ -6,28 +6,12 @@
#include "MappedInputManager.h"
#include "SdCardFontGlobals.h"
#include "components/UITheme.h"
#include "fontIds.h"
namespace {
uint8_t currentFontIndex() {
if (SETTINGS.sdFontFamilyName[0] != '\0') {
const auto& families = sdFontSystem.registry().getFamilies();
for (int i = 0; i < static_cast<int>(families.size()); i++) {
if (families[i].name == SETTINGS.sdFontFamilyName) {
return static_cast<uint8_t>(CrossPointSettings::BUILTIN_FONT_COUNT + i);
}
}
}
return SETTINGS.fontFamily < CrossPointSettings::BUILTIN_FONT_COUNT ? SETTINGS.fontFamily : 0;
}
} // namespace
void FontSelectionActivity::onEnter() {
Activity::onEnter();
fontCount = fontFamilyOptionCount();
selectedIndex = currentFontIndex();
selectedIndex =
static_cast<int>(target == Target::TXT ? txtFontFamilyDynamicGetter(nullptr) : fontFamilyDynamicGetter(nullptr));
if (selectedIndex >= fontCount) selectedIndex = 0;
requestUpdate();
}
@@ -50,7 +34,11 @@ void FontSelectionActivity::loop() {
}
void FontSelectionActivity::handleSelection() {
fontFamilyDynamicSetter(nullptr, static_cast<uint8_t>(selectedIndex));
if (target == Target::TXT) {
txtFontFamilyDynamicSetter(nullptr, static_cast<uint8_t>(selectedIndex));
} else {
fontFamilyDynamicSetter(nullptr, static_cast<uint8_t>(selectedIndex));
}
finish();
}
@@ -60,13 +48,15 @@ void FontSelectionActivity::render(RenderLock&&) {
const auto& metrics = UITheme::getInstance().getMetrics();
const Rect contentRect = UITheme::getContentRect(renderer, true, false);
const StrId headerStr = target == Target::TXT ? StrId::STR_TXT_FONT_FAMILY : StrId::STR_FONT_FAMILY;
GUI.drawHeader(renderer, Rect{contentRect.x, metrics.topPadding, contentRect.width, metrics.headerHeight},
tr(STR_FONT_FAMILY));
I18N.get(headerStr));
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
const int contentHeight = contentRect.height - contentTop - metrics.verticalSpacing;
const uint8_t activeIndex = currentFontIndex();
const uint8_t activeIndex = static_cast<uint8_t>(target == Target::TXT ? txtFontFamilyDynamicGetter(nullptr)
: fontFamilyDynamicGetter(nullptr));
GUI.drawList(
renderer, Rect{contentRect.x, contentTop, contentRect.width, contentHeight}, fontCount, selectedIndex,
[](int index) { return fontFamilyOptionLabel(static_cast<uint8_t>(index)); }, nullptr, nullptr,
@@ -11,8 +11,10 @@ class MappedInputManager;
/// Replaces in-place enum cycling for the Reader Font Family setting.
class FontSelectionActivity final : public Activity {
public:
explicit FontSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)
: Activity("FontSelect", renderer, mappedInput) {}
enum class Target { EPUB, TXT };
explicit FontSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, Target target = Target::EPUB)
: Activity("FontSelect", renderer, mappedInput), target(target) {}
void onEnter() override;
void onExit() override;
@@ -25,4 +27,5 @@ class FontSelectionActivity final : public Activity {
ButtonNavigator buttonNavigator;
int selectedIndex = 0;
uint8_t fontCount = 0;
Target target;
};
+20 -9
View File
@@ -81,10 +81,11 @@ void SettingsActivity::onEnter() {
setting.nameId == StrId::STR_TIMEZONE)) {
continue;
}
// Enrich the font-family entry with SD card families discovered at boot.
// Enrich font-family entries with SD card families discovered at boot.
// The list itself is a namespace-static; we only mutate our local copy here.
SettingInfo enriched = setting;
if (setting.key && std::strcmp(setting.key, "fontFamily") == 0) {
if (setting.key &&
(std::strcmp(setting.key, "fontFamily") == 0 || std::strcmp(setting.key, "txtFontFamily") == 0)) {
const uint8_t n = fontFamilyOptionCount();
enriched.enumLabels.clear();
enriched.enumLabels.reserve(n);
@@ -96,8 +97,7 @@ void SettingsActivity::onEnter() {
continue;
}
const bool isReaderFontEntry =
enriched.category == StrId::STR_CAT_READER && (enriched.subcategory == StrId::STR_MENU_READER_FONT ||
enriched.submenu == StrId::STR_MENU_READER_FONT_SETTINGS);
enriched.category == StrId::STR_CAT_READER && enriched.submenu == StrId::STR_MENU_READER_FONT;
if (!insertedFontDownload && sawReaderFontSection && !isReaderFontEntry) {
insertFontDownloadBelowFontSection();
@@ -278,11 +278,22 @@ void SettingsActivity::toggleCurrentSetting() {
if (setting.isSeparator) return;
if (setting.type == SettingType::ENUM && setting.nameId == StrId::STR_FONT_FAMILY) {
startActivityForResult(std::make_unique<FontSelectionActivity>(renderer, mappedInput),
[this](const ActivityResult&) {
SETTINGS.saveToFile();
needsHalfRefresh = true;
});
startActivityForResult(
std::make_unique<FontSelectionActivity>(renderer, mappedInput, FontSelectionActivity::Target::EPUB),
[this](const ActivityResult&) {
SETTINGS.saveToFile();
needsHalfRefresh = true;
});
return;
}
if (setting.type == SettingType::ENUM && setting.nameId == StrId::STR_TXT_FONT_FAMILY) {
startActivityForResult(
std::make_unique<FontSelectionActivity>(renderer, mappedInput, FontSelectionActivity::Target::TXT),
[this](const ActivityResult&) {
SETTINGS.saveToFile();
needsHalfRefresh = true;
});
return;
}