Wrap-around navigation in Settings. (#31)

This commit is contained in:
Jonas Diemer 2025-12-16 12:54:16 +01:00 committed by GitHub
parent 57d1939be7
commit 9ad8111ce7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,37 +45,28 @@ void SettingsScreen::onExit() {
} }
void SettingsScreen::handleInput() { void SettingsScreen::handleInput() {
// Check for Confirm button to toggle setting // Handle actions with early return
if (inputManager.wasPressed(InputManager::BTN_CONFIRM)) { if (inputManager.wasPressed(InputManager::BTN_CONFIRM)) {
// Toggle the current setting
toggleCurrentSetting(); toggleCurrentSetting();
// Trigger a redraw of the entire screen
updateRequired = true; updateRequired = true;
return; // Return early to prevent further processing return;
} }
// Check for Back button to exit settings
if (inputManager.wasPressed(InputManager::BTN_BACK)) { if (inputManager.wasPressed(InputManager::BTN_BACK)) {
// Save settings and exit
SETTINGS.saveToFile(); SETTINGS.saveToFile();
onGoHome(); onGoHome();
return; return;
} }
// Handle UP/DOWN navigation for multiple settings // Handle navigation
if (inputManager.wasPressed(InputManager::BTN_UP) || inputManager.wasPressed(InputManager::BTN_LEFT)) { if (inputManager.wasPressed(InputManager::BTN_UP) || inputManager.wasPressed(InputManager::BTN_LEFT)) {
// Move selection up // Move selection up (with wrap-around)
if (selectedSettingIndex > 0) { selectedSettingIndex = (selectedSettingIndex > 0) ? (selectedSettingIndex - 1) : (settingsCount - 1);
selectedSettingIndex--; updateRequired = true;
updateRequired = true;
}
} else if (inputManager.wasPressed(InputManager::BTN_DOWN) || inputManager.wasPressed(InputManager::BTN_RIGHT)) { } else if (inputManager.wasPressed(InputManager::BTN_DOWN) || inputManager.wasPressed(InputManager::BTN_RIGHT)) {
// Move selection down // Move selection down (with wrap-around)
if (selectedSettingIndex < settingsCount - 1) { selectedSettingIndex = (selectedSettingIndex < settingsCount - 1) ? (selectedSettingIndex + 1) : 0;
selectedSettingIndex++; updateRequired = true;
updateRequired = true;
}
} }
} }