From 5f0af59c18d136c64c579daff7d1599135a2c482 Mon Sep 17 00:00:00 2001 From: Katajisto Date: Sat, 3 May 2025 11:42:14 +0300 Subject: [PATCH] ui text rendering ordering working + console report view --- src/arbtri.jai | 60 +++--------------------------------------- src/editor/console.jai | 24 ++++++++++++++--- src/editor/editor.jai | 2 +- src/main.jai | 7 ++++- src/ui/ui.jai | 28 ++++++++++++-------- 5 files changed, 48 insertions(+), 73 deletions(-) diff --git a/src/arbtri.jai b/src/arbtri.jai index c5aae21..2ce77fb 100644 --- a/src/arbtri.jai +++ b/src/arbtri.jai @@ -24,10 +24,7 @@ Arb_Draw_Command :: struct { texture : *Ui_Texture; // for text - font : *Ui_Font; - text : string; - text_color : Vector4; - x,y : s64; + layer: s32 = 0; } @@ -102,8 +99,7 @@ arb_tri_flush :: () { flush_arb_commands(); } -debug_arb_flush : bool : true; -is_in_pass : bool = false; +debug_arb_flush : bool : false; layer : s32 = 0; @@ -119,62 +115,12 @@ flush_arb_commands :: () { case .REMOVE_TEXTURE; gCurrentTexture = null; case .FLUSH_TRI; - // if !is_in_pass { - // sg_begin_pass(*(sg_pass.{ action = state.pass_action, swapchain = cast,force(sg_swapchain) sglue_swapchain() })); - // is_in_pass = true; - // } sg_apply_pipeline(gPipelines.arbtri.pipeline); sg_apply_bindings(*gPipelines.arbtri.bind); sg_draw(xx (it.tri_offset * 3), xx (it.tri_count * 3), 1); case .PREPARE_TEXT; - // if is_in_pass { - // sg_end_pass(); - // is_in_pass = false; - // } - font := it.font; - text := it.text; - if text.count < 1 then continue; - print("prep at size: %\n", font.character_height); - fonsSetFont(state.fons, state.font_default.fons_font); - fonsSetSize(state.fons, xx font.character_height); - w := fonsTextBounds(state.fons, 0.0, 0.0, text.data, text.data + text.count, null); - gPreppedText = text; - gPreppedTextWidth = cast(s32) w; - - array_reset(*font.temporary_glyphs); - array_reset(*font.temporary_glyphs_byte_offsets); - - for 0..(text.count-1) { - glyph : Ui_Font_Glyph; - - glyph.advance = cast(u32) fonsTextBounds(state.fons, 0.0, 0.0, text.data + it, text.data + it + 1, null); - - array_add(*font.temporary_glyphs, glyph); - array_add(*font.temporary_glyphs_byte_offsets, cast(u32) it); - } case .DRAW_TEXT; - if gPreppedText.count < 1 then continue; - text_color := it.text_color; - x := it.x; - y := it.y; - font := it.font; - - color := sfons_rgba(xx (255.0 * text_color.x), xx (255.0 * text_color.y), xx (255.0 * text_color.z), xx (255.0 * text_color.w)); - fonsSetColor(state.fons, color); - result := cast(*u8) temporary_alloc(gPreppedText.count + 1); // Add 1 for the zero. - memcpy(result, gPreppedText.data, gPreppedText.count); - result[gPreppedText.count] = 0; - sgl_layer(layer); - fonsDrawText(state.fons, xx x, xx y, result, null); - // sg_begin_pass(*(sg_pass.{ action = state.pass_action, swapchain = cast,force(sg_swapchain) sglue_swapchain() })); - sfons_flush(state.fons); - sgl_draw_layer(layer); - // sg_end_pass(); - layer += 1; - fonsPushState(state.fons); + sgl_draw_layer(it.layer); } } - // if is_in_pass { - // sg_end_pass(); - // } } diff --git a/src/editor/console.jai b/src/editor/console.jai index 5cb4732..23bde19 100644 --- a/src/editor/console.jai +++ b/src/editor/console.jai @@ -4,8 +4,12 @@ Console_State :: enum { OPEN_FULL; } +MAX_REPORT_ROWS :: 100; + console_state : Console_State = .CLOSED; +console_report : [..]string; + console_h : float = 0.0; console_move_speed : float = 400.0; @@ -53,9 +57,13 @@ tick_console :: () { console_h = t; } } + + while console_report.count > MAX_REPORT_ROWS { + array_ordered_remove_by_index(*console_report, 0); + } } -console_input : string = "HELLO??dasdasdasd"; +console_input_start : string = ""; draw_console :: (theme: *GR.Overall_Theme) { if console_h < 1 then return; @@ -65,7 +73,17 @@ draw_console :: (theme: *GR.Overall_Theme) { r.x -= 1*vw; r.y = r.h - ui_h(5, 4); r.h = ui_h(5, 4); - // GR.label(r, "HELLO?!! wTF=", *theme.label_theme); - a, new, state := GR.text_input(r, console_input, *theme.text_input_theme); + + a, new, state := GR.text_input(r, console_input_start, *theme.text_input_theme); + if a & .ENTERED { + array_add(*console_report, copy_string(tprint("> %", new))); + state.text = console_input_start; + } + + for < console_report { + r.y -= r.h; + GR.label(r, it, *t_label_left(theme)); + } + if !state.active then GR.activate(state); } diff --git a/src/editor/editor.jai b/src/editor/editor.jai index a1e90b1..ef52e0d 100644 --- a/src/editor/editor.jai +++ b/src/editor/editor.jai @@ -6,7 +6,7 @@ draw_editor_ui :: (theme: *GR.Overall_Theme) { r.y = 0; r.h = ui_h(5, 0); draw_bg_rectangle(r, theme); r.w = 15*vw; - GR.label(r, "Trueno!", *t_label_left(theme)); + GR.label(r, tprint("Trueno v%.%", V_MAJOR, V_MINOR), *t_label_left(theme)); r = GR.get_rect(0, ui_h(5,0), ui_w(20, 20), ui_h(95, 0)); draw_bg_rectangle(r, theme); diff --git a/src/main.jai b/src/main.jai index 39cda58..9ba10d6 100644 --- a/src/main.jai +++ b/src/main.jai @@ -15,6 +15,10 @@ stbi :: #import "stb_image"; last_frame_time : float64; delta\ _time : float64; + +V_MAJOR :: 0; +V_MINOR :: 2; + state: struct { pass_action_clear : sg_pass_action; pass_action : sg_pass_action; @@ -104,7 +108,8 @@ frame :: () { tick_ui(); render_ui(); - is_in_pass = true; + + // UI Pass: sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, swapchain = cast,force(sg_swapchain) sglue_swapchain() })); arb_tri_flush(); sg_end_pass(); diff --git a/src/ui/ui.jai b/src/ui/ui.jai index 7e4f94e..2b8c264 100644 --- a/src/ui/ui.jai +++ b/src/ui/ui.jai @@ -153,13 +153,11 @@ gPreppedText: string; gPreppedTextWidth : s32; prepare_text :: (font: *Ui_Type_Indicator.Font, text: string, effects: Ui_Type_Indicator.Font_Effects = 0) -> s64 { - if text.count < 1 then return 0; - - arb_tri_command_add(.{ - type = .PREPARE_TEXT, - font = font, - text = text - }); + if text.count < 1 { + gPreppedText = ""; + gPreppedTextWidth = 0; + return 0; + } fonsSetFont(state.fons, state.font_default.fons_font); fonsSetSize(state.fons, xx font.character_height); w := fonsTextBounds(state.fons, 0.0, 0.0, text.data, text.data + text.count, null); @@ -181,13 +179,21 @@ prepare_text :: (font: *Ui_Type_Indicator.Font, text: string, effects: Ui_Type_I return cast(s64) w; } draw_prepared_text :: (font: *Ui_Type_Indicator.Font, x: s64, y: s64, text_color: Vector4, effects: Ui_Type_Indicator.Font_Effects = 0) { + if gPreppedText.count < 1 then return; + color := sfons_rgba(xx (255.0 * text_color.x), xx (255.0 * text_color.y), xx (255.0 * text_color.z), xx (255.0 * text_color.w)); + fonsSetColor(state.fons, color); + result := cast(*u8) temporary_alloc(gPreppedText.count + 1); // Add 1 for the zero. + memcpy(result, gPreppedText.data, gPreppedText.count); + result[gPreppedText.count] = 0; + sgl_layer(layer); + fonsDrawText(state.fons, xx x, xx y, result, null); + sfons_flush(state.fons); + fonsPushState(state.fons); arb_tri_command_add(.{ type = .DRAW_TEXT, - text_color = text_color, - font = font, - x = x, - y = y + layer = layer }); + layer += 1; } get_mouse_pointer_position :: (window: Ui_Type_Indicator.Window_Type, right_handed: bool) -> (x: int, y: int, success: bool) { return xx input_mouse_x, xx input_mouse_y, true;