More reshaping

This commit is contained in:
jpirnay
2026-04-09 21:50:32 +02:00
parent 68f175eced
commit 14dcd8be0f
11 changed files with 144 additions and 59 deletions
@@ -10,6 +10,7 @@
#include "SyncTimeActivity.h"
#include "components/UITheme.h"
#include "fontIds.h"
#include "util/MenuItemHelpers.h"
namespace {
const StrId timeZoneNames[CrossPointSettings::TIMEZONE_COUNT] = {
@@ -23,22 +24,20 @@ std::vector<ClockSettingsActivity::MenuItem> ClockSettingsActivity::buildMenuIte
std::vector<MenuItem> items;
items.reserve(7);
// Settings
items.push_back({Action::NONE, StrId::STR_SETTINGS_TITLE, true});
items.push_back(makeSeparatorMenuItem<MenuItem>(StrId::STR_SETTINGS_TITLE));
items.push_back({Action::USE_CLOCK, StrId::STR_USE_CLOCK});
items.push_back({Action::CLOCK_FORMAT, StrId::STR_CLOCK_FORMAT});
items.push_back({Action::CLOCK_FORMAT, StrId::STR_CLOCK_FORMAT});
items.push_back({Action::TIMEZONE, StrId::STR_TIMEZONE});
// Tools
items.push_back({Action::NONE, StrId::STR_READER_TOOLS, true});
items.push_back(makeSeparatorMenuItem<MenuItem>(StrId::STR_READER_TOOLS));
items.push_back({Action::DETECT_TIMEZONE, StrId::STR_DETECT_TIMEZONE});
items.push_back({Action::SYNC_TIME, StrId::STR_SYNC_TIME});
items.push_back({Action::SYNC_TIME, StrId::STR_SYNC_TIME});
return items;
}
std::function<bool(int)> ClockSettingsActivity::buildSelectablePredicate() const {
return [this](int index) {
return index >= 0 && index < static_cast<int>(menuItems.size()) && !menuItems[index].isSeparator;
};
return makeSelectablePredicate(menuItems);
}
void ClockSettingsActivity::onEnter() {
@@ -124,8 +123,7 @@ void ClockSettingsActivity::render(RenderLock&&) {
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2;
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) {
const auto title = I18N.get(menuItems[index].labelId);
return menuItems[index].isSeparator ? UITheme::makeSeparatorTitle(title) : title;
@@ -1,21 +1,14 @@
#pragma once
#include <I18n.h>
#include <functional>
#include <vector>
#include <I18n.h>
#include "activities/Activity.h"
#include "util/ButtonNavigator.h"
class ClockSettingsActivity final : public Activity {
enum class Action {
USE_CLOCK,
CLOCK_FORMAT,
TIMEZONE,
SYNC_TIME,
DETECT_TIMEZONE,
NONE
};
enum class Action { USE_CLOCK, CLOCK_FORMAT, TIMEZONE, SYNC_TIME, DETECT_TIMEZONE, NONE };
struct MenuItem {
Action action;
+42 -9
View File
@@ -22,9 +22,11 @@
#include "activities/weather/WeatherSettingsActivity.h"
#include "components/UITheme.h"
#include "fontIds.h"
#include "util/MenuItemHelpers.h"
const StrId SettingsActivity::categoryNames[categoryCount] = {StrId::STR_CAT_DISPLAY, StrId::STR_CAT_READER,
StrId::STR_CAT_CONTROLS, StrId::STR_CAT_SYSTEM};
StrId::STR_CAT_CONTROLS, StrId::STR_CAT_NETWORK,
StrId::STR_CAT_SYSTEM};
void SettingsActivity::onEnter() {
Activity::onEnter();
@@ -33,7 +35,9 @@ void SettingsActivity::onEnter() {
displaySettings.clear();
readerSettings.clear();
controlsSettings.clear();
networkSettings.clear();
systemSettings.clear();
systemSettings.push_back(SettingInfo::Separator(StrId::STR_SETTINGS_MENU_SETTINGS));
for (const auto& setting : getSettingsList()) {
if (setting.category == StrId::STR_NONE_OPT) continue;
@@ -50,6 +54,8 @@ void SettingsActivity::onEnter() {
controlsSettings.push_back(setting);
} else if (setting.category == StrId::STR_CAT_SYSTEM) {
systemSettings.push_back(setting);
} else if (setting.category == StrId::STR_CAT_NETWORK) {
networkSettings.push_back(setting);
}
// Web-only categories (KOReader Sync, OPDS Browser) are skipped for device UI
}
@@ -57,15 +63,26 @@ void SettingsActivity::onEnter() {
// Append device-only ACTION items
controlsSettings.insert(controlsSettings.begin(),
SettingInfo::Action(StrId::STR_REMAP_FRONT_BUTTONS, SettingAction::RemapFrontButtons));
networkSettings.push_back(SettingInfo::Separator(StrId::STR_SETTINGS_MENU_NETWORK));
networkSettings.push_back(SettingInfo::Action(StrId::STR_WIFI_NETWORKS, SettingAction::Network));
networkSettings.push_back(SettingInfo::Separator(StrId::STR_SETTINGS_MENU_SOURCES));
networkSettings.push_back(SettingInfo::Action(StrId::STR_OPDS_BROWSER, SettingAction::OPDSBrowser));
networkSettings.push_back(SettingInfo::Separator(StrId::STR_SETTINGS_MENU_SYNC));
networkSettings.push_back(SettingInfo::Action(StrId::STR_KOREADER_SYNC, SettingAction::KOReaderSync));
// System settings with actions
systemSettings.push_back(SettingInfo::Action(StrId::STR_LANGUAGE, SettingAction::Language));
systemSettings.push_back(SettingInfo::Separator(StrId::STR_SETTINGS_MENU_TOOLS));
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLOCK_SETTINGS, SettingAction::ClockSettings));
systemSettings.push_back(SettingInfo::Action(StrId::STR_WIFI_NETWORKS, SettingAction::Network));
systemSettings.push_back(SettingInfo::Action(StrId::STR_KOREADER_SYNC, SettingAction::KOReaderSync));
systemSettings.push_back(SettingInfo::Action(StrId::STR_OPDS_BROWSER, SettingAction::OPDSBrowser));
systemSettings.push_back(SettingInfo::Action(StrId::STR_WEATHER_SETTINGS, SettingAction::Weather));
systemSettings.push_back(SettingInfo::Separator(StrId::STR_SETTINGS_MENU_SYSTEM));
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLEAR_READING_CACHE, SettingAction::ClearCache));
systemSettings.push_back(SettingInfo::Action(StrId::STR_CHECK_UPDATES, SettingAction::CheckForUpdates));
systemSettings.push_back(SettingInfo::Action(StrId::STR_LANGUAGE, SettingAction::Language));
systemSettings.push_back(SettingInfo::Action(StrId::STR_SYSTEM_INFO, SettingAction::SystemInfo));
systemSettings.push_back(SettingInfo::Action(StrId::STR_WEATHER_SETTINGS, SettingAction::Weather));
readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));
// Reset selection to first category
@@ -75,11 +92,16 @@ void SettingsActivity::onEnter() {
// Initialize with first category (Display)
currentSettings = &displaySettings;
settingsCount = static_cast<int>(displaySettings.size());
buttonNavigator.setSelectablePredicate(makeSelectablePredicate(*currentSettings, 1, true), settingsCount + 1);
// Trigger first update
requestUpdate();
}
std::function<bool(int)> SettingsActivity::buildSelectablePredicate() const {
return makeSelectablePredicate(*currentSettings, 1, true);
}
void SettingsActivity::onExit() {
Activity::onExit();
@@ -115,12 +137,12 @@ void SettingsActivity::loop() {
// Handle navigation
buttonNavigator.onNextRelease([this] {
selectedSettingIndex = ButtonNavigator::nextIndex(selectedSettingIndex, settingsCount + 1);
selectedSettingIndex = buttonNavigator.nextIndex(selectedSettingIndex);
requestUpdate();
});
buttonNavigator.onPreviousRelease([this] {
selectedSettingIndex = ButtonNavigator::previousIndex(selectedSettingIndex, settingsCount + 1);
selectedSettingIndex = buttonNavigator.previousIndex(selectedSettingIndex);
requestUpdate();
});
@@ -149,10 +171,14 @@ void SettingsActivity::loop() {
currentSettings = &controlsSettings;
break;
case 3:
currentSettings = &networkSettings;
break;
case 4:
currentSettings = &systemSettings;
break;
}
settingsCount = static_cast<int>(currentSettings->size());
buttonNavigator.setSelectablePredicate(makeSelectablePredicate(*currentSettings, 1, true), settingsCount + 1);
}
}
@@ -163,6 +189,9 @@ void SettingsActivity::toggleCurrentSetting() {
}
const auto& setting = (*currentSettings)[selectedSetting];
if (setting.isSeparator) {
return;
}
if (setting.type == SettingType::TOGGLE && setting.valuePtr != nullptr) {
// Toggle the boolean value using the member pointer
@@ -259,7 +288,11 @@ void SettingsActivity::render(RenderLock&&) {
contentRect.height -
(metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing * 2)},
settingsCount, selectedSettingIndex - 1,
[&settings](int index) { return std::string(I18N.get(settings[index].nameId)); }, nullptr, nullptr,
[&settings](int index) {
const auto title = I18N.get(settings[index].nameId);
return settings[index].isSeparator ? UITheme::makeSeparatorTitle(title) : title;
},
nullptr, nullptr,
[&settings](int i) {
const auto& setting = settings[i];
std::string valueText = "";
+15 -2
View File
@@ -30,6 +30,7 @@ enum class SettingAction {
struct SettingInfo {
StrId nameId;
bool isSeparator = false;
SettingType type;
uint8_t CrossPointSettings::* valuePtr = nullptr;
std::vector<StrId> enumValues;
@@ -84,11 +85,21 @@ struct SettingInfo {
return s;
}
static SettingInfo Action(StrId nameId, SettingAction action) {
static SettingInfo Action(StrId nameId, SettingAction action, bool isSeparator = false) {
SettingInfo s;
s.nameId = nameId;
s.type = SettingType::ACTION;
s.action = action;
s.isSeparator = isSeparator;
return s;
}
static SettingInfo Separator(StrId nameId) {
SettingInfo s;
s.nameId = nameId;
s.type = SettingType::ACTION;
s.action = SettingAction::None;
s.isSeparator = true;
return s;
}
@@ -155,14 +166,16 @@ class SettingsActivity final : public Activity {
std::vector<SettingInfo> displaySettings;
std::vector<SettingInfo> readerSettings;
std::vector<SettingInfo> controlsSettings;
std::vector<SettingInfo> networkSettings;
std::vector<SettingInfo> systemSettings;
const std::vector<SettingInfo>* currentSettings = nullptr;
static constexpr int categoryCount = 4;
static constexpr int categoryCount = 5;
static const StrId categoryNames[categoryCount];
void enterCategory(int categoryIndex);
void toggleCurrentSetting();
std::function<bool(int)> buildSelectablePredicate() const;
public:
explicit SettingsActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)