From aea002f290e5eddde98eb394fa7a9145c325fffe Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Wed, 27 Jan 2021 19:47:31 -0500 Subject: buttons (for warn overwrite popup) --- ui.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'ui.c') diff --git a/ui.c b/ui.c index 05e4110..827f73c 100644 --- a/ui.c +++ b/ui.c @@ -461,6 +461,24 @@ static void file_selector_render(Ted *ted, FileSelector *fs) { } } +static void button_render(Ted *ted, Rect button, char const *text, u32 color) { + u32 const *colors = ted->settings.colors; + + glBegin(GL_QUADS); + if (rect_contains_point(button, ted->mouse_pos)) { + // highlight button when hovering over it + gl_color_rgba((color & 0xffffff00) | ((color & 0xff) / 3)); + rect_render(button); + } + gl_color_rgba(colors[COLOR_BORDER]); + rect_render_border(button, 1); + glEnd(); + + gl_color_rgba(color); + v2 pos = rect_center(button); + text_render_anchored(ted->font, text, pos.x, pos.y, ANCHOR_MIDDLE); +} + typedef enum { POPUP_NONE, POPUP_YES, @@ -519,4 +537,15 @@ static void popup_render(Ted *ted, char const *title, char const *body) { .min_y = -FLT_MAX, .max_y = +FLT_MAX }; text_render_with_state(font, &state, body, text_x1, y); + + float button_height = 30; + u16 nbuttons = 3; + float button_width = r.size.x / nbuttons; + Rect button_yes = rect(V2(r.pos.x, rect_y2(r) - button_height), V2(button_width, button_height)); + Rect button_no = rect_translate(button_yes, V2(button_width, 0)); + Rect button_cancel = rect_translate(button_no, V2(button_width, 0)); + + button_render(ted, button_yes, "Yes", colors[COLOR_YES]); + button_render(ted, button_no, "No", colors[COLOR_NO]); + button_render(ted, button_cancel, "Cancel", colors[COLOR_CANCEL]); } -- cgit v1.2.3