From be7bac1f819012003b898154f530cc1361c8ccab Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 7 Feb 2022 22:42:11 -0600 Subject: [PATCH] better way of doing fonts for ui --- src/entity/editor.onyx | 2 +- src/gfx/ui.onyx | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/entity/editor.onyx b/src/entity/editor.onyx index 6c2d5a3..9d91d28 100644 --- a/src/entity/editor.onyx +++ b/src/entity/editor.onyx @@ -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; } } diff --git a/src/gfx/ui.onyx b/src/gfx/ui.onyx index c0436f2..bab6555 100644 --- a/src/gfx/ui.onyx +++ b/src/gfx/ui.onyx @@ -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 { -- 2.25.1