WIP sliders and incrimenting
This commit is contained in:
@@ -25,4 +25,30 @@ void DrawBox(uint32_t topleft_x_loc, uint32_t topleft_y_loc, uint32_t width, uin
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_toggle_switch(volatile pixel_t *const framebuffer, const toggle_switch_t *const toggle_switch)
|
||||
{
|
||||
const uint16_t x_loc = toggle_switch->x;
|
||||
const uint16_t y_loc = toggle_switch->y;
|
||||
const uint16_t width = toggle_switch->width ? toggle_switch->width : 50;
|
||||
const uint16_t height = toggle_switch->height ? toggle_switch->height : 20;
|
||||
const pixel_t on_color = toggle_switch->on_color ? toggle_switch->on_color : MAKE_PIXEL(0, 255, 0);
|
||||
const pixel_t off_color = toggle_switch->off_color ? toggle_switch->off_color : MAKE_PIXEL(160, 20, 20);
|
||||
const bool value = toggle_switch->value;
|
||||
|
||||
DrawBox(x_loc, y_loc, width, height, value ? on_color : off_color);
|
||||
if (value)
|
||||
{
|
||||
const uint16_t inner_switchbox_width = height - (toggle_switch->inner_padding_pixels * 2);
|
||||
const uint16_t inner_switchbox_x_loc = x_loc + width - toggle_switch->inner_padding_pixels - inner_switchbox_width;
|
||||
const uint16_t inner_switchbox_y_loc = y_loc + toggle_switch->inner_padding_pixels;
|
||||
DrawBox(inner_switchbox_x_loc, inner_switchbox_y_loc, inner_switchbox_width, inner_switchbox_width, MAKE_PIXEL(255, 255, 255));
|
||||
|
||||
} else {
|
||||
const uint16_t inner_switchbox_width = height - (toggle_switch->inner_padding_pixels * 2);
|
||||
const uint16_t inner_switchbox_x_loc = x_loc + toggle_switch->inner_padding_pixels;
|
||||
const uint16_t inner_switchbox_y_loc = y_loc + toggle_switch->inner_padding_pixels;
|
||||
DrawBox(inner_switchbox_x_loc, inner_switchbox_y_loc, inner_switchbox_width, inner_switchbox_width, MAKE_PIXEL(255, 255, 255));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user