From f15eda312af2138ca6b0f552da602ed91008f939 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 22 Sep 2025 07:47:36 +1000 Subject: [PATCH] z-index still broken, disable horizontal splits for now --- src/editor/editor.d | 4 +- src/editor/ui.d | 145 +++++++++++++++++++++++++++++++------------ src/editor/widgets.d | 11 ---- 3 files changed, 106 insertions(+), 54 deletions(-) diff --git a/src/editor/editor.d b/src/editor/editor.d index fc09c4d..c12935c 100644 --- a/src/editor/editor.d +++ b/src/editor/editor.d @@ -269,8 +269,8 @@ HandleInputs(EditorCtx* ctx, Inputs* inputs) } break; case Input.c: { - AddEditor(ctx, GetFocusedPanel(), A2D.Y); - taken = true; + //AddEditor(ctx, GetFocusedPanel(), A2D.Y); + //taken = true; } break; case Input.d: { diff --git a/src/editor/ui.d b/src/editor/ui.d index 8ccdbd1..6a76b9c 100644 --- a/src/editor/ui.d +++ b/src/editor/ui.d @@ -646,6 +646,7 @@ EndBuild() { CalcPositions!(axis)(ctx.root); } + FixViolations(ctx.root); PrepRendering(ctx); DrawUI(ctx, ctx.root); @@ -669,7 +670,7 @@ EndBuild() static u32 prev_count = 0; if(prev_count != ctx.item_count) { - //PrintNodes(ctx.root); + PrintNodes(ctx.root); prev_count = ctx.item_count; } } @@ -710,13 +711,41 @@ PrintNodes(UIItem* item) { if(!Nil(item)) { - Logf("x0 %s x1 %s y0 %s y1 %s", item.rect.x0, item.rect.x1, item.rect.y0, item.rect.y1); + if(item.culling.vec0 != Vec2(0.0) || item.culling.vec1 != Vec2(0.0)) + { + Logf("%s:", cast(char[])item.key.text); + Logf("x0 %s x1 %s y0 %s y1 %s", item.rect.x0, item.rect.x1, item.rect.y0, item.rect.y1); + Logf("cull x0 %s x1 %s y0 %s y1 %s\n", item.culling.x0, item.culling.x1, item.culling.y0, item.culling.y1); + } PrintNodes(item.first); PrintNodes(item.next); } } +void +FixViolations(UIItem* item) +{ + A2D axis = A2D.Y; + for(UIItem* i = item; !Nil(i); i = Recurse(i)) + { + if(!Nil(i.parent)) + { + f32 bounds_start = i.parent.rect.vec0.v[axis] - i.parent.culling.vec0.v[axis]; + if(i.rect.vec0.v[axis] < bounds_start) + { + i.culling.vec0.v[axis] = bounds_start - i.rect.vec0.v[axis]; + } + + f32 bounds_end = i.parent.rect.vec1.v[axis] - i.parent.culling.vec1.v[axis]; + if(i.rect.vec1.v[axis] > bounds_end) + { + i.culling.vec1.v[axis] = i.rect.vec1.v[axis] - bounds_end; + } + } + } +} + void CalcFixedSizes(UIItem* item) { @@ -1254,67 +1283,101 @@ DrawGlyph(UIItem* item, Glyph* glyph, f32 scale, f32* x_pos, f32 y, bool highlig { UICtx* ctx = GetCtx(); Vertex* bg_v = null, v = null; - f32 h; if(glyph.ch == '\t') { *x_pos += glyph.advance * (GetCtx().tab_width - 1); } - - v = ctx.buffers[ctx.f_idx].vtx.ptr + ctx.buffers[ctx.f_idx].count; - f32 r = glyph.plane_right * scale; - f32 l = glyph.plane_left * scale; + f32 r = glyph.plane_right * scale; + f32 l = glyph.plane_left * scale; + f32 t = glyph.plane_top * scale; + f32 b = glyph.plane_bottom * scale; f32 w = r - l; - h = (glyph.plane_bottom - glyph.plane_top) * scale; - f32 y_pos = glyph.plane_top * scale; + f32 h = b - t; - v.dst_start.x = *x_pos + l; - v.dst_start.y = y - y_pos; - v.dst_end.x = *x_pos + w + l; - v.dst_end.y = y + h - y_pos; + f32 atlas_r = glyph.atlas_right; + f32 atlas_l = glyph.atlas_left; + f32 atlas_t = glyph.atlas_top; + f32 atlas_b = glyph.atlas_bottom; - v.z_index = item.z_index; - - if(glyph.ch != '\t' && glyph.ch != '\n') + bool skip = false; + if(item.culling.x0 != 0.0 || item.culling.x1 != 0.0) { - v.src_start.x = glyph.atlas_left; - v.src_start.y = glyph.atlas_top; - v.src_end.x = glyph.atlas_right; - v.src_end.y = glyph.atlas_bottom; - } - - /* - static foreach(axis; A2D.min .. A2D.max) - { - if(item.culling.vec0.v[axis] != 0.0 || item.culling.vec1.v[axis] != 0.0) + if(w <= item.culling.x0+item.culling.x1) { - f32 length = v.dst_end.v[axis] - v.dst_start.v[axis]; - f32 start_pct = 1.0-((length-item.culling.vec0.v[axis])/length); - f32 end_pct = 1.0-((length-item.culling.vec1.v[axis])/length); + skip = true; + } + else + { + f32 start_pct = 1.0-((w-item.culling.x0)/w); + f32 end_pct = 1.0-((w-item.culling.x1)/w); - f32 atlas_len = v.src_end.v[axis] - v.src_start.v[axis]; - v.src_start.v[axis] -= atlas_len * start_pct; - v.src_end.v[axis] -= atlas_len * end_pct; + f32 atlas_len = atlas_r - atlas_l; + atlas_l += atlas_len * start_pct; + atlas_r -= atlas_len * end_pct; - v.dst_start.v[axis] -= item.culling.vec0.v[axis]; - v.dst_end.v[axis] -= item.culling.vec1.v[axis]; + l += item.culling.x0; + r -= item.culling.x1; - Logf("culling %s %s %s %s start_pct %s end_pct %s", length, item.culling.vec0.v[axis], item.culling.vec1.v[axis], axis, start_pct, end_pct); + w = r-l; } } - */ - if(highlight) + if(!skip && (item.culling.y0 != 0.0 || item.culling.y1 != 0.0)) { - col = Vec4(Vec3(1.0)-col.xyz, 1.0); + if(h <= item.culling.y0+item.culling.y1) + { + skip = true; + } + else + { + f32 start_pct = 1.0-((h-item.culling.y0)/h); + f32 end_pct = 1.0-((h-item.culling.y1)/h); + + f32 atlas_len = atlas_b-atlas_t; + atlas_t += atlas_len * start_pct; + atlas_b -= atlas_len * end_pct; + + t += item.culling.y0; + b -= item.culling.y1; + + h = b-t; + } } + + if(!skip) + { + f32 y_pos = t; - v.cols = col; + v = ctx.buffers[ctx.f_idx].vtx.ptr + ctx.buffers[ctx.f_idx].count; - v.texture = 1; + v.dst_start.x = *x_pos + l; + v.dst_start.y = y - y_pos; + v.dst_end.x = *x_pos + w + l; + v.dst_end.y = y + h - y_pos; - AddUIIndices(ctx); + v.z_index = item.z_index; + + if(glyph.ch != '\t' && glyph.ch != '\n') + { + v.src_start.x = glyph.atlas_left; + v.src_start.y = glyph.atlas_top; + v.src_end.x = glyph.atlas_right; + v.src_end.y = glyph.atlas_bottom; + } + + if(highlight) + { + col = Vec4(Vec3(1.0)-col.xyz, 1.0); + } + + v.cols = col; + + v.texture = 1; + + AddUIIndices(ctx); + } *x_pos += glyph.advance * scale; } diff --git a/src/editor/widgets.d b/src/editor/widgets.d index ed88f1c..0f803ce 100644 --- a/src/editor/widgets.d +++ b/src/editor/widgets.d @@ -245,9 +245,7 @@ Separator(UIPanel* panel, UIItem* parent, f32* adj_x, f32* adj_y) UIItem* item = Get(buf); f32 prev_z = GetZIndex(); - SetZIndex(-5.0); BuildItem(item, UISize(x_t, sep_x), UISize(y_t, sep_y), UIF.DrawBackground|UIF.Draggable); - SetZIndex(prev_z); Signal(item); @@ -316,18 +314,11 @@ EditorView(UIPanel* panel) bool focused = panel == GetFocusedPanel(); f32 prev_z = GetZIndex(); - if(!focused) - { - SetZIndex(-1.0); - } UICtx* ctx = GetCtx(); UIItem* item = Panel(panel, UIF.Clickable); Editor* ed = panel.ed; - - scope(exit) SetZIndex(prev_z); - Container(ScratchName(panel.id, "cntr"), UISize(ST.Percentage, 1.0), UISize(ST.Percentage, 1.0), A2D.X); f32 text_size = 16.0; @@ -502,9 +493,7 @@ DrawPanels(UIPanel* panel) } else { - SetZIndex(1.0); Panel(panel); - SetZIndex(0.0); } DrawPanels(panel.first);