From f13c682171db2231bac645c612ab98dea4e8ef93 Mon Sep 17 00:00:00 2001 From: Able Date: Wed, 6 Nov 2024 20:11:36 -0600 Subject: [PATCH] refactor and widgeting magic --- sysdata/libraries/horizon_api/src/lib.hb | 2 +- .../src/{widgets.hb => widgets/label.hb} | 28 ++++--------------- .../horizon_api/src/widgets/widget_types.hb | 4 +++ .../horizon_api/src/widgets/widgets.hb | 28 +++++++++++++++++++ sysdata/programs/horizon/src/main.hb | 2 +- 5 files changed, 39 insertions(+), 25 deletions(-) rename sysdata/libraries/horizon_api/src/{widgets.hb => widgets/label.hb} (64%) create mode 100644 sysdata/libraries/horizon_api/src/widgets/widget_types.hb create mode 100644 sysdata/libraries/horizon_api/src/widgets/widgets.hb diff --git a/sysdata/libraries/horizon_api/src/lib.hb b/sysdata/libraries/horizon_api/src/lib.hb index 72f58d10b..112bbac3a 100644 --- a/sysdata/libraries/horizon_api/src/lib.hb +++ b/sysdata/libraries/horizon_api/src/lib.hb @@ -5,7 +5,7 @@ render := @use("../../../libraries/render/src/lib.hb") input := @use("../../intouch/src/lib.hb") -widgets := @use("widgets.hb") +widgets := @use("widgets/widgets.hb") ui := @use("ui.hb") WindowID := struct { diff --git a/sysdata/libraries/horizon_api/src/widgets.hb b/sysdata/libraries/horizon_api/src/widgets/label.hb similarity index 64% rename from sysdata/libraries/horizon_api/src/widgets.hb rename to sysdata/libraries/horizon_api/src/widgets/label.hb index 1fa04b547..3a44b3972 100644 --- a/sysdata/libraries/horizon_api/src/widgets.hb +++ b/sysdata/libraries/horizon_api/src/widgets/label.hb @@ -1,25 +1,13 @@ -// Widget types - -// End types -stn := @use("../../../libraries/stn/src/lib.hb"); +stn := @use("../../../../libraries/stn/src/lib.hb"); .{string, log} := stn; .{Vec2} := stn.math -render := @use("../../../libraries/render/src/lib.hb"); +render := @use("../../../../libraries/render/src/lib.hb"); .{Surface} := render; .{Font} := render.text -LayoutChildHorizontalFirst := 0 -LayoutChildVerticalFirst := 1 - -Size := struct { - min_width: int, - max_width: int, - min_height: int, - max_height: int, -} - Label := struct { + magic: uint, is_dirty: bool, surface: Surface, text: ^u8, @@ -45,13 +33,7 @@ render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: V new_label := fn(text: ^u8): Label { text_surface := render.new_surface(1000, 20) text_length := string.length(text) - label := Label.(true, text_surface, text, text_length) + widget_type := 3 + label := Label.(widget_type, true, text_surface, text, text_length) return label -} - -VerticalLayout := 0 -HorizontalLayout := 1 - -Container := struct { - layout: uint, } \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/src/widgets/widget_types.hb b/sysdata/libraries/horizon_api/src/widgets/widget_types.hb new file mode 100644 index 000000000..9755ec8bf --- /dev/null +++ b/sysdata/libraries/horizon_api/src/widgets/widget_types.hb @@ -0,0 +1,4 @@ +VerticalWidgetType := 1 +HorizontalWidgetType := 2 + +LabelWidgetType := 3 \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/src/widgets/widgets.hb b/sysdata/libraries/horizon_api/src/widgets/widgets.hb new file mode 100644 index 000000000..c9aca72a5 --- /dev/null +++ b/sysdata/libraries/horizon_api/src/widgets/widgets.hb @@ -0,0 +1,28 @@ +// Widget types + +// End types +stn := @use("../../../../libraries/stn/src/lib.hb"); +.{string, log} := stn; +.{Vec2} := stn.math + +render := @use("../../../../libraries/render/src/lib.hb"); +.{Surface} := render; +.{Font} := render.text + +widget_types := @use("widget_types.hb") +label := @use("label.hb") +// .{Label, render_label_to_surface, set_label_text} := label + +Size := struct { + min_width: int, + max_width: int, + min_height: int, + max_height: int, +} + +Vertical := packed struct { + magic: uint, + // array of children, idk + // use a vec or linked list or whatever + children: ^^u8, +} \ No newline at end of file diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index ed405bbdc..cf9a000e4 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -3,7 +3,7 @@ stn := @use("../../../libraries/stn/src/lib.hb"); .{Vec2} := stn.math horizon_api := @use("../../../libraries/horizon_api/src/lib.hb"); -.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets; +.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label; .{sexpr_parser, render_ui} := horizon_api.ui render := @use("../../../libraries/render/src/lib.hb");