From 49501a32aa10f57177ed40ef06c2433b17366467 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 19 Dec 2025 13:20:22 +1100 Subject: [PATCH] base ui layout code working --- dub.json | 6 +++--- src/dlib | 2 +- src/editor/editor.d | 18 ++++++++++-------- src/editor/ui.d | 23 ++++++++++++----------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/dub.json b/dub.json index f4bcecf..5c7d5d6 100644 --- a/dub.json +++ b/dub.json @@ -7,16 +7,16 @@ "targetType": "executable", "targetName": "Editor", "targetPath": "build", - "sourceFiles-linux": ["build/libvma.a", "build/libstb.a", "build/libm3d.a", "build/libcglm.a"], + "sourceFiles-linux": ["build/libvma.a", "build/libstb.a", "build/libm3d.a"], "sourceFiles-windows": [], "importPaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"], "sourcePaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"], "libs-linux": ["X11", "vulkan", "stdc++", "xfixes", "freetype"], "libs-windows": [], - "versions": ["VULKAN_DEBUG", "ENABLE_RENDERER"], + "versions": ["VULKAN_DEBUG", "ENABLE_RENDERER", "NO_STBI"], "preGenerateCommands-linux": ["./build.sh"], "preGenerateCommands-windows": [], - "dflags": ["-P-I/usr/include/freetype2", "-Jbuild", "-Jassets"], + "dflags": ["-P-I/usr/include/freetype2", "-Jbuild", "-Jassets", "-Xcc=-DNO_STBI"], "dflags-ldc2": ["-link-debuglib"], "dflags-dmd": [] }, diff --git a/src/dlib b/src/dlib index 617e03f..7f4c109 160000 --- a/src/dlib +++ b/src/dlib @@ -1 +1 @@ -Subproject commit 617e03f917911f6f9898086720a6539756f79758 +Subproject commit 7f4c109106eaabda180158a8f7a92c9d2e60d3db diff --git a/src/editor/editor.d b/src/editor/editor.d index 47e91a1..91e2502 100644 --- a/src/editor/editor.d +++ b/src/editor/editor.d @@ -143,26 +143,27 @@ Cycle(EditorCtx* ctx, Inputs* inputs) UICtx* ui_ctx = GetCtx(); - Vec4[4] col0 = Vec4(0.2, 0.4, 0.8, 1.0); - Vec4[4] col1 = Vec4(0.8, 0.4, 0.2, 1.0); - Vec4[4] col_sep = Vec4(0.2, 0.8, 0.1, 1.0); + Vec4[4] col0 = Vec4(0.2, 0.4, 0.8, 1.0); + Vec4[4] col1 = Vec4(0.8, 0.4, 0.2, 1.0); + Vec4[4] black = Vec4(0.0, 0.0, 0.0, 1.0); + Vec4[4] green = Vec4(0.2, 0.8, 0.1, 1.0); + Push!("border_thickness", true)(ui_ctx, 10.0f); Push!("size_info")(ui_ctx, MakeUISizeX(ST.Percentage, 0.5)); - Push!("bg_col", true)(ui_ctx, col0); - UIItem* p0 = MakeItem("###p0", UIF.DrawBackground|UIF.Resizeable); + UIItem* p0 = MakeItem("###p0", UIF.DrawBackground|UIF.Resizeable|UIF.DrawBorder); Push!("size_info", true)(ui_ctx, MakeUISize(UISize(ST.Pixels, 200.0), UISize(ST.Pixels, 80.0))); Push!("parent", true)(ui_ctx, p0); - Push!("bg_col", true)(ui_ctx, col_sep); + Push!("bg_col", true)(ui_ctx, green); Push!("padding", true)(ui_ctx, Vec2(4.0)); UIItem* text = MakeItem("Haha##text", UIF.DrawBackground|UIF.DrawText); Push!("size_info", true)(ui_ctx, MakeUISizeX(ST.Pixels, 2.0)); - Push!("bg_col", true)(ui_ctx, col_sep); + Push!("bg_col", true)(ui_ctx, black); UIItem* sep = MakeItem("###sep", UIF.Draggable|UIF.DrawBackground|UIF.ResizeAdjacent); - + Push!("layout_axis", true)(ui_ctx, A2D.Y); Push!("bg_col", true)(ui_ctx, col1); UIItem* p1 = MakeItem("###p1", UIF.DrawBackground|UIF.Resizeable); @@ -193,6 +194,7 @@ Cycle(EditorCtx* ctx, Inputs* inputs) 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 4cc52f1..ec6af2a 100644 --- a/src/editor/ui.d +++ b/src/editor/ui.d @@ -562,6 +562,8 @@ MakeItem(T)(T k, UIFlags flags = UIF.None) if(is(T: UIKey) || StringType!T) item.last_frame = ctx.frame; + item.padding += item.border_thickness; + return item; } @@ -780,7 +782,7 @@ EndUI() { if(item.size_info[axis].type == ST.Pixels) { - item.size.v[axis] = item.size_info[axis].value + item.padding.v[axis]; + item.size.v[axis] = item.size_info[axis].value; } } @@ -789,7 +791,7 @@ EndUI() { if(item.size_info[axis].type == ST.Percentage) { - if(item.layout_axis == axis && item.flags & UIF.Resizeable) + if(item.parent.layout_axis == axis && item.flags & UIF.Resizeable) { item.size_info[axis].value = item.resize_pct; } @@ -821,7 +823,7 @@ EndUI() // Violations for(UIItem* item = ctx.root; !Nil(item); item = Recurse!(true)(item, g_UI_NIL)) { - f32 size = item.size[axis]; // InnerSize!(axis)(item); + f32 size = InnerSize!(axis)(item); if(axis == item.layout_axis) { @@ -883,12 +885,11 @@ EndUI() f32 pos = 0.0; for(UIItem* item = ctx.root; !Nil(item);) { - // This padding idea is FUCKED - f32 padding = !Nil(item.parent) ? item.parent.border_thickness : 0.0; + f32 inner_pos = pos + item.parent.padding.v[axis]; f32 next_pos = 0.0; - f32 end_pos = pos + item.size.v[axis]; + f32 end_pos = inner_pos + item.size.v[axis]; - item.rect.p0.v[axis] = pos + padding; + item.rect.p0.v[axis] = inner_pos; item.rect.p1.v[axis] = end_pos; assert(!isNaN(item.rect.p0.v[axis])); @@ -910,7 +911,7 @@ EndUI() if(!Nil(p.next)) { item = p.next; - pos = item.parent.layout_axis == axis ? item.prev.rect.p1.v[axis] : item.prev.rect.p0.v[axis]; + pos = item.parent.layout_axis == axis ? item.prev.rect.p1.v[axis] : item.parent.rect.p0.v[axis]; break; } @@ -961,8 +962,8 @@ RenderItems(UIItem* root) { // DrawRect Vertex* v = GetVertex(ctx); - v.dst_start = item.rect.p0 + item.border_thickness; - v.dst_end = item.rect.p1 - item.border_thickness; + v.dst_start = item.rect.p0; // - item.border_thickness; + v.dst_end = item.rect.p1; // + item.border_thickness; v.cols = item.bg_col; v.corner_radius = item.corner_radius; @@ -1416,7 +1417,7 @@ DrawGlyph(UIItem* item, Glyph* glyph, f32* x_pos, f32 y) pragma(inline) f32 InnerSize(Axis2D axis)(UIItem* item) { - return clamp(item.size[axis] - item.border_thickness*2.0, 0.0, f32.max); + return clamp(item.size[axis] - item.padding.v[axis]*2.0, 0.0, f32.max); } pragma(inline) Vertex*