From 8a7f19fef38f4e5a96dcc47fbf8889f1d416c392 Mon Sep 17 00:00:00 2001 From: vurtun Date: Tue, 8 Sep 2015 10:57:27 +0200 Subject: [PATCH] added toggle button back in --- gui.c | 39 ++++++++++++++++++++++++++++++++++++++- gui.h | 15 ++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/gui.c b/gui.c index 5ade89d0..107eeeb0 100644 --- a/gui.c +++ b/gui.c @@ -2574,6 +2574,7 @@ gui_edit_buffer_at(gui_edit_buffer *buffer, gui_int pos, gui_long *unicode, *len = glyph_len; break; } + i++; src_len = src_len + glyph_len; glyph_len = gui_utf_decode(text + src_len, unicode, text_len - src_len); @@ -3303,7 +3304,7 @@ gui_widget_progress(struct gui_command_buffer *out, struct gui_rect r, prog_value = MIN(prog_value, max); prog_scale = (gui_float)prog_value / (gui_float)max; - /* draw progressbar width background and cursor */ + /* draw progressbar with background and cursor */ gui_command_buffer_push_rect(out, r, prog->rounding, prog->background); r.w = (r.w - 2) * prog_scale; gui_command_buffer_push_rect(out, r, prog->rounding, col); @@ -5785,6 +5786,42 @@ gui_button_fitting(struct gui_context *layout, const char *text, &button, i, &config->font); } +gui_bool +gui_button_toggle(struct gui_context *layout, const char *str, gui_bool value) +{ + struct gui_rect bounds; + struct gui_button_text button; + const struct gui_style *config; + + const struct gui_input *i; + enum gui_widget_state state; + state = gui_button(&button.base, &bounds, layout); + if (!state) return value; + i = (state == GUI_WIDGET_ROM || layout->flags & GUI_WINDOW_ROM) ? 0 : layout->input; + + config = layout->style; + button.base.border = config->colors[GUI_COLOR_BORDER]; + button.alignment = GUI_TEXT_CENTERED; + if (!value) { + button.base.normal = config->colors[GUI_COLOR_BUTTON]; + button.base.hover = config->colors[GUI_COLOR_BUTTON_HOVER]; + button.base.active = config->colors[GUI_COLOR_BUTTON_ACTIVE]; + button.normal = config->colors[GUI_COLOR_TEXT]; + button.hover = config->colors[GUI_COLOR_TEXT_HOVERING]; + button.active = config->colors[GUI_COLOR_TEXT_ACTIVE]; + } else { + button.base.normal = config->colors[GUI_COLOR_BUTTON_ACTIVE]; + button.base.hover = config->colors[GUI_COLOR_BUTTON_HOVER]; + button.base.active = config->colors[GUI_COLOR_BUTTON]; + button.normal = config->colors[GUI_COLOR_TEXT_ACTIVE]; + button.hover = config->colors[GUI_COLOR_TEXT_HOVERING]; + button.active = config->colors[GUI_COLOR_TEXT]; + } + if (gui_widget_button_text(layout->buffer, bounds, str, GUI_BUTTON_DEFAULT, + &button, i, &config->font)) value = !value; + return value; +} + static enum gui_widget_state gui_toggle_base(struct gui_toggle *toggle, struct gui_rect *bounds, struct gui_context *layout) diff --git a/gui.h b/gui.h index e537f5a6..1f3807ce 100644 --- a/gui.h +++ b/gui.h @@ -55,9 +55,9 @@ extern "C" { #define GUI_COMPILE_WITH_FONT 1 /* setting this define to 1 adds the `stb_truetype` and `stb_rect_pack` header to this library and provided a default font for font loading and rendering. - If you already have a font or do not want to use this font you can just set this - define to zero and the font module will not be compiled and the two header - will not be needed. */ + If you already have font handling or do not want to use this font handler + you can just set this define to zero and the font module will not be compiled + and the two header will not be needed. */ /* * ============================================================== * @@ -2830,6 +2830,7 @@ void gui_layout_pop(struct gui_context*); gui_label -- text widget for printing zero terminated strings gui_label_colored -- widget for printing colored zero terminiated strings gui_button_text -- button widget with text content + gui_button_toggle -- button toggle widget with text content gui_button_color -- colored button widget without content gui_button_symbol -- button with triangle either up-/down-/left- or right gui_button_image -- button widget width icon content @@ -3002,6 +3003,14 @@ gui_bool gui_button_fitting(struct gui_context *layout, const char *text, - gui_true if the button was transistioned from unpressed to pressed with default button behavior or pressed if repeater behavior. */ +gui_bool gui_button_toggle(struct gui_context*, const char*,gui_bool value); +/* this function creates a toggle button which is either active or inactive + Input: + - label describing the toggle button + - current state of the toggle + Output: + - from user input updated toggle state +*/ gui_float gui_slider(struct gui_context*, gui_float min, gui_float val, gui_float max, gui_float step); /* this function creates a slider for value manipulation