From f9afc00d15f934d8509f3eeb7c62b01ca84ca204 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Tue, 9 Feb 2021 09:37:41 -0500 Subject: improve buffer_unsaved_changes so that making an edit then undoing it doesn't count as making a change --- ui.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'ui.c') diff --git a/ui.c b/ui.c index 49c0dc8..b743d82 100644 --- a/ui.c +++ b/ui.c @@ -582,6 +582,7 @@ static void popup_render(Ted *ted, u32 options, char const *title, char const *b text_get_size(font_bold, title, &title_size.x, &title_size.y); v2 title_pos = v2_sub(V2(window_width * 0.5f, y), V2(title_size.x * 0.5f, 0)); text_utf8(font_bold, title, title_pos.x, title_pos.y, colors[COLOR_TEXT]); + text_render(font_bold); // body text float text_x1 = rect_x1(r) + padding; @@ -598,3 +599,29 @@ static void popup_render(Ted *ted, u32 options, char const *title, char const *b text_render(font); } + +static void checkbox_frame(Ted *ted, bool *value, char const *label, v2 pos) { + Font *font = ted->font; + float char_height = text_font_char_height(font); + float checkbox_size = char_height; + Settings const *settings = &ted->settings; + u32 const *colors = settings->colors; + + Rect checkbox_rect = rect(pos, V2(checkbox_size, checkbox_size)); + + for (u32 i = 0; i < ted->nmouse_clicks[SDL_BUTTON_LEFT]; ++i) { + if (rect_contains_point(checkbox_rect, ted->mouse_clicks[SDL_BUTTON_LEFT][i])) { + *value = !*value; + } + } + + if (*value) + gl_geometry_rect(checkbox_rect, colors[COLOR_TEXT]); + else + gl_geometry_rect_border(checkbox_rect, 1, colors[COLOR_TEXT]); + v2 text_pos = v2_add(pos, V2(checkbox_size, 0)); + text_utf8(font, label, text_pos.x, text_pos.y, colors[COLOR_TEXT]); + + gl_geometry_draw(); + text_render(font); +} -- cgit v1.2.3