From ed31755a3a25532dfffa11b3892223e4b56c4ae6 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Fri, 16 Jan 2026 14:53:56 -0500 Subject: [PATCH] Incrimenting and decrementing works with disabled values --- Core/Src/graphics/menu.c | 53 +++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/Core/Src/graphics/menu.c b/Core/Src/graphics/menu.c index bc688a4..4759b22 100644 --- a/Core/Src/graphics/menu.c +++ b/Core/Src/graphics/menu.c @@ -78,29 +78,6 @@ void set_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_ { const uint16_t old_highlighted_entry_idx = menu->highlighted_child_idx; - - // Handle case where the last entry is disabled - if (idx == menu->num_children - 1) - { - while (!menu->children[idx].disabled) - { - idx--; - } - } - - // Only allow selecting enabled entries - while (menu->children[idx].disabled) - { - if (idx > menu->highlighted_child_idx) - { - idx--; - } - else - { - idx++; - } - } - // Clamp the index to valid range if (idx >= menu->num_children) { @@ -114,20 +91,34 @@ void set_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_ void decrement_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_menu_t *const menu) { - if (menu->highlighted_child_idx == 0) + uint8_t idx = menu->highlighted_child_idx; + + // Only allow selecting enabled entries + do { - set_selected_menu_entry_idx(framebuffer, menu, menu->num_children - 1); - return; + if (idx == 0) + { + idx = menu->num_children - 1; + } + else + { + idx--; + } } - set_selected_menu_entry_idx(framebuffer, menu, menu->highlighted_child_idx - 1); + while (menu->children[idx].disabled); + + set_selected_menu_entry_idx(framebuffer, menu, idx); } void increment_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_menu_t *const menu) { - if (menu->highlighted_child_idx == menu->num_children - 1) + uint8_t idx = (menu->highlighted_child_idx + 1) % menu->num_children; + + // Only allow selecting enabled entries + while (menu->children[idx].disabled) { - set_selected_menu_entry_idx(framebuffer, menu, 0); - return; + idx = (idx + 1) % menu->num_children; } - set_selected_menu_entry_idx(framebuffer, menu, menu->highlighted_child_idx + 1); + + set_selected_menu_entry_idx(framebuffer, menu, idx); } \ No newline at end of file