CustomButtonMapping: Keep unsaved button choices when the views are recreated

The checkbox array was reloaded from the config on every view creation,
but only saved when a popup closed or the screen finished. Rotating the
device reverted the choices. Also stop leaking a handler per button on
each rebuild.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-10-22 10:55:31 +02:00
1 parent 75ac7b6de8
commit 75b0fbe30c
2 files changed
+11 -17

No files matched your search

+10 -9
View File
@@ -136,14 +136,18 @@ void CustomButtonMappingScreen::CreateDialogViews(UI::ViewGroup *parent) {
ConfigCustomButton *cfg = nullptr;
bool *show = nullptr;
memset(array, 0, sizeof(array));
cfg = &g_Config.CustomButton[id_];
// This screen is reachable from the main menu, so neither GamepadEmu nor the layout screen
// need have sanitized these yet - and everything below indexes the tables with them.
CustomKeyData::Sanitize(*cfg);
show = &touch.touchCustom[id_].show;
for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++)
array[i] = (0x01 == ((g_Config.CustomButton[id_].key >> i) & 0x01));
// Only load once, since the views can be recreated (on rotation, for example) before the array is saved.
if (!arrayLoaded_) {
for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++) {
array[i] = (0x01 == ((g_Config.CustomButton[id_].key >> i) & 0x01));
}
arrayLoaded_ = true;
}
// TODO: Less hacky layout work
const Bounds layoutBounds = GetLayoutBounds(*screenManager()->getUIContext());
@@ -205,8 +209,9 @@ void CustomButtonMappingScreen::CreateDialogViews(UI::ViewGroup *parent) {
choice = new Choice(mc->T(KeyMap::GetPspButtonNameCharPointer(g_customKeyList[i].c)), new LinearLayoutParams(1.0f));
}
ChoiceEventHandler *choiceEventHandler = new ChoiceEventHandler(checkbox);
choice->OnClick.Handle(choiceEventHandler, &ChoiceEventHandler::onChoiceClick);
choice->OnClick.Add([checkbox](UI::EventParams &) {
checkbox->Toggle();
});
choice->SetCentered(true);
@@ -241,7 +246,3 @@ void CustomButtonMappingScreen::onFinish(DialogResult result) {
saveArray();
g_Config.Save("CustomButtonMappingScreen::onFinish");
}
void CustomButtonMappingScreen::ChoiceEventHandler::onChoiceClick(UI::EventParams &e){
checkbox_->Toggle();
};