From: hgn Date: Wed, 17 Apr 2024 17:29:19 +0000 (+0100) Subject: checkbox imgui api X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=fb7a6a573f4259045cdc08d556298b6c41bda5fb checkbox imgui api --- diff --git a/src/fonts/vg_font_thin_3.png b/src/fonts/vg_font_thin_3.png index ad1f1f4..18139a2 100644 Binary files a/src/fonts/vg_font_thin_3.png and b/src/fonts/vg_font_thin_3.png differ diff --git a/src/fonts/vg_font_thin_3.xcf b/src/fonts/vg_font_thin_3.xcf index 85ed689..1e40c46 100644 Binary files a/src/fonts/vg_font_thin_3.xcf and b/src/fonts/vg_font_thin_3.xcf differ diff --git a/vg_build_font.h b/vg_build_font.h index 5278ca1..5ee5e10 100644 --- a/vg_build_font.h +++ b/vg_build_font.h @@ -111,6 +111,7 @@ void vg_build_default_font(void) vg_build_font_face_run( &small, 'a', 'z', 0, 28 ); vg_build_font_face_run( &small, '0', '9', 208,14 ); vg_build_font_face_run( &small, 0x7f, 0xa4, 0,42 ); + vg_build_font_face_run( &small, 0xb0, 0xb2, 208,28 ); vg_build_write_font_face( fp, &small ); vg_font_face large = @@ -128,6 +129,7 @@ void vg_build_default_font(void) vg_build_font_face_run( &large, 'a', 'z', 0, 98 ); vg_build_font_face_run( &large, '0', '9', 312,77 ); vg_build_font_face_run( &large, 0x7f, 0xa4, 0,119 ); + vg_build_font_face_run( &large, 0xb0, 0xb2, 312,98 ); vg_build_write_font_face( fp, &large ); vg_font_face title = @@ -152,6 +154,7 @@ void vg_build_default_font(void) vg_build_font_face_run( &title, 0x7f, 0x88, 120,350 ); vg_build_font_face_run( &title, 0x93, 0x98, 360,350 ); vg_build_font_face_run( &title, 0x99, 0xa4, 0,392 ); + vg_build_font_face_run( &title, 0xb0, 0xb2, 288,392 ); vg_build_write_font_face( fp, &title ); fclose( fp ); diff --git a/vg_imgui.c b/vg_imgui.c index 60bb296..bb4f46f 100644 --- a/vg_imgui.c +++ b/vg_imgui.c @@ -839,7 +839,7 @@ u32 ui_ntext( ui_rect rect, const char *str, u32 len, ui_px scale, text_cursor[0] -= vg_ui.font->sx*scale; ui_rect glyph; - ui_text_glyph( vg_ui.font, '\xb6' /*FIXME*/, glyph ); + ui_text_glyph( vg_ui.font, '\xb1' /*FIXME*/, glyph ); ui_fill_rect( text_cursor, 0x00ffffff, glyph ); text_cursor[0] += vg_ui.font->sx*scale; } @@ -1199,6 +1199,14 @@ void ui_postrender(void) * ----------------------------------------------------------------------------- */ +enum ui_button_state ui_checkbox_base( ui_rect box, i32 *data ) +{ + enum ui_button_state state = ui_button_base( box ); + if( state == k_ui_button_click ) + *data = (*data) ^ 0x1; + return state; +} + int ui_checkbox( ui_rect inout_panel, const char *str_label, i32 *data ) { ui_rect rect, label, box; @@ -1206,12 +1214,34 @@ int ui_checkbox( ui_rect inout_panel, const char *str_label, i32 *data ) ui_split( rect, k_ui_axis_v, -rect[3], 0, label, box ); ui_text( label, str_label, k_ui_scale, k_ui_align_middle_left, 0 ); + + enum ui_button_state state = ui_checkbox_base( box, data ); - int changed = ui_colourbutton( box, k_ui_bg, 0, 0 ) == k_ui_button_click; - if( changed ) - *data = (*data) ^ 0x1; + if( state == k_ui_button_holding_inside ) + { + ui_fill( box, ui_colour(k_ui_bg+2) ); + ui_outline( box, 1, ui_colour(k_ui_fg), 0 ); + } + else if( state == k_ui_button_holding_outside ) + { + ui_fill( box, ui_colour(k_ui_bg) ); + ui_outline( box, 1, ui_colour(k_ui_fg), 0 ); + } + else if( state == k_ui_button_hover ) + { + ui_fill( box, ui_colour(k_ui_bg) ); + ui_outline( box, 1, ui_colour(k_ui_fg), 0 ); + } + else + { + ui_fill( box, ui_colour(k_ui_bg) ); + ui_outline( box, 1, ui_colour(k_ui_bg+4), 0 ); + } + + bool changed = (state == k_ui_button_click); - if( *data ){ + if( *data ) + { ui_rect_pad( box, (ui_px[2]){4,4} ); ui_fill( box, ui_colour( k_ui_orange ) ); } diff --git a/vg_imgui.h b/vg_imgui.h index 7e882aa..8ec0330 100644 --- a/vg_imgui.h +++ b/vg_imgui.h @@ -277,6 +277,7 @@ enum ui_button_state ui_button( ui_rect inout_panel, const char *string ); void ui_postrender(void); +enum ui_button_state ui_checkbox_base( ui_rect box, i32 *data ); int ui_checkbox( ui_rect inout_panel, const char *str_label, i32 *data ); void ui_enum( ui_rect inout_panel, const char *str_label, struct ui_enum_opt *options, u32 len, i32 *value );