From 47558576afa2fc66ee6c29944d7570c2dd7c0574 Mon Sep 17 00:00:00 2001 From: Daniel Bross Date: Wed, 1 Jan 2025 02:29:58 +0100 Subject: [PATCH] Checkbox time --- editor/editor_ui.jai | 4 +++- ui/widgets.jai | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/editor/editor_ui.jai b/editor/editor_ui.jai index 2f96207..6ecf470 100644 --- a/editor/editor_ui.jai +++ b/editor/editor_ui.jai @@ -31,6 +31,8 @@ pick_scene_view_at :: (camera: Camera, coordinates: Vector2) { } } +test := false; + editor_ui :: () { // Scene picking if !ui_mouse_over_window() { @@ -55,7 +57,7 @@ editor_ui :: () { } ui_window_begin("Entities", 1, 5, 200, 600); - checked := ui_checkbox(true); + test = ui_checkbox(test); if engine.current_scene != null { for engine.current_scene.entities { if it.flags & .DELETED continue; diff --git a/ui/widgets.jai b/ui/widgets.jai index 37f5335..9426bf7 100644 --- a/ui/widgets.jai +++ b/ui/widgets.jai @@ -32,21 +32,29 @@ ui_button :: (text: string, identifier: s64 = 0, loc := #caller_location) -> cli ui_checkbox :: (checked: bool, identifier: s64 = 0, loc := #caller_location) -> bool { ui_set_next_background_color(.{0.2,0.2,0.2,1}); ui_set_next_text_color(.{1,1,1,1}); - ui_set_next_size_x(.PIXELS, 20); - ui_set_next_size_y(.PIXELS, 20); + ui_set_next_size_x(.PIXELS, 12); + ui_set_next_size_y(.PIXELS, 12); ui_set_next_padding(5); + //ui_set_next_padding(5); //ui_set_next_text_alignment(CENTER_HORIZONTALLY | .CENTER_VERTICALLY); - box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .DRAW_BACKGROUND | .ANIMATE_ON_HOVER, get_hash(loc, identifier)); + box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .DRAW_BACKGROUND, get_hash(loc, identifier)); ui_push_parent(box, .LEFT, .HORIZONTAL); { - //ui_set_next_padding(5); - ui_set_next_background_color(.{1.0,1.0,1.0,1}); - inner_box := ui_box_make(.DRAW_TEXT | .DRAW_BACKGROUND, get_hash(loc, 1)); + if checked { + ui_set_next_size_x(.PCT, 1); + ui_set_next_size_y(.PCT, 1); + ui_set_next_background_color(.{0.4,0.4,0.4,1}); + inner_box := ui_box_make(.DRAW_TEXT | .DRAW_BACKGROUND | .ANIMATE_ON_HOVER, get_hash(loc, 1)); + } } ui_pop_parent(); - return box.interaction.clicked; + if box.interaction.clicked { + return !checked; + } + + return checked; } ui_button_with_texture :: (texture_handle: Texture_Handle, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {