From 7b69723f3505374fde4c3dc611879caad9739ee9 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 9 Mar 2024 14:24:02 -0500 Subject: [PATCH] Made the ui_resize_border_width percent based instead of pixel based. --- code/api.odin | 2 +- code/env.odin | 2 +- code/tick_render.odin | 15 +++++++-------- code/tick_update.odin | 29 ++--------------------------- code/ui_signal.odin | 2 +- code/ui_tests.odin | 24 ++++++++++++++++++++++++ 6 files changed, 36 insertions(+), 38 deletions(-) diff --git a/code/api.odin b/code/api.odin index caf159b..551a9d9 100644 --- a/code/api.odin +++ b/code/api.odin @@ -102,7 +102,7 @@ startup :: proc( persistent_mem, frame_mem, transient_mem, files_buffer_mem : ^V engine_refresh_hz = 30 - ui_resize_border_width = 10 + ui_resize_border_width = 5 } Desired_OS_Scheduler_MS :: 1 diff --git a/code/env.odin b/code/env.odin index f6ae4de..8b9174f 100644 --- a/code/env.odin +++ b/code/env.odin @@ -128,7 +128,7 @@ AppConfig :: struct { engine_refresh_hz : uint, - ui_resize_border_width : uint, + ui_resize_border_width : f32, } State :: struct { diff --git a/code/tick_render.odin b/code/tick_render.odin index 0e7e156..d0e864e 100644 --- a/code/tick_render.odin +++ b/code/tick_render.odin @@ -160,10 +160,10 @@ render_mode_2d :: proc() rl.DrawRectangleRoundedLines( rect_padding, style.layout.corner_radii[0], 9, line_thickness, Color_Debug_UI_Padding_Bounds ) rl.DrawRectangleRoundedLines( rect_content, style.layout.corner_radii[0], 9, line_thickness, Color_Debug_UI_Content_Bounds ) - if .Mouse_Resizable in current.flags { - resize_border_width := cast(f32) get_state().config.ui_resize_border_width - - resize_percent_width := style.size * (1.0 / resize_border_width) + if .Mouse_Resizable in current.flags + { + resize_border_width := cast(f32) get_state().config.ui_resize_border_width + resize_percent_width := style.size * (resize_border_width * 1.0/ 200.0) resize_border_non_range := add(current.computed.bounds, range2( { resize_percent_width.x, -resize_percent_width.x }, { -resize_percent_width.x, resize_percent_width.x })) @@ -181,10 +181,9 @@ render_mode_2d :: proc() rl.DrawRectangleRoundedLines( rect_resize, style.layout.corner_radii[0], 9, line_thickness, Color_Red ) } - // if current - - // rl.DrawCircleV( render_bounds.p0, 5, Color_Red ) - // rl.DrawCircleV( render_bounds.p1, 5, Color_Blue ) + point_radius := 3 * (1 / cam.zoom) + rl.DrawCircleV( render_bounds.p0, point_radius, Color_Red ) + rl.DrawCircleV( render_bounds.p1, point_radius, Color_Blue ) if len(current.text.str) > 0 { draw_text_string_cached( current.text, world_to_screen_pos(computed.text_pos), style.font_size, style.text_color ) diff --git a/code/tick_update.odin b/code/tick_update.odin index e7ce935..9102348 100644 --- a/code/tick_update.odin +++ b/code/tick_update.odin @@ -228,34 +228,9 @@ update :: proc( delta_time : f64 ) -> b32 frame_theme.focused.bg_color = Color_Frame_Select ui_style_theme( frame_theme ) - // test_hover_n_click() - + config.ui_resize_border_width = 2.5 test_draggable() - - config.ui_resize_border_width = 20 - // First box with text!!!! - when true - { - @static pos : Vec2 - style := ui_style_peek( .Default ) - ui_style_theme( { styles = { style, style, style, style, }} ) - - text := str_intern( "Lorem ipsum dolor sit amet") - font_size := 30 - - text_box := ui_text("TEXT BOX!", text, 30, flags = { .Mouse_Clickable }) - if text_box.first_frame { - pos = text_box.style.layout.pos - } - - if text_box.dragging { - pos += mouse_world_delta() - } - - text_box.style.layout.pos = pos - } - - // test_draggable() + test_text_box() } //endregion Imgui Tick diff --git a/code/ui_signal.odin b/code/ui_signal.odin index 3af368a..cb99251 100644 --- a/code/ui_signal.odin +++ b/code/ui_signal.odin @@ -14,7 +14,7 @@ ui_signal_from_box :: proc ( box : ^ UI_Box ) -> UI_Signal signal.cursor_over = cast(b8) pos_within_range2( signal.cursor_pos, box.computed.bounds ) resize_border_width := cast(f32) get_state().config.ui_resize_border_width - resize_percent_width := box.style.size * (1.0 / resize_border_width) + resize_percent_width := box.style.size * (resize_border_width * 1.0/ 200.0) resize_border_non_range := add(box.computed.bounds, range2( { resize_percent_width.x, -resize_percent_width.x }, { -resize_percent_width.x, resize_percent_width.x })) diff --git a/code/ui_tests.odin b/code/ui_tests.odin index 6e3c968..32cfca2 100644 --- a/code/ui_tests.odin +++ b/code/ui_tests.odin @@ -54,3 +54,27 @@ test_draggable :: proc() draggable.style.layout.pos = debug.draggable_box_pos draggable.style.layout.size = debug.draggable_box_size } + +test_text_box :: proc() +{ + state := get_state(); using state + ui := ui_context + + @static pos : Vec2 + style := ui_style_peek( .Default ) + ui_style_theme( { styles = { style, style, style, style, }} ) + + text := str_intern( "Lorem ipsum dolor sit amet") + font_size := 30 + + text_box := ui_text("TEXT BOX!", text, 30, flags = { .Mouse_Clickable }) + if text_box.first_frame { + pos = text_box.style.layout.pos + } + + if text_box.dragging { + pos += mouse_world_delta() + } + + text_box.style.layout.pos = pos +} \ No newline at end of file