diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 10:11:14 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:16 -0300 |
| commit | f207f1d4d56d1012766e6206e713f2b3da70579d (patch) | |
| tree | 307fb71b210cb4757f2d3fa56094effe20e4d3cf /src/layout.zig | |
| parent | df6106af80e13cc4f0121b7f2caf5315a4453a9d (diff) | |
| download | pardes-f207f1d4d56d1012766e6206e713f2b3da70579d.tar.gz pardes-f207f1d4d56d1012766e6206e713f2b3da70579d.zip | |
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 <[email protected]>
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 46 |
1 files changed, 46 insertions, 0 deletions
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 |
