From 99dea9e863785cf8243e79e699dd94c8f485a27f Mon Sep 17 00:00:00 2001 From: Patrick Cleavelin Date: Fri, 19 Jan 2024 22:01:16 -0600 Subject: [PATCH] fix background being draw on top of border --- src/main.odin | 71 ++++++++++++++++++++++++++----------------------- src/ui/imm.odin | 29 +++++++++++++------- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/main.odin b/src/main.odin index 08804ce..82a0ddc 100644 --- a/src/main.odin +++ b/src/main.odin @@ -212,6 +212,13 @@ load_plugin :: proc(info: os.File_Info, in_err: os.Errno, state: rawptr) -> (err return in_err, skip_dir; } +ui_font_width :: proc() -> i32 { + return i32(state.source_font_width); +} +ui_font_height :: proc() -> i32 { + return i32(state.source_font_height); +} + main :: proc() { state = State { ctx = context, @@ -224,6 +231,12 @@ main :: proc() { highlighters = make(map[string]plugin.OnColorBufferProc), hooks = make(map[plugin.Hook][dynamic]plugin.OnHookProc), }; + + ui_ctx := ui.Context { + text_width = ui_font_width, + text_height = ui_font_height, + } + state.plugin_vtable = plugin.Plugin { state = cast(rawptr)&state, register_hook = proc "c" (hook: plugin.Hook, on_hook: plugin.OnHookProc) { @@ -737,9 +750,9 @@ main :: proc() { } } - raylib.InitWindow(640, 480, "odin_editor - [back to basics]"); + raylib.InitWindow(640, 480, "odin_editor - [now with more ui]"); raylib.SetWindowState({ .WINDOW_RESIZABLE, .VSYNC_HINT }); - raylib.SetTargetFPS(60); + raylib.SetTargetFPS(144); raylib.SetExitKey(.KEY_NULL); // TODO: don't just hard code a MacOS font path @@ -772,13 +785,6 @@ main :: proc() { raylib.ClearBackground(theme.get_palette_raylib_color(.Background)); - // TODO: be more granular in /what/ is being draw by the plugin - for plugin in state.plugins { - if plugin.on_initialize != nil { - //plugin.on_draw(plugin.plugin); - } - } - core.draw_file_buffer(&state, buffer, 32, state.source_font_height, state.font); { @@ -789,7 +795,7 @@ main :: proc() { ui.push_parent(ui.push_box("top_nav", {.DrawBackground}, semantic_size = {ui.make_semantic_size(.PercentOfParent, 100), ui.make_semantic_size(.Exact, state.source_font_height)})); defer ui.pop_parent(); - if ui.button("Editor").clicked { + if ui.label("Editor").clicked { fmt.println("you clicked the button"); } @@ -802,23 +808,12 @@ main :: proc() { } ); - if ui.button("Buffers").clicked { + if ui.label("Buffers").clicked { fmt.println("you clicked the button"); } - - //ui.two_buttons_test("button left", "button right"); } { - ui.push_parent(ui.push_box("deezbuffer", {}, semantic_size = {ui.make_semantic_size(.PercentOfParent, 100), ui.make_semantic_size(.Fill, 0)})); - defer ui.pop_parent(); - - ui.spacer("left side"); - { - ui.push_parent(ui.spacer("right side")); - defer ui.pop_parent(); - - ui.button("Do you need some help?"); - } + ui.push_box("deezbuffer", {}, semantic_size = {ui.make_semantic_size(.PercentOfParent, 100), ui.make_semantic_size(.Fill, 0)}); } { ui.push_parent(ui.push_box("bottom stats", {.DrawBackground}, semantic_size = {ui.make_semantic_size(.PercentOfParent, 100), ui.make_semantic_size(.Exact, state.source_font_height)})); @@ -837,16 +832,26 @@ main :: proc() { ui.spacer("stats inbetween"); - line_info_text := raylib.TextFormat( - "Line: %d, Col: %d, Len: %d --- Slice Index: %d, Content Index: %d", - //"Line: %d, Col: %d", - buffer.cursor.line + 1, - buffer.cursor.col + 1, - core.file_buffer_line_length(buffer, buffer.cursor.index), - buffer.cursor.index.slice_index, - buffer.cursor.index.content_index - ); - ui.button(string(line_info_text)); + { + ui.push_parent(ui.push_box("center info", {}, semantic_size = ui.ChildrenSum)); + defer ui.pop_parent(); + + line_info_text := raylib.TextFormat( + //"Line: %d, Col: %d, Len: %d --- Slice Index: %d, Content Index: %d --- Frame Time: %fms", + "Line: %d, Col: %d", + buffer.cursor.line + 1, + buffer.cursor.col + 1, + //core.file_buffer_line_length(buffer, buffer.cursor.index), + // buffer.cursor.index.slice_index, + // buffer.cursor.index.content_index, + ); + ui.label(string(line_info_text)); + } + + ui.spacer("frame time spacer"); + frame_time := (60.0/f32(raylib.GetFPS())) * 10; + frame_time_text := raylib.TextFormat("frame time: %fms", frame_time); + ui.label(string(frame_time_text)); } } diff --git a/src/ui/imm.odin b/src/ui/imm.odin index 7ea021c..aa8bf14 100644 --- a/src/ui/imm.odin +++ b/src/ui/imm.odin @@ -7,6 +7,11 @@ import "vendor:raylib" import "../theme" +Context :: struct { + text_width: proc() -> i32, + text_height: proc() -> i32, +} + root: ^Box = nil; current_parent: ^Box = nil; persistent: map[Key]^Box = nil; @@ -454,15 +459,6 @@ draw :: proc(font: raylib.Font, font_width: int, font_height: int, box: ^Box = r push_clip(box.computed_pos, box.computed_size); defer pop_clip(); - if .DrawBorder in box.flags { - raylib.DrawRectangleLines( - i32(box.computed_pos.x), - i32(box.computed_pos.y), - i32(box.computed_size.x), - i32(box.computed_size.y), - theme.get_palette_raylib_color(.Background4) - ); - } if .DrawBackground in box.flags { raylib.DrawRectangle( i32(box.computed_pos.x), @@ -472,6 +468,15 @@ draw :: proc(font: raylib.Font, font_width: int, font_height: int, box: ^Box = r theme.get_palette_raylib_color(.Background1) ); } + if .DrawBorder in box.flags { + raylib.DrawRectangleLines( + i32(box.computed_pos.x), + i32(box.computed_pos.y), + i32(box.computed_size.x), + i32(box.computed_size.y), + theme.get_palette_raylib_color(.Background4) + ); + } if .DrawText in box.flags { for codepoint, index in box.label { raylib.DrawTextCodepoint( @@ -535,6 +540,12 @@ spacer :: proc(label: string) -> ^Box { return push_box(label, {}, semantic_size = {make_semantic_size(.Fill, 0), make_semantic_size(.Fill, 0)}); } +label :: proc(label: string) -> Interaction { + box := push_box(label, {.DrawText}); + + return test_box(box); +} + button :: proc(label: string) -> Interaction { box := push_box(label, {.Clickable, .Hoverable, .DrawText, .DrawBorder, .DrawBackground});