WIP sliders and incrimenting

This commit is contained in:
Dylan Smith
2026-01-16 14:45:38 -05:00
parent 6711b5dcc1
commit 7dc4bf493d
6 changed files with 178 additions and 73 deletions

View File

@@ -15,8 +15,8 @@ static const pixel_t highlighted_text_color = MAKE_PIXEL(255, 255, 0);
void draw_menu_entry(volatile pixel_t *const framebuffer, const graphical_menu_t *const menu, uint8_t entry_idx)
{
const uint16_t y_pos = entry_idx * entry_height;
const graphical_menu_entry_t *entry = &menu->layout->entries[entry_idx];
const bool is_highlighted = (entry_idx == menu->selected_entry_idx) && entry->enabled;
const graphical_menu_entry_t *entry = &menu->children[entry_idx];
const bool is_highlighted = (entry_idx == menu->highlighted_child_idx) && !entry->disabled;
// Draw entry background - use highlighted color if this is the selected entry
pixel_t bg_color = is_highlighted ? highlighted_bg_color : entry_bg_color;
@@ -30,7 +30,7 @@ void draw_menu_entry(volatile pixel_t *const framebuffer, const graphical_menu_t
}
else
{
text_color = entry->enabled ? enabled_text_color : disabled_text_color;
text_color = !entry->disabled ? enabled_text_color : disabled_text_color;
}
// Calculate baseline from top position: baseline = top + (line_height - base_line)
@@ -44,7 +44,7 @@ void draw_menu(volatile pixel_t *const framebuffer, const graphical_menu_t *cons
{
DrawBox(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, entry_bg_color);
for (uint8_t i = 0; i < menu->layout->num_entries; i++)
for (uint8_t i = 0; i < menu->num_children; i++)
{
draw_menu_entry(framebuffer, menu, i);
}
@@ -60,15 +60,15 @@ void partial_redraw_menu(volatile pixel_t *const framebuffer, graphical_menu_t *
void select_menu_entry(graphical_menu_t *const menu)
{
// Ensure selected_entry_idx is within bounds
if (menu->selected_entry_idx >= menu->layout->num_entries)
if (menu->highlighted_child_idx >= menu->num_children)
{
return;
}
const graphical_menu_entry_t *entry = &menu->layout->entries[menu->selected_entry_idx];
const graphical_menu_entry_t *entry = &menu->children[menu->highlighted_child_idx];
// Only select if the entry is enabled
if (entry->enabled && entry->selected_callback_function != NULL)
if (!entry->disabled && entry->selected_callback_function != NULL)
{
entry->selected_callback_function(entry->selected_callback_function_args);
}
@@ -76,22 +76,22 @@ void select_menu_entry(graphical_menu_t *const menu)
void set_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_menu_t *const menu, uint8_t idx)
{
const uint16_t old_highlighted_entry_idx = menu->selected_entry_idx;
const uint16_t old_highlighted_entry_idx = menu->highlighted_child_idx;
// Handle case where the last entry is disabled
if (idx == menu->layout->num_entries - 1)
if (idx == menu->num_children - 1)
{
while (!menu->layout->entries[idx].enabled)
while (!menu->children[idx].disabled)
{
idx--;
}
}
// Only allow selecting enabled entries
while (!menu->layout->entries[idx].enabled)
while (menu->children[idx].disabled)
{
if (idx > menu->selected_entry_idx)
if (idx > menu->highlighted_child_idx)
{
idx--;
}
@@ -102,32 +102,32 @@ void set_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_
}
// Clamp the index to valid range
if (idx >= menu->layout->num_entries)
if (idx >= menu->num_children)
{
if (menu->layout->num_entries == 0) return;
idx = menu->layout->num_entries - 1;
if (menu->num_children == 0) return;
idx = menu->num_children - 1;
}
menu->selected_entry_idx = idx;
menu->highlighted_child_idx = idx;
partial_redraw_menu(framebuffer, menu, old_highlighted_entry_idx, idx);
}
void decrement_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_menu_t *const menu)
{
if (menu->selected_entry_idx == 0)
if (menu->highlighted_child_idx == 0)
{
set_selected_menu_entry_idx(framebuffer, menu, menu->layout->num_entries - 1);
set_selected_menu_entry_idx(framebuffer, menu, menu->num_children - 1);
return;
}
set_selected_menu_entry_idx(framebuffer, menu, menu->selected_entry_idx - 1);
set_selected_menu_entry_idx(framebuffer, menu, menu->highlighted_child_idx - 1);
}
void increment_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_menu_t *const menu)
{
if (menu->selected_entry_idx == menu->layout->num_entries - 1)
if (menu->highlighted_child_idx == menu->num_children - 1)
{
set_selected_menu_entry_idx(framebuffer, menu, 0);
return;
}
set_selected_menu_entry_idx(framebuffer, menu, menu->selected_entry_idx + 1);
set_selected_menu_entry_idx(framebuffer, menu, menu->highlighted_child_idx + 1);
}