From f89a0094cf12ef5cf16eef99f08e6063c46adfe1 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 11 Jan 2026 15:37:32 +1100 Subject: [PATCH] update before refactoring all the code (again) --- assets/gui.frag.spv | Bin 7376 -> 7316 bytes assets/gui.vert.spv | Bin 9520 -> 9228 bytes src/VulkanRenderer | 2 +- src/editor/ui.d | 210 ++++++++++++++++++++++++++++---------- src/shaders/gui.layout | 1 - src/shaders/gui.vert.glsl | 24 ++--- 6 files changed, 167 insertions(+), 70 deletions(-) diff --git a/assets/gui.frag.spv b/assets/gui.frag.spv index bd666ad8d604f5a2668a4a601bfc72d6240c8f85..fb062574cfef1257a0c7021789fd6a8c9a74404b 100644 GIT binary patch delta 1104 zcmYjPO=uHA7@bLWlWen_W)rp{S)@WK8fq!27A&O-UPJ^fEh0ss6jMd8Sd2e-N`rV1 z^ial|6ckTAc#s9btF}}R6)T8XTC^JIrHDc4L9F$?Ww&JDvETQ-x8J<^X5RNd?6;zk zj=0dJND521GuAnMMF>%UKKU{(zk2%;?;cDssG2czQd4uLyGI9KDPJ6`j89Honeb&$#eH2&t(&flt8FvqB%r%Cez`JH zX77a08>(n+$Q5O$a_B)KLE&-zY#mdFJ(?b^y~b z5Er~sc1OxhRdRCGA1G`B=YgR>@DuTc0JWgjKu#?=6Qg0HUjR4T50Edwh3OAQh~EKs z3}5Q*pbyP&0p!>}f%7gpMY*LKjw>_DYU`01Z?NrTr1}RmTWi35fWLFgzW}*=Kxp?L z;#&biyF19KB^TP2uov1T-)uJ$aI_0uYS*s@BBGr9K|GZc`5x(bxARfi{TjMMzzbjy zF6nI^VErt-a{ddzD_~yD6N3y_<3i}hM$Gz>nswXrtBCk+P6t=HhM2Wg z_0jF9CZJ`d2!t1Ephh1p0QqpQ7Q~&Xkq@=WCN25UC!aW1`0p3Qe9hDk!3lk?3o$B4 jG=tYl@*BW|K(yO*7%|ro*yB^DCfsm@1lBgjbQt&#mSmi| delta 1142 zcmZ8fO-NKx6ux(6-u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SWehoLw< z7=1hBdq55t0J<?}C+Keh4=5#1G?e5nK&OqL z?lVrzG<4eg0JGPN(AkF%n|;Wq0n=w2bROQ5Z}T^R5109uA+G?JfEIxHKdQ@b|bbJqbHJ2W3i6rH#hMQtL-GwxHG2e%dH8Xel9j&fE70JaTsKIrq-J zGk0b<*m3v?m!VhWYYwHY)LdHen5#*7$F{eu{#etr?}1Ceb>Jp2KQ`W}_KaP7%^mI= z4DU-O>cTMMiPV5hEC0Q*DCsgio*e9Hl%b+BV^cINZ>t)k7UQIX@dp^gJ|X6@k%58MJ{;L#B3ETTJ5;hxMd)rvi<>b90XBgAaf|24 z@zPL)r$@ElQXLk5%i_Asm986QBbb9n$Y|bLayFZsH<&!%j$&)__~AS&^`F*dA?=4sbpusB6dCg&MY<7#hU zWFk8``Atis{}0%V%_Yp!{)Ekig@JPT?_lJ{wgN#cfoB%7v^%?CFo22fVq_u)a3SRL zmd36yiHj@IwB`+HE{m)Jr$!VYhVFMvGUa~RQQj}>18zB6zFTdQXrNuy%21$PrUHd>DzHY?%XFYx zPLvmjJ6I;q2HjE@tdxTo_XaD~!*VECs~TkjzguNCSgkfoB;=Qap#o_Qb*N@J6iTQT znF%%5Z{xo3HDMQQ&oO|PvIRRmit#w`5l{&{fz<2R2z!mTTu?G2hnThzTF2Lfe zup@tf%}Bl+Mv`BU*xKA`nCmBi5qvw0Ab(WG*Lp`;c?#gGvGYyCW;9X)4FT?&2*a^IBX}`g~43q({SlSiX)Oq)OBmw}Kz#>d*n+=-UVxvi%}T7oGx`q{ zdS`)cKnXC0S-h(M0?fo1d%aJ==4WSFfXz65w)P)vYIuW-ngXGw16}x!$^5#~IyENX g1O~7;x5am1fb+jZ4B*DeF=25bUC{Y0pv)HFe|h?g=>Px# diff --git a/src/VulkanRenderer b/src/VulkanRenderer index c2b7544..3390ee9 160000 --- a/src/VulkanRenderer +++ b/src/VulkanRenderer @@ -1 +1 @@ -Subproject commit c2b7544979b16e1f27f419475b866a2903bd9c0a +Subproject commit 3390ee9742fbce758941a0dd216ebec5c75876e5 diff --git a/src/editor/ui.d b/src/editor/ui.d index 66ed5ee..5b36c80 100644 --- a/src/editor/ui.d +++ b/src/editor/ui.d @@ -332,6 +332,20 @@ struct UICtx debug u64 item_count; } +struct ItemStyle +{ + Vec4 bg_col; + Vec4 bg_hl_col; + Vec4 border_col; + Vec4 border_hl_col; + Vec4 text_col; + Vec4 text_hl_col; + Vec2[2] padding; + Vec4 corner_radius; + f32 border_thickness; + f32 edge_softness; +} + enum UIElement { Default, @@ -353,20 +367,31 @@ enum UIElement StatusMessage, Max, } - alias UIElem = UIElement; -struct ItemStyle +enum Element { - Vec4 bg_col; - Vec4 bg_col_end; - Vec4 bg_hl_col; - Vec4 border_col; - Vec4 border_hl_col; - Vec4 text_col; - Vec4 text_hl_col; - Vec2[2] padding; + Panel, + PanelFocus, + Window, + WindowFocus, + Border, + BorderFocus, + Text, + Button, + ButtonAlt, // Alternating option colours + ButtonFocus, + Max, +} alias Elem = Element; + +struct UIStyle +{ + enum N = Elem.max; + + Vec4[N] cols; Vec4 corner_radius; + Vec2[2] text_box_padding; + Vec2[2] button_padding; f32 border_thickness; f32 edge_softness; } @@ -376,7 +401,6 @@ DefaultItemStyle() { ItemStyle style = { bg_col: BG_COL, - bg_col_end: BG_COL, bg_hl_col: BG_HL_COL, border_col: BORDER_COL, border_hl_col: BORDER_HL_COL, @@ -480,6 +504,8 @@ enum SizeType Percentage, ChildrenSum, TextSize, + Pct = ST.Percentage, + Px = ST.Pixels, } alias ST = SizeType; @@ -488,7 +514,6 @@ struct UISize { SizeType type; f32 value; - f32 strictness = 1.0; } struct UIBuffer @@ -510,7 +535,6 @@ struct VPos struct Vertex { Vec4 cols; - Vec4 cols_end; Vec4 corner_radius; union { @@ -537,18 +561,17 @@ enum SettingType Toggle, } -Attribute[11] attributes = [ - { binding: 0, location: 0, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof }, - { binding: 0, location: 1, format: FMT.RGBA_F32, offset: Vertex.cols_end.offsetof }, - { binding: 0, location: 2, format: FMT.RGBA_F32, offset: Vertex.corner_radius.offsetof }, - { binding: 0, location: 3, format: FMT.RG_F32, offset: Vertex.dst_start.offsetof }, - { binding: 0, location: 4, format: FMT.RG_F32, offset: Vertex.dst_end.offsetof }, - { binding: 0, location: 5, format: FMT.RG_F32, offset: Vertex.src_start.offsetof }, - { binding: 0, location: 6, format: FMT.RG_F32, offset: Vertex.src_end.offsetof }, - { binding: 0, location: 7, format: FMT.R_F32, offset: Vertex.border_thickness.offsetof }, - { binding: 0, location: 8, format: FMT.R_F32, offset: Vertex.edge_softness.offsetof }, - { binding: 0, location: 9, format: FMT.R_F32, offset: Vertex.raised.offsetof }, - { binding: 0, location: 10, format: FMT.R_U32, offset: Vertex.has_texture.offsetof }, +Attribute[10] attributes = [ + { binding: 0, location: 0, format: FMT.RGBA_F32, offset: Vertex.cols.offsetof }, + { binding: 0, location: 1, format: FMT.RGBA_F32, offset: Vertex.corner_radius.offsetof }, + { binding: 0, location: 2, format: FMT.RG_F32, offset: Vertex.dst_start.offsetof }, + { binding: 0, location: 3, format: FMT.RG_F32, offset: Vertex.dst_end.offsetof }, + { binding: 0, location: 4, format: FMT.RG_F32, offset: Vertex.src_start.offsetof }, + { binding: 0, location: 5, format: FMT.RG_F32, offset: Vertex.src_end.offsetof }, + { binding: 0, location: 6, format: FMT.R_F32, offset: Vertex.border_thickness.offsetof }, + { binding: 0, location: 7, format: FMT.R_F32, offset: Vertex.edge_softness.offsetof }, + { binding: 0, location: 8, format: FMT.R_F32, offset: Vertex.raised.offsetof }, + { binding: 0, location: 9, format: FMT.R_U32, offset: Vertex.has_texture.offsetof }, ]; union Rect @@ -568,7 +591,103 @@ struct UIKey } enum bool KeyType(T) = (StringType!(T) || is(T == UIKey) || is(T == const(UIKey))); -enum bool ItemAndKeyType(T) = (KeyType!(T) || is(T == UIItem*)); +enum bool ItemAndKeyType(T) = (KeyType!(T) || is(T == UIItem*)); + +// ****** +// Public +// ****** + +void +BeginContainer(ST x_t = ST.Pct, ST y_t = ST.Pct)(Axis2D axis, f32 w, f32 h) +{ + PushSizeInfo(UIS2(x_t, y_t, w, h)); + PushAxisLayout(axis); + UIItem* item = MakeItem(ZeroKey()); + PushParent(item); +} + +alias EndContainer = Pop!("parent"); + +enum WindowFlags +{ + None = 0<<0, + NoBorder = 1<<0, + NoBackground = 1<<1, + NoDropShadow = 1<<2, + Draggable = 1<<3, + NoTitleBar = 1<<4, +} alias WinF = WindowFlags; + +UIFlags +GetFlags(WinF flags)() +{ + UIFlags flags = UIF.DrawBackground|UIF.DrawBorder|UIF.DrawDropShadow|UIF.AnimateReady|UIF.Window; + static if(flags & WinF.NoBorder) + { + flags &= ~UIF.DrawBorder; + } + static if(flags & WinF.NoBackground) + { + flags &= ~UIF.DrawBackground; + } + static if(flags & WinF.NoDropShadow) + { + flags &= ~UIF.DrawDropShadow; + } + static if(flags & WinF.Draggable) + { + flags &= ~UIF.Window; + flags |= UIF.FloatingWindow; + } + + return flags; +} + +// Converts to parameters (string label, Args args, Axis2D axis, f32 x, f32 y, f32 w, f32 h) +void +BeginWindow(WinF flags = WinF.None, ST x_t = ST.Px, ST x_y = ST.Px, Args...)(string label, Args args) +{ + enum len = Args.length; + + static assert(is(typeof(Args[len-1]) == f32)); + static assert(is(typeof(Args[len-2]) == f32)); + static assert(is(typeof(Args[len-3]) == f32)); + static assert(is(typeof(Args[len-4]) == f32)); + static assert(is(typeof(Args[len-5]) == Axis2D)); + + string scratch = Scratchf!(Args[0 .. len-5])(label, args[0 .. len-5]); + + BeginWindow!(flags, x_t, x_y)(scratch, args[len-5], args[len-4], args[len-3], args[len-2], args[len-1]); +} + +void +BeginWindow(WinF flags = WinF.None, ST x_t = ST.Px, ST x_y = ST.Px)(string label, Axis2D axis, f32 x, f32 y, f32 w, f32 h) +{ + PushFixedPos(Vec2(x, y)); + PushSizeInfo(UIS2(x_t, y_t, w, h)); + PushAxisLayout(axis); + UIFlags flags = GetFlags!(flags); + + static assert((flags & WinF.Draggable) == 0 || (flags & ~WinF.NoTitleBar) == flags, "Unable to use NoTitleBar flag with the Draggable flag"); + + UIItem* window = MakeItem("###window_%s", label, flags); + + static if(flags & WinF.Draggable) + { + //UIItem* header + } +} + +void +EndWindow() +{ + UIItem* window = Pop!("parent"); + +} + +// ******** +// Internal +// ******** void InitUICtx(PlatformWindow* window) @@ -1382,6 +1501,8 @@ EndUI() BeginRendering(&ctx.rd); + SetStencilTest(&ctx.rd, false); + Vec2 ext = GetExtent(); if(ext != ctx.res) { @@ -1521,22 +1642,6 @@ EndUI() if(children_size > size) { f32 excess = children_size - size; - for(UIItem* c = item.last; !Nil(c); c = c.prev) - { - if(c.flags & (UIF.FixedPosition | (UIF.OverflowX< 0.0009) { for(UIItem* c = item.last; !Nil(c); c = c.prev) @@ -1816,7 +1921,6 @@ RenderItem(UICtx* ctx, UIItem* item) v.dst_start = border_p0 - Vec2(px); v.dst_end = border_p1 + Vec2(px); v.cols = Vec4(0.0, 0.0, 0.0, alpha); - v.cols_end = Vec4(0.0, 0.0, 0.0, alpha); v.corner_radius = 0.8f; v.edge_softness = 8.0f; @@ -1826,15 +1930,13 @@ RenderItem(UICtx* ctx, UIItem* item) if(item.flags & UIF.DrawBackground) { Vec4 bg_col = style.bg_col; - Vec4 bg_col_end = style.bg_col_end; - AnimateHot(item, BG_HL_COL, &bg_col, &bg_col_end); - AnimateReady(item, &bg_col, &bg_col_end); + AnimateHot(item, BG_HL_COL, &bg_col); + AnimateReady(item, &bg_col); Vertex* v = GetVertex(ctx); v.dst_start = item.rect.p0; v.dst_end = item.rect.p1; v.cols = bg_col; - v.cols_end = item.flags & UIF.Gradient ? bg_col_end : bg_col; v.corner_radius = item.flags & UIF.DrawBorder ? style.corner_radius*0.5 : style.corner_radius; v.edge_softness = style.edge_softness; @@ -1851,7 +1953,6 @@ RenderItem(UICtx* ctx, UIItem* item) v.dst_start = border_p0; v.dst_end = border_p1; v.cols = style.border_col; - v.cols_end = style.border_col; v.corner_radius = style.corner_radius; v.border_thickness = style.border_thickness; v.edge_softness = style.edge_softness; @@ -2509,7 +2610,6 @@ DrawGlyph(UIItem* item, Glyph* glyph, f32* x_pos, f32 y, f32 line_height, Vec4 c v.dst_start = Vec2(*x_pos+glyph.plane_left, y_pos); v.dst_end = Vec2(*x_pos+glyph.plane_left+w, y_pos+h); v.cols = col; - v.cols_end = col; v.src_start = Vec2(glyph.atlas_left, glyph.atlas_top); v.src_end = Vec2(glyph.atlas_right, glyph.atlas_bottom); v.has_texture = true; @@ -2579,21 +2679,21 @@ GetVertex(UICtx* ctx) } static UISize[2] -UIS2(SizeType t0 = ST.Percentage, SizeType t1 = ST.Percentage, f32 v0 = 1.0, f32 v1 = 1.0, f32 s0 = 1.0, f32 s1 = 1.0) +UIS2(SizeType t0 = ST.Percentage, SizeType t1 = ST.Percentage, f32 v0 = 1.0, f32 v1 = 1.0) { - return [UISize(t0, v0, s0), UISize(t1, v1, s1)]; + return [UISize(t0, v0), UISize(t1, v1)]; } static UISize[2] -UISX(SizeType type, f32 value = 1.0, f32 strictness = 1.0) +UISX(SizeType type, f32 value = 1.0) { - return [UISize(type, value, strictness), UISize(ST.Percentage, 1.0)]; + return [UISize(type, value), UISize(ST.Percentage, 1.0)]; } static UISize[2] -UISY(SizeType type, f32 value = 1.0, f32 strictness = 1.0) +UISY(SizeType type, f32 value = 1.0) { - return [UISize(ST.Percentage, 1.0), UISize(type, value, strictness)]; + return [UISize(ST.Percentage, 1.0), UISize(type, value)]; } bool diff --git a/src/shaders/gui.layout b/src/shaders/gui.layout index 6e464eb..1691df7 100644 --- a/src/shaders/gui.layout +++ b/src/shaders/gui.layout @@ -29,7 +29,6 @@ layout (location = 0) FragDataFlat layout (location = 1) FragData { vec4 color; - vec4 color_end; vec2 uv; vec2 dst_pos; vec2 dst_center; diff --git a/src/shaders/gui.vert.glsl b/src/shaders/gui.vert.glsl index 9911138..87f37ab 100644 --- a/src/shaders/gui.vert.glsl +++ b/src/shaders/gui.vert.glsl @@ -6,17 +6,16 @@ #include "gui.layout" -layout (location = 0) in vec4 in_col_start; -layout (location = 1) in vec4 in_col_end; -layout (location = 2) in vec4 in_corner_radius; -layout (location = 3) in vec2 in_dst_start; -layout (location = 4) in vec2 in_dst_end; -layout (location = 5) in vec2 in_src_start; -layout (location = 6) in vec2 in_src_end; -layout (location = 7) in float border_thickness; -layout (location = 8) in float edge_softness; -layout (location = 9) in float raised; -layout (location = 10) in uint has_texture; +layout (location = 0) in vec4 in_col; +layout (location = 1) in vec4 in_corner_radius; +layout (location = 2) in vec2 in_dst_start; +layout (location = 3) in vec2 in_dst_end; +layout (location = 4) in vec2 in_src_start; +layout (location = 5) in vec2 in_src_end; +layout (location = 6) in float border_thickness; +layout (location = 7) in float edge_softness; +layout (location = 8) in float raised; +layout (location = 9) in uint has_texture; vec2 Vertices[4] = vec2[4]( vec2(-1.0, -1.0), @@ -62,8 +61,7 @@ void main() vec2 dst_verts_pct = vec2(bool(gl_VertexIndex >> 1) ? 1.0f : 0.0f, bool(gl_VertexIndex & 1) ? 0.0f : 1.0f); - FD.color = in_col_start; - FD.color_end = in_col_end; + FD.color = in_col; FD.uv = uvs[gl_VertexIndex] / tex_size; FD.dst_pos = pos; FD.dst_center = center;