checkbox imgui api
authorhgn <hgodden00@gmail.com>
Wed, 17 Apr 2024 17:29:19 +0000 (18:29 +0100)
committerhgn <hgodden00@gmail.com>
Wed, 17 Apr 2024 17:29:19 +0000 (18:29 +0100)
src/fonts/vg_font_thin_3.png
src/fonts/vg_font_thin_3.xcf
vg_build_font.h
vg_imgui.c
vg_imgui.h

index ad1f1f46da24a25fbf8f4c418efb1c631e9a3aa7..18139a2944e86c8b77988d05d92aa7f33bd06a2c 100644 (file)
Binary files a/src/fonts/vg_font_thin_3.png and b/src/fonts/vg_font_thin_3.png differ
index 85ed68942883c3580b27cd5b621267b5e99eec90..1e40c461bac84e22cad69ef8a585c43c5388a91e 100644 (file)
Binary files a/src/fonts/vg_font_thin_3.xcf and b/src/fonts/vg_font_thin_3.xcf differ
index 5278ca10094b94cd84594641737ced96384b0e31..5ee5e10b77a8132da5a34526d4e72bcdacfaa26f 100644 (file)
@@ -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 );
index 60bb296bfab0a3d8eb9984b8f3f853d4523aa0d8..bb4f46f54d7f7d152904985871c75d0f9f6c2140 100644 (file)
@@ -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 ) );
    }
index 7e882aab38317cab119f5944f7da4ab033b6b5f7..8ec033009859b9ac44fe180a945a44eb27fcaeeb 100644 (file)
@@ -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 );