From 5ee1ae6d175d441953ab5bf854527d251dcc1ebb Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 8 Sep 2025 07:52:08 +1000 Subject: [PATCH] added separators --- src/editor/ui.d | 6 ++++++ src/editor/widgets.d | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/editor/ui.d b/src/editor/ui.d index f7896c3..d89b967 100644 --- a/src/editor/ui.d +++ b/src/editor/ui.d @@ -282,6 +282,12 @@ PrevSiblingPanel(UIItem* panel) return result; } +UIItem* +PeekParent() +{ + return g_ui_ctx.top_parent == g_UI_NIL_NODE ? g_UI_NIL : g_ui_ctx.top_parent.item; +} + UIItem* PopParent() { diff --git a/src/editor/widgets.d b/src/editor/widgets.d index 33e75bb..2c7e1b1 100644 --- a/src/editor/widgets.d +++ b/src/editor/widgets.d @@ -1,6 +1,7 @@ import dlib; import ui; +import std.format : sformat; UIItem* Root() @@ -15,13 +16,34 @@ Root() UIItem* Panel(string id, f32 x_pct, f32 y_pct, Axis2D layout_axis, Vec4 color) { + UIItem* prev_panel = PeekSiblingPanel(); + UIItem* parent = PeekParent(); + + if (!Nil(prev_panel) && parent != prev_panel) + { + f32 sep_y = 1.0, sep_x = 1.0; + if (parent.layout_axis == A2D.X) + { + sep_x = 0.005; + //x_pct -= 0.005; + } + else + { + sep_y = 0.005; + //y_pct -= 0.005; + } + + u8[128] buf; + (cast(char[])buf).sformat("sep_%s", id); + + Separator(buf, sep_x, sep_y); + } + SetColor(color); SetLayoutAxis(layout_axis); UIItem* item = BuildItem(id, UISize(ST.Percentage, x_pct), UISize(ST.Percentage, y_pct), UIF.DrawBackground); - UIItem* prev_panel = PrevSiblingPanel(item); - - Logf("%s %s", id, !Nil(prev_panel)); + UIItem* sibling = PrevSiblingPanel(item); PushSiblingPanel(item); PushParent(item); @@ -29,6 +51,16 @@ Panel(string id, f32 x_pct, f32 y_pct, Axis2D layout_axis, Vec4 color) return item; } +UIItem* +Separator(u8[] id, f32 x_pct, f32 y_pct) +{ + SetColor(Vec4(0.0, 0.0, 0.0, 1.0)); + + UIItem* item = BuildItem(id, UISize(ST.Percentage, x_pct), UISize(ST.Percentage, y_pct), UIF.DrawBackground); + + return item; +} + void EndPanel() {