From 7643a044f42de69486e63d8ffdd401ca621f0fc9 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 9 Jan 2025 00:37:54 -0800 Subject: [PATCH] mGUI: Wrap around menu cursor when navigating past end (closes #3356) --- CHANGES | 1 + src/util/gui/menu.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index b87501580..84f785795 100644 --- a/CHANGES +++ b/CHANGES @@ -41,6 +41,7 @@ Misc: - Libretro: Add Super Game Boy Color support (closes mgba.io/i/3188) - mGUI: Enable auto-softpatching (closes mgba.io/i/2899) - mGUI: Persist fast forwarding after closing menu (fixes mgba.io/i/2414) + - mGUI: Wrap around menu cursor when navigating past end (closes mgba.io/i/3356) - Qt: Handle multiple save game files for disparate games separately (fixes mgba.io/i/2887) - Qt: Remove maligned double-click-to-fullscreen shortcut (closes mgba.io/i/2632) - Qt: Pass logging context through to video proxy thread (fixes mgba.io/i/3095) diff --git a/src/util/gui/menu.c b/src/util/gui/menu.c index 2109bf8e1..3aeff4533 100644 --- a/src/util/gui/menu.c +++ b/src/util/gui/menu.c @@ -119,12 +119,6 @@ static enum GUIMenuExitReason GUIMenuPollInput(struct GUIParams* params, struct state->cursor = GUIPollCursor(params, &state->cx, &state->cy); // Check for new direction presses - if (newInput & (1 << GUI_INPUT_UP) && menu->index > 0) { - --menu->index; - } - if (newInput & (1 << GUI_INPUT_DOWN) && menu->index < GUIMenuItemListSize(&menu->items) - 1) { - ++menu->index; - } if (newInput & (1 << GUI_INPUT_LEFT)) { struct GUIMenuItem* item = GUIMenuItemListGetPointer(&menu->items, menu->index); if (item->validStates && !item->readonly) { @@ -145,6 +139,20 @@ static enum GUIMenuExitReason GUIMenuPollInput(struct GUIParams* params, struct menu->index = GUIMenuItemListSize(&menu->items) - 1; } } + if (newInput & (1 << GUI_INPUT_UP)) { + if (menu->index > 0) { + --menu->index; + } else { + menu->index = GUIMenuItemListSize(&menu->items) - 1; + } + } + if (newInput & (1 << GUI_INPUT_DOWN)) { + if (menu->index < GUIMenuItemListSize(&menu->items) - 1) { + ++menu->index; + } else { + menu->index = 0; + } + } // Handle cursor movement if (state->cursor != GUI_CURSOR_NOT_PRESENT) {