From a49ac7bca03c00eb1b6a3da16b7300ff0c1a0bf5 Mon Sep 17 00:00:00 2001 From: Able Date: Wed, 6 Nov 2024 09:36:17 -0600 Subject: [PATCH] Label Widget inside horizon --- sysdata/programs/horizon/src/main.hb | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index 0756293..5535bcd 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -4,9 +4,35 @@ stn := @use("../../../libraries/stn/src/lib.hb"); horizon_api := @use("../../../libraries/horizon_api/src/lib.hb") -render := @use("../../../libraries/render/src/lib.hb") +render := @use("../../../libraries/render/src/lib.hb"); +.{Surface} := render; +.{Font} := render.text intouch := @use("../../../libraries/intouch/src/lib.hb") +Label := struct {is_dirty: bool, surface: Surface, text: ^u8, text_length: uint} +set_label_text := fn(label: Label, text: ^u8, text_length: uint): void { + label.is_dirty = true + label.text = text + label.text_length = text_length +} + +render_label_to_surface := fn(surface: Surface, label: Label, font: Font): void { + if label.is_dirty { + render.clear(label.surface, render.blue) + render.put_text(label.surface, font, .(0, 0), render.red, "hi\0") + } + pos := Vec2(uint).(100, 100) + render.put_surface(surface, label.surface, pos, false) + render.sync(surface) +} + +new_label := fn(text: ^u8): Label { + text_surface := render.new_surface(100, 16) + text_length := string.length(text) + label := Label.(true, text_surface, text, text_length) + return label +} + Window := struct { // TODO: Replace this with widgets implicit_framebuffer: render.Surface, @@ -37,6 +63,7 @@ main := fn(): int { mouse_x := 0 mouse_y := 0 + text_label := new_label("Hi\0") loop { // Clear the screen @@ -70,6 +97,8 @@ main := fn(): int { render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white) + render_label_to_surface(screen, text_label, font) + // Sync the screen render.sync(screen) }