Incrimenting and decrementing works with disabled values
This commit is contained in:
@@ -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;
|
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
|
// Clamp the index to valid range
|
||||||
if (idx >= menu->num_children)
|
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)
|
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);
|
if (idx == 0)
|
||||||
return;
|
{
|
||||||
|
idx = menu->num_children - 1;
|
||||||
}
|
}
|
||||||
set_selected_menu_entry_idx(framebuffer, menu, menu->highlighted_child_idx - 1);
|
else
|
||||||
|
{
|
||||||
|
idx--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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)
|
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);
|
idx = (idx + 1) % menu->num_children;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
set_selected_menu_entry_idx(framebuffer, menu, menu->highlighted_child_idx + 1);
|
|
||||||
|
set_selected_menu_entry_idx(framebuffer, menu, idx);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user