From e77dec086f94da480af8c42bec6cac8e873a6931 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Fri, 13 Oct 2023 12:00:49 +0200 Subject: Progressed ability to write text using new oui system --- src/ui_implementation.odin | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/ui_implementation.odin') diff --git a/src/ui_implementation.odin b/src/ui_implementation.odin index 4842a76..7c5f9e3 100644 --- a/src/ui_implementation.odin +++ b/src/ui_implementation.odin @@ -1,6 +1,8 @@ package main import "../lib/oui" +import "core:strings" +import "core:fmt" import rl "vendor:raylib" @@ -44,6 +46,8 @@ Data_Button :: struct { Data_Label :: struct { using _: Data_Head, text: string, + font: rl.Font, + font_size: i32, alignment: Text_Alignment, } @@ -84,6 +88,7 @@ button :: proc(text: string, width: int, selected := false) -> Item { Text_Alignment :: enum int { Left, Right, + Center } label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) -> Item { item := oui.item_make() @@ -91,6 +96,7 @@ label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) -> data := oui.alloc_typed(item, Data_Label) data.subtype = .Label data.text = text + data.font_size = font.baseSize // This should not be necesssary data.alignment = alignment return item @@ -121,10 +127,18 @@ ui_draw :: proc(item: oui.Item) { case .Button: rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), PBGCOLOR) case .Panel: - subtyped := cast(^Data_Panel) head - rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), subtyped.color) + data := cast(^Data_Panel) head + rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), data.color) ui_draw_children(item) case .Label: - + data := cast(^Data_Label) oui.get_handle(item) + + // For some reason, data.font.baseSize == 0 here. It doesn't outside of this function. Dunno why. + font_height := f32(data.font_size) + + rl.DrawTextEx(data.font, strings.unsafe_string_to_cstring(data.text), { 0, 0 }, font_height, 0.0, rl.RAYWHITE); + //rl.DrawTextEx(rl.GetFontDefault(), strings.unsafe_string_to_cstring(data.text), { 0, 0 }, 40, 0, rl.WHITE); + //rl.DrawFPS(0, 0) + //fmt.println(font_height) } } \ No newline at end of file -- cgit v1.2.1