Toggle switches work
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user