better way of doing fonts for ui
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 8 Feb 2022 04:42:11 +0000 (22:42 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 8 Feb 2022 04:42:11 +0000 (22:42 -0600)
src/entity/editor.onyx
src/gfx/ui.onyx

index 6c2d5a3ed34af15ce52f13a68932b74ca7620557..9d91d281d64a5096c4869ce0709243273cd648e0 100644 (file)
@@ -187,7 +187,7 @@ editor_draw :: () {
         y += 40.0f;
         theme := Button_Theme.{};
         theme.active = active_index == i;
-        if draw_button(.{x + 4, y - 18, w, 36.0f}, info.name, ^theme, increment=i) {
+        if draw_button(.{x, y - 18, w, 36.0f}, info.name, ^theme, increment=i) {
             active_index = i;
         }
     }
index c0436f236f6b5bbc1fa17b74eed1f354950e7e5c..bab6555414a67ad1c5034773897176da60307dc9 100644 (file)
@@ -42,8 +42,7 @@ Button_Theme :: struct {
     active := false;
 }
 
-@CompilerBug // This should work...
-// default_button_theme := Button_Theme.{};
+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.
@@ -94,9 +93,7 @@ draw_button  :: (use r: Rect, text: str, theme: ^Button_Theme, site := #callsite
     immediate_set_color(surface_color);
     immediate_rectangle(x + border_width, y + border_width, w - border_width * 2, h - border_width * 2);
 
-    font : Font;
-    if theme.font == null do font = font_lookup(.{"./assets/fonts/calibri.ttf", 16});
-    else                  do font = *theme.font;
+    font := font_lookup(.{theme.font_name, theme.font_size});
     font_height := font_get_height(font, text);
     font_set_color(theme.text_color);
     font_draw_centered(font, x, y + (h - font_height) / 2 + font.em - 2, w, text);
@@ -131,8 +128,7 @@ Textbox_Theme :: struct {
     placeholder_text_color := Color.{ 0.5, 0.5, 0.5 };
 }
 
-@CompilerBug
-// default_textbox_theme := Textbox_Theme.{};
+default_textbox_theme := Textbox_Theme.{};
 
 #local {
     Textbox_Editing_State :: struct {
@@ -161,9 +157,7 @@ draw_textbox :: (use r: Rect, text_buffer: ^[..] u8, placeholder := null_str, th
         text_color = theme.placeholder_text_color;
     }
 
-    font : Font;
-    if theme.font == null do font = font_lookup(.{"./assets/fonts/calibri.ttf", 16});
-    else                  do font = *theme.font;
+    font := font_lookup(.{theme.font_name, theme.font_size});
     text_width  := font_get_width(font, text);
     text_height := font_get_height(font, text);
 
@@ -303,7 +297,8 @@ draw_textbox :: (use r: Rect, text_buffer: ^[..] u8, placeholder := null_str, th
 
     Text_Theme :: struct {
         text_color := Color.{1, 1, 1};
-        font       :  ^Font = null;
+        font_name  := "./assets/fonts/calibri.ttf";
+        font_size  := 18;
     }
 
     Animation_Theme :: struct {