From f207f1d4d56d1012766e6206e713f2b3da70579d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 10:11:14 -0300 Subject: A column takes panes until their minimums fill it, not until none can be halved Placement halved the tallest pane or refused, so 11 panes filled 48 rows that hold 16 at their tag and two rows each: the refusal did not match the documented arithmetic. When no pane can be halved but the minimums with the new pane's fit, the column's rows are shared out again; and a refused pane's removal leaves no pane under its minimum. Co-Authored-By: Claude Opus 5.5 --- src/layout.zig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/layout.zig') diff --git a/src/layout.zig b/src/layout.zig index 09cf23b3..16af1ec5 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -441,6 +441,52 @@ pub fn minimaFit(p: *Pardes) bool { return true; } +/// Whether every unfolded pane of column `c` has its `minRows` (a pane +/// alone in its column always does). +pub fn columnAtMinimums(p: *Pardes, c: usize) bool { + compute(p); + if (p.col_n[c] < 2) return true; + for (p.col_panes[c][0..p.col_n[c]]) |k| { + const pane = p.panes[k] orelse continue; + if (!pane.collapsed and p.rects[k].h < minRows(p, k)) return false; + } + return true; +} + +/// Shares column `c`'s rows out again so every unfolded pane has its +/// `minRows`, as evenly as that allows; false, changing nothing, when the +/// column has not the rows for all of them (or holds a folded pane). +pub fn shareColumn(p: *Pardes, c: usize) bool { + compute(p); + const n = p.col_n[c]; + if (n == 0) return false; + const avail = p.screen_h -| (p.topBarHeight() + p.columnBarHeight()); + var mins: [MAX_PANES]u16 = undefined; + var need: u32 = 0; + for (p.col_panes[c][0..n], 0..) |k, i| { + const pane = p.panes[k] orelse return false; + if (pane.collapsed) return false; + p.rects[k].w = p.col_w[c]; + mins[i] = minRows(p, k); + need += mins[i]; + } + if (need > avail) return false; + // Each its minimum, then what is left a row at a time to the smallest. + var hs: [MAX_PANES]u16 = undefined; + @memcpy(hs[0..n], mins[0..n]); + var left = avail - need; + while (left > 0) : (left -= 1) { + var low: usize = 0; + for (1..n) |i| if (hs[i] < hs[low]) { + low = i; + }; + hs[low] += 1; + } + for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(hs[i]); + compute(p); + return true; +} + /// After a resize the minima fit: each unfolded pane the resize took below /// its `minRows` (it had them in `before`) gets them back, a row at a time /// from whichever pane of its column has the most above its own. A pane -- cgit v1.3