From 6b673bc7e6b789fc7faac13e43a5b327b98a68b9 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 18 Nov 2024 09:19:04 -0600 Subject: [PATCH] labels now have bg/fg color --- .../libraries/horizon_api/src/widgets/label.hb | 16 ++++++++++++---- sysdata/programs/sunset_server/src/main.hb | 9 +++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/sysdata/libraries/horizon_api/src/widgets/label.hb b/sysdata/libraries/horizon_api/src/widgets/label.hb index 106e452c..5d1fb195 100644 --- a/sysdata/libraries/horizon_api/src/widgets/label.hb +++ b/sysdata/libraries/horizon_api/src/widgets/label.hb @@ -3,7 +3,7 @@ stn := @use("../../../../libraries/stn/src/lib.hb"); .{Vec2} := stn.math render := @use("../../../../libraries/render/src/lib.hb"); -.{Surface} := render; +.{Surface, Color} := render; .{Font} := render.text Label := struct { @@ -12,6 +12,8 @@ Label := struct { surface: Surface, text: ^u8, text_length: uint, + bg: Color, + fg: Color, } set_label_text := fn(label: Label, text: ^u8): void { @@ -24,8 +26,8 @@ set_label_text := fn(label: Label, text: ^u8): void { render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void { if label.is_dirty { - render.clear(label.surface, render.black) - render.put_text(label.surface, font, .(0, 0), render.white, label.text) + render.clear(label.surface, label.bg) + render.put_text(label.surface, font, .(0, 0), label.fg, label.text) } render.put_surface(surface, label.surface, pos, false) } @@ -33,6 +35,12 @@ render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: V new_label := fn(text: ^u8): Label { text_surface := render.new_surface(1024, 20) text_length := string.length(text) - label := Label.(3, true, text_surface, text, text_length) + label := Label.(3, true, text_surface, text, text_length, render.black, render.white) return label +} + +$set_color := fn(label: Label, bg: Color, fg: Color): void { + label.bg = bg + label.fg = fg + label.is_dirty = true } \ No newline at end of file diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index bc28349d..43295868 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -3,7 +3,7 @@ render := @use("../../../libraries/render/src/lib.hb") intouch := @use("../../../libraries/intouch/src/lib.hb") horizon_api := @use("../../../libraries/horizon_api/src/lib.hb"); -.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label +.{new_label, render_label_to_surface, set_label_text, set_color} := horizon_api.widgets.label stn := @use("../../../libraries/stn/src/lib.hb"); .{Vec2} := stn.math @@ -29,6 +29,7 @@ main := fn(): int { mouse_y := 100 text_label := new_label("Hi\0") + set_color(text_label, sunset.server.DECO_COLOUR, render.black) loop { mouse_event := intouch.recieve_mouse_event() @@ -38,7 +39,7 @@ main := fn(): int { change_x = change_x >> 8 mouse_x += change_x - if mouse_x < 0 { + if mouse_x <= 0 { mouse_x = 0 } if mouse_x >= screen.width - 20 { @@ -49,13 +50,13 @@ main := fn(): int { change_y = change_y << 8 change_y = change_y >> 8 + mouse_y -= change_y if mouse_y < 0 { - mouse_y = 0 + mouse_y = 1 } if mouse_y >= screen.height - 20 { mouse_y = @intcast(screen.height - 21) } - mouse_y -= change_y if mouse_event.left { set_label_text(text_label, "LEFT CLICK\0")