Toggle switches work

This commit is contained in:
Dylan Smith
2026-01-16 15:45:32 -05:00
parent ed31755a3a
commit fd46ea65ca
3 changed files with 38 additions and 14 deletions

View File

@@ -29,26 +29,33 @@ 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 default_width = 50;
const uint16_t default_height = 20;
const pixel_t default_on_color = MAKE_PIXEL(0, 255, 0);
const pixel_t default_off_color = MAKE_PIXEL(160, 20, 20);
const uint16_t default_inner_padding_pixels = 0;
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 uint16_t width = toggle_switch->width ? toggle_switch->width : default_width;
const uint16_t height = toggle_switch->height ? toggle_switch->height : default_height;
const pixel_t on_color = toggle_switch->on_color ? toggle_switch->on_color : default_on_color;
const pixel_t off_color = toggle_switch->off_color ? toggle_switch->off_color : default_off_color;
const uint16_t inner_padding_pixels = toggle_switch->inner_padding_pixels ? toggle_switch->inner_padding_pixels : default_inner_padding_pixels;
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;
const uint16_t inner_switchbox_width = height - (inner_padding_pixels * 2);
const uint16_t inner_switchbox_x_loc = x_loc + width - inner_padding_pixels - inner_switchbox_width;
const uint16_t inner_switchbox_y_loc = y_loc + 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;
const uint16_t inner_switchbox_width = height - (inner_padding_pixels * 2);
const uint16_t inner_switchbox_x_loc = x_loc + inner_padding_pixels;
const uint16_t inner_switchbox_y_loc = y_loc + inner_padding_pixels;
DrawBox(inner_switchbox_x_loc, inner_switchbox_y_loc, inner_switchbox_width, inner_switchbox_width, MAKE_PIXEL(255, 255, 255));
}
}

View File

@@ -7,7 +7,7 @@ static const uint16_t entry_height = 40;
static const uint16_t padding_x = 10;
static const uint16_t padding_y = 0;
static const pixel_t enabled_text_color = MAKE_PIXEL(255, 255, 255);
static const pixel_t disabled_text_color = MAKE_PIXEL(128, 128, 128);
static const pixel_t disabled_text_color = MAKE_PIXEL(80, 80, 80);
static const pixel_t entry_bg_color = MAKE_PIXEL(0, 0, 0);
static const pixel_t highlighted_bg_color = MAKE_PIXEL(50, 50, 50);
static const pixel_t highlighted_text_color = MAKE_PIXEL(255, 255, 0);
@@ -38,6 +38,18 @@ void draw_menu_entry(volatile pixel_t *const framebuffer, const graphical_menu_t
draw_string(framebuffer, &runescape_font,
padding_x, text_baseline_y,
entry->title, text_color);
if (entry->extra_draw_function != NULL)
{
const menu_entry_size_t menu_entry_size = {
.x = 0,
.y = y_pos,
.width = DISPLAY_WIDTH,
.height = entry_height,
};
entry->extra_draw_function(&menu_entry_size, entry->extra_draw_function_args);
}
}
void draw_menu(volatile pixel_t *const framebuffer, const graphical_menu_t *const menu)
@@ -54,7 +66,6 @@ void partial_redraw_menu(volatile pixel_t *const framebuffer, graphical_menu_t *
{
draw_menu_entry(framebuffer, menu, old_highlighted_entry_idx);
draw_menu_entry(framebuffer, menu, new_highlighted_entry_idx);
}
void select_menu_entry(graphical_menu_t *const menu)