From 2ebbe3d911a2b5e38f3ed72b69e7d95881438423 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 15 Dec 2025 08:30:56 +1100 Subject: [PATCH] some changes --- src/editor/editor.d | 27 ++++++++++++++++++++++++ src/editor/ui.d | 50 +++++++++++++++++++++++++++++++-------------- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/editor/editor.d b/src/editor/editor.d index 7e21170..47e91a1 100644 --- a/src/editor/editor.d +++ b/src/editor/editor.d @@ -166,6 +166,33 @@ Cycle(EditorCtx* ctx, Inputs* inputs) Push!("bg_col", true)(ui_ctx, col1); UIItem* p1 = MakeItem("###p1", UIF.DrawBackground|UIF.Resizeable); + Push!("parent")(ui_ctx, p1); + + Vec4[4] c0 = Vec4(Vec3(0.2), 1.0); + Vec4[4] c1 = Vec4(Vec3(0.4), 1.0); + Vec4[4] c2 = Vec4(Vec3(0.6), 1.0); + Vec4[4] c3 = Vec4(Vec3(0.8), 1.0); + Vec4[4] c4 = Vec4(1.0); + + Push!("bg_col", true)(ui_ctx, c0); + Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.1)); + MakeItem("###c0", UIF.DrawBackground); + + Push!("bg_col", true)(ui_ctx, c1); + Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.13)); + MakeItem("###c1", UIF.DrawBackground); + + Push!("bg_col", true)(ui_ctx, c2); + Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.17)); + MakeItem("###c2", UIF.DrawBackground); + + Push!("bg_col", true)(ui_ctx, c3); + Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.25)); + MakeItem("###c3", UIF.DrawBackground); + + Push!("bg_col", true)(ui_ctx, c4); + Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.35)); + MakeItem("###c4", UIF.DrawBackground); /* UIPanel* root = ctx.base_panel; diff --git a/src/editor/ui.d b/src/editor/ui.d index f54bb4e..4cc52f1 100644 --- a/src/editor/ui.d +++ b/src/editor/ui.d @@ -53,7 +53,7 @@ const u8[] FRAGMENT_BYTES = import("gui.frag.spv"); f32 g_corner_radius_default = 2.0; f32 g_edge_softness_default = 0.1; -f32 g_border_thickness_default = 2.0; +f32 g_border_thickness_default = 0.0; Vec4[4] g_bg_col_default = BG_COL; Vec4[4] g_bg_hl_col_default = BG_HL_COL; Vec4[4] g_border_col_default = BORDER_COL; @@ -128,11 +128,12 @@ alias UIS = UISignal; enum UIEvent { - None = 0, - Click = 1<<0, - Drag = 1<<1, - DragStart = 1<<2, - Press = 1<<3, + None = 0, + Click = 1<<0, + DragRelease = 1<<1, + Drag = 1<<2, + DragStart = 1<<3, + Press = 1<<4, } alias UIE = UIEvent; @@ -268,7 +269,12 @@ mixin template UIItemParameters() enum info = CtxMemberInfo!(i); static if(info.is_stack) { - fields ~= typeof(UICtx.tupleof[i].top.value).stringof ~ " " ~ info.id ~ ";\n"; + fields ~= typeof(UICtx.tupleof[i].top.value).stringof ~ " " ~ info.id; + static if(is(typeof(UICtx.tupleof[i]): f32)) + { + fields ~= " = 0.0"; + } + fields ~= ";\n"; } } } @@ -598,6 +604,12 @@ Signal(UIItem* item) taken = true; } + if(ctx.drag_item == item && i.type == UIE.DragRelease) + { + ctx.drag_item = g_UI_NIL; + taken = true; + } + if(taken) { DLLRemove(&ctx.events, i, g_UI_NIL_INPUT); @@ -637,6 +649,10 @@ BeginUI(Inputs* inputs) { PushUIEvent(ctx, UIInput(UIE.Click)); } + else if(!mouse_down) + { + PushUIEvent(ctx, UIInput(UIE.DragRelease)); + } dragging = false; } break; case Input.MouseMotion: @@ -805,7 +821,6 @@ EndUI() // Violations for(UIItem* item = ctx.root; !Nil(item); item = Recurse!(true)(item, g_UI_NIL)) { - Logf("ccc %s", cast(char[])item.key.hash_text); f32 size = item.size[axis]; // InnerSize!(axis)(item); if(axis == item.layout_axis) @@ -816,7 +831,6 @@ EndUI() children_size += c.size.v[axis]; } - Logf("%s %s %s", cast(char[])item.key.hash_text, size, children_size); if(children_size > size) { f32 excess = children_size - size; @@ -839,7 +853,6 @@ EndUI() for(UIItem* c = item.last; !Nil(c); c = c.prev) { f32 reduced = Min(excess, c.size[axis]); - Logf("r %s", reduced); excess -= reduced; c.size.v[axis] -= reduced; @@ -849,7 +862,6 @@ EndUI() } } - Logf("%s %s", excess, cast(char[])item.key.hash_text); assert(excess < 0.0009); } } @@ -877,10 +889,6 @@ EndUI() f32 end_pos = pos + item.size.v[axis]; item.rect.p0.v[axis] = pos + padding; - if(axis == A2D.Y) - { - Logf("padding %s %s", pos, padding); - } item.rect.p1.v[axis] = end_pos; assert(!isNaN(item.rect.p0.v[axis])); @@ -929,6 +937,18 @@ EndUI() FinishRendering(&rd); SubmitAndPresent(&rd); } + + if(!Nil(ctx.drag_item)) + { + for(UIInput* i = ctx.events.first; !CheckNil(g_UI_NIL_INPUT, i); i = i.next) + { + if(i.type == UIE.DragRelease) + { + ctx.drag_item = g_UI_NIL; + break; + } + } + } } void