From b8a3f95dbbfa37aba72cda75b7df7eaf8f48e41c Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 8 Jul 2021 15:10:27 -0500 Subject: [PATCH] renaming scrollable_area to workspace --- modules/ui/components/textbox.onyx | 11 +++++++++-- .../{scrollable_area.onyx => workspace.onyx} | 14 +++++++------- modules/ui/module.onyx | 2 +- modules/ui/ui.onyx | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) rename modules/ui/components/{scrollable_area.onyx => workspace.onyx} (87%) diff --git a/modules/ui/components/textbox.onyx b/modules/ui/components/textbox.onyx index ed5d979a..78c83026 100644 --- a/modules/ui/components/textbox.onyx +++ b/modules/ui/components/textbox.onyx @@ -23,6 +23,8 @@ Textbox_Theme :: struct { cursor_color := gfx.Color4.{ 0.5, 0.5, 0.5 }; cursor_width := 4.0f; @InPixels cursor_blink_speed := 0.04f; // Bigger is faster + + placeholder_text_color := gfx.Color4.{ 0.5, 0.5, 0.5 }; } default_textbox_theme := Textbox_Theme.{}; @@ -41,7 +43,7 @@ Textbox_Editing_State :: struct { // There is only one 'Textbox_Editing_State', not a map of them because there can only be one textbox being edited at once. textbox_editing_state := Textbox_Editing_State.{}; -textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^default_textbox_theme, site := #callsite, increment := 0) -> bool { +textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, placeholder := null_str, theme := ^default_textbox_theme, site := #callsite, increment := 0) -> bool { result := false; hash := get_site_hash(site, increment); @@ -51,7 +53,12 @@ textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^defa border_width := theme.border_width; width, height := Rectangle.dimensions(r); + text_color := theme.text_color; text := string.buffer_to_str(text_buffer); + if text.count == 0 && placeholder.count > 0 { + text = placeholder; + text_color = theme.placeholder_text_color; + } text_width := bmfont.get_width(^font, text, theme.font_size); text_height := bmfont.get_height(^font, text, theme.font_size); @@ -147,7 +154,7 @@ textbox :: (use r: Rectangle, text_buffer: ^string.String_Buffer, theme := ^defa surface_color = color_lerp(animation_state.click_time, surface_color, theme.click_color); gfx.rect(.{ x0 + border_width, y0 + border_width }, .{ width - border_width * 2, height - border_width * 2 }, surface_color); - draw_text_raw(text, text_x, text_y, theme.font_size, theme.text_color); + draw_text_raw(text, text_x, text_y, theme.font_size, text_color); if textbox_editing_state.hash == hash { cursor_x := get_cursor_location(text_buffer, text_x, text_y, theme.font_size, textbox_editing_state.cursor_position); diff --git a/modules/ui/components/scrollable_area.onyx b/modules/ui/components/workspace.onyx similarity index 87% rename from modules/ui/components/scrollable_area.onyx rename to modules/ui/components/workspace.onyx index b13fef58..9fe95642 100644 --- a/modules/ui/components/scrollable_area.onyx +++ b/modules/ui/components/workspace.onyx @@ -3,7 +3,7 @@ package ui use package core #private_file -SA_State :: struct { +Workspace_State :: struct { transform: gfx.Transform = .{ translation = .{ 0, 0 }, scale = .{ 1, 1 }, @@ -13,14 +13,14 @@ SA_State :: struct { } #private -scrollable_area_states : map.Map(UI_Id, SA_State); +workspace_states : map.Map(UI_Id, Workspace_State); -scrollable_area_start :: (use r: Rectangle, site := #callsite) { +workspace_start :: (use r: Rectangle, site := #callsite) { hash := get_site_hash(site, 0); x, y := Rectangle.top_left(r); width, height := Rectangle.dimensions(r); - state := map.get(^scrollable_area_states, hash); + state := map.get(^workspace_states, hash); mx, my := get_mouse_position(); if Rectangle.contains(r, mx, my) { @@ -61,13 +61,13 @@ scrollable_area_start :: (use r: Rectangle, site := #callsite) { state.dragging = false; } - map.put(^scrollable_area_states, hash, state); + map.put(^workspace_states, hash, state); gfx.push_scissor(x, y, width, height); gfx.push_matrix(); gfx.apply_transform(state.transform); - zoom :: (state: ^SA_State, r: Rectangle, scale := 1.0f) { + zoom :: (state: ^Workspace_State, r: Rectangle, scale := 1.0f) { x, y := Rectangle.top_left(r); width, height := Rectangle.dimensions(r); @@ -82,7 +82,7 @@ scrollable_area_start :: (use r: Rectangle, site := #callsite) { } } -scrollable_area_end :: () { +workspace_end :: () { gfx.pop_scissor(); gfx.pop_matrix(); } \ No newline at end of file diff --git a/modules/ui/module.onyx b/modules/ui/module.onyx index 341a5dc0..96da6fec 100644 --- a/modules/ui/module.onyx +++ b/modules/ui/module.onyx @@ -48,7 +48,7 @@ package ui #load "./components/slider" #load "./components/radio" #load "./components/textbox" -#load "./components/scrollable_area" +#load "./components/workspace" // Package inclusions that are part of all files in the "ui" package. #private gfx :: package immediate_mode // The immediate_mode module needs to be accessible diff --git a/modules/ui/ui.onyx b/modules/ui/ui.onyx index 6310c56b..b6d94209 100644 --- a/modules/ui/ui.onyx +++ b/modules/ui/ui.onyx @@ -22,7 +22,7 @@ init_ui :: () { init_font(); map.init(^animation_states, default=.{}, hash_count=4); - map.init(^scrollable_area_states, default=.{}, hash_count=4); + map.init(^workspace_states, default=.{}, hash_count=4); } // This function should be called at the end of drawing a frame, after all of the UI elements -- 2.25.1