diff options
author | San Jacobs | 2025-10-03 15:38:18 +0200 |
---|---|---|
committer | San Jacobs | 2025-10-03 15:38:18 +0200 |
commit | 4a23e74951aa20f1fb9016f30e083f8ed5b11918 (patch) | |
tree | c92bdce650a601c0e68670659e34faa9771e4ef6 /src | |
parent | 76af2394368c4f5e5361b608099cdcf481dac8d7 (diff) | |
download | tafl-master.tar.gz tafl-master.tar.bz2 tafl-master.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/tafl/tafl.odin | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/tafl/tafl.odin b/src/tafl/tafl.odin index 21de20f..9dad078 100644 --- a/src/tafl/tafl.odin +++ b/src/tafl/tafl.odin @@ -24,8 +24,6 @@ scissor_stack : [1024]Box mouse_position : [2]int -tafl_cache : map[string]Tafl_Cache - dragging_id : string = "" drag_root : [2]int drag_delta : [2]int @@ -41,7 +39,7 @@ hovered_id : string something_is_hovered := false DEFAULT_FONT : rl.Font -FONT_SIZE : int : 24 +DEFAULT_FONT_SIZE : int : 26 clear_layout :: proc() { tafl_stack_depth = 0 @@ -61,6 +59,7 @@ tafl :: proc( child_gap : int = 0, color : Color = {0,0,0,0}, text := "", + font_size := DEFAULT_FONT_SIZE, id := "", flags : Feature_Flags = {}, ) -> Com { @@ -75,6 +74,7 @@ tafl :: proc( child_gap = child_gap, color = color, text = text, + font_size = font_size, id = id, flags = flags, ) @@ -90,6 +90,8 @@ tafl_open :: proc( child_gap : int = 0, color : Color = {0,0,0,0}, text := "", + font_size := DEFAULT_FONT_SIZE, + font_type : Font_Type = .SANS, id := "", flags : Feature_Flags = {}, ) -> Com { @@ -103,7 +105,8 @@ tafl_open :: proc( } if text != "" { - measurement := rl.MeasureTextEx(DEFAULT_FONT, strings.clone_to_cstring(text, allocator=context.temp_allocator), f32(FONT_SIZE), 0) + font := get_font(font_size) + measurement := rl.MeasureTextEx(font, strings.clone_to_cstring(text, allocator=context.temp_allocator), f32(font_size), 0) width = max(width, int(measurement.x)) height = max(height, int(measurement.y)) } @@ -181,6 +184,7 @@ tafl_open :: proc( align_children = align_children, cut_from = cut_from, + font_size = font_size, color = color, @@ -300,8 +304,6 @@ render :: proc() { rl.EndScissorMode() - rl.DrawFPS(5, 5) - rl.EndDrawing() @@ -357,7 +359,8 @@ recursive_draw :: proc(index : int) { u8(tafl.color.a*255.0),} rl.DrawRectangleRec({f32(tafl.x), f32(tafl.y), f32(tafl.width), f32(tafl.height),}, color) if(tafl.text != "") { - rl.DrawTextEx(DEFAULT_FONT, strings.clone_to_cstring(tafl.text, allocator=context.temp_allocator), {f32(tafl.x), f32(tafl.y)}, f32(FONT_SIZE), 0, rl.WHITE) + font := get_font(tafl.font_size) + rl.DrawTextEx(font, strings.clone_to_cstring(tafl.text, allocator=context.temp_allocator), {f32(tafl.x), f32(tafl.y)}, f32(tafl.font_size), 0, rl.WHITE) } for child_index in child_index_buffer[tafl.children.index:tafl.children.index+tafl.children.len] { @@ -370,7 +373,8 @@ start_window :: proc(width, height : int, title : cstring, fps_target : int = 60 rl.SetTargetFPS(60) rl.SetConfigFlags({.WINDOW_RESIZABLE}) rl.InitWindow(i32(width), i32(height), title) - DEFAULT_FONT = rl.LoadFontFromMemory(".ttf", raw_data(__DEFAULT_FONT_FILE), i32(len(__DEFAULT_FONT_FILE)), i32(FONT_SIZE), nil, 0) + DEFAULT_FONT = rl.LoadFontFromMemory(".ttf", raw_data(__DEFAULT_FONT_FILE), i32(len(__DEFAULT_FONT_FILE)), i32(DEFAULT_FONT_SIZE), nil, 0) + _FONTS[DEFAULT_FONT_SIZE] = DEFAULT_FONT } window_should_close :: proc() -> bool { @@ -444,7 +448,8 @@ Tafl :: struct { child_gap : int, color : Color, text : string, - id : string, + font_size : int, + id : string, flags : Feature_Flags, @@ -452,9 +457,9 @@ Tafl :: struct { hover_t : f32, press_t : f32, } -Tafl_Cache :: struct{ - hover_t : f32, - press_t : f32, +Font_Type :: enum { + SANS, + MONO, } Feature_Flag :: enum { @@ -523,4 +528,12 @@ u8_clamp :: proc(input: f32) -> u8 { if mult<0 do output = 0 if mult>255 do output = 255 return output +} + +_FONTS : map[int]rl.Font +get_font :: proc(size : int) -> rl.Font { + if size not_in _FONTS { + _FONTS[size] = rl.LoadFontFromMemory(".ttf", raw_data(__DEFAULT_FONT_FILE), i32(len(__DEFAULT_FONT_FILE)), i32(size), nil, 0) + } + return _FONTS[size] }
\ No newline at end of file |