From 69a76bfb3d66544ea02e585a5a898a0e6fbdc019 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 7 Feb 2022 22:48:20 -0600 Subject: [PATCH] actually using the work that I did with fonts --- src/entity/editor.onyx | 8 +++----- src/gfx/ui.onyx | 17 +++++++---------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/entity/editor.onyx b/src/entity/editor.onyx index 9d91d28..e59bab6 100644 --- a/src/entity/editor.onyx +++ b/src/entity/editor.onyx @@ -138,11 +138,11 @@ editor_draw :: () { h -= 4; w = 100; + theme := Button_Theme.{}; for^ type_info.enum_values(Tabs) { // Don't draw the "None" item; if it.value == 0 do continue; - theme := Button_Theme.{}; theme.active = active_tab == ~~it.value; if draw_button(.{x, y, w, h}, it.name, ^theme, increment=~~it.value) { clicked_tab = ~~it.value; @@ -185,8 +185,7 @@ editor_draw :: () { info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(type); y += 40.0f; - theme := Button_Theme.{}; - theme.active = active_index == i; + theme := Button_Theme.{active = active_index == i}; if draw_button(.{x, y - 18, w, 36.0f}, info.name, ^theme, increment=i) { active_index = i; } @@ -200,8 +199,7 @@ editor_draw :: () { test << #char "t"; } - theme := Textbox_Theme.{}; - draw_textbox(.{x, y + 72.0f, w, 36.0f}, ^test, theme=^theme); + draw_textbox(.{x, y + 72.0f, w, 36.0f}, ^test); } #local render_entity_fields :: (entity: ^Entity, x, y, w, h: f32) { diff --git a/src/gfx/ui.onyx b/src/gfx/ui.onyx index bab6555..0e987ce 100644 --- a/src/gfx/ui.onyx +++ b/src/gfx/ui.onyx @@ -42,14 +42,9 @@ Button_Theme :: struct { active := false; } -default_button_theme := Button_Theme.{}; +#local default_button_theme := Button_Theme.{}; -draw_button :: (use r: Rect, text: str, theme: ^Button_Theme, site := #callsite, increment := 0) -> bool { - // HMMM.... this should be gotten rid of as quick as possible. - __ASDF := Button_Theme.{}; - if theme == null { - theme = ^__ASDF; - } +draw_button :: (use r: Rect, text: str, theme := ^default_button_theme, site := #callsite, increment := 0) -> bool { result := false; hash := get_site_hash(site, increment); @@ -128,9 +123,9 @@ Textbox_Theme :: struct { placeholder_text_color := Color.{ 0.5, 0.5, 0.5 }; } -default_textbox_theme := Textbox_Theme.{}; - #local { + default_textbox_theme := Textbox_Theme.{}; + Textbox_Editing_State :: struct { hash: UI_Id = 0; @@ -142,7 +137,7 @@ default_textbox_theme := Textbox_Theme.{}; textbox_editing_state := Textbox_Editing_State.{}; } -draw_textbox :: (use r: Rect, text_buffer: ^[..] u8, placeholder := null_str, theme: ^Textbox_Theme = null, site := #callsite, increment := 0) -> bool { +draw_textbox :: (use r: Rect, text_buffer: ^[..] u8, placeholder := null_str, theme := ^default_textbox_theme, site := #callsite, increment := 0) -> bool { result := false; hash := get_site_hash(site, increment); @@ -224,6 +219,8 @@ draw_textbox :: (use r: Rect, text_buffer: ^[..] u8, placeholder := null_str, th textbox_editing_state.cursor_position = math.clamp(textbox_editing_state.cursor_position, 0, text_buffer.count); textbox_editing_state.cursor_animation = 1.0f; + + text = str.{text_buffer.data, text_buffer.count}; } } -- 2.25.1