summaryrefslogtreecommitdiff
path: root/src/layout.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-28 17:56:30 -0300
committerGabriel Schneider <[email protected]>2026-10-28 21:05:25 -0300
commit96f840a055651b88eb1191772bc4b10fcbbb60ce (patch)
tree55ccd6e05fc1f7419f1fef3fb2c7116b556c85d2 /src/layout.zig
parentf8c27dbfa9afca327189181a668f2191b499bea5 (diff)
downloadpardes-96f840a055651b88eb1191772bc4b10fcbbb60ce.tar.gz
pardes-96f840a055651b88eb1191772bc4b10fcbbb60ce.zip
layout: a new pane takes rows only from the pane it splits, as acme's coladd does: no column shared out evenly after a placement (only a pane the rounding squeezed, and the new one, lifted to their minimum, restoreMinimaFrom), none when there is no pane to halve (takeRoom: its minimum from the panes with the most to spare), none after a refused pane (it held no weight; absorbVWeight gives back and snaps nothing for it), none after Newcol or the finder column (only a pane whose tag now wraps past its rows is lifted, squeezed); a pane dragged short keeps its rows through all of them; test: a pane made from the middle between two short ones, then Newcol
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/layout.zig')
-rw-r--r--src/layout.zig72
1 files changed, 70 insertions, 2 deletions
diff --git a/src/layout.zig b/src/layout.zig
index efa79394..f545f60d 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -681,6 +681,24 @@ pub fn shareColumn(p: *Pardes, c: usize) bool {
/// from whichever pane of its column has the most above its own. A pane
/// dragged short before keeps what it had.
pub fn restoreMinima(p: *Pardes, before: *const [MAX_PANES]Rect) void {
+ restoreMinimaFrom(p, before, null);
+}
+
+/// Each pane's `minRows` now: what `restoreMinimaFrom` measures a step that
+/// grows the minima (a narrower column wrapping tags) against.
+pub fn minima(p: *Pardes) [MAX_PANES]u16 {
+ compute(p);
+ var mins: [MAX_PANES]u16 = @splat(0);
+ for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |k| {
+ mins[k] = minRows(p, k);
+ };
+ return mins;
+}
+
+/// restoreMinima, a pane's minimum before the step `before_min` (its tag
+/// may wrap onto more rows since): one that had that minimum is lifted to
+/// its minimum now, one dragged under it before keeps its rows.
+pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: ?*const [MAX_PANES]u16) void {
compute(p);
for (0..p.ncol) |c| {
const n = p.col_n[c];
@@ -693,11 +711,11 @@ pub fn restoreMinima(p: *Pardes, before: *const [MAX_PANES]Rect) void {
if (pane.collapsed) break;
hs[i] = p.rects[k].h;
mins[i] = minRows(p, k);
- if (hs[i] < mins[i] and before[k].h >= mins[i]) short = true;
+ if (hs[i] < mins[i] and before[k].h >= if (before_min) |bm| bm[k] else mins[i]) short = true;
} else {
if (!short) continue;
for (p.col_panes[c][0..n], 0..) |k, i| {
- if (hs[i] >= mins[i] or before[k].h < mins[i]) continue;
+ if (hs[i] >= mins[i] or before[k].h < if (before_min) |bm| bm[k] else mins[i]) continue;
while (hs[i] < mins[i]) {
var giver: ?usize = null;
var spare: u16 = 0;
@@ -716,6 +734,53 @@ pub fn restoreMinima(p: *Pardes, before: *const [MAX_PANES]Rect) void {
compute(p);
}
+/// Whether a pane of column `c` is under its minimum now that had its
+/// minimum then (`before`, `before_min`): one a step squeezed, not one
+/// dragged short.
+pub fn squeezed(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_min: *const [MAX_PANES]u16) bool {
+ compute(p);
+ if (p.col_n[c] < 2) return false;
+ 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) and before[k].h >= before_min[k]) return true;
+ }
+ return false;
+}
+
+/// Column `c`'s rows for `id`, last in it, at its minimum: a row at a
+/// time from whichever pane has the most above its own minimum, so a pane
+/// dragged short keeps its rows and the others give only what they must.
+/// False, changing nothing, when the column has not the rows.
+pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool {
+ compute(p);
+ const n = p.col_n[c];
+ p.rects[id].w = p.col_w[c];
+ var need = minRows(p, id);
+ var hs: [MAX_PANES]u16 = undefined;
+ var mins: [MAX_PANES]u16 = undefined;
+ var spare: 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;
+ hs[i] = p.rects[k].h;
+ mins[i] = minRows(p, k);
+ spare += hs[i] -| mins[i];
+ }
+ if (spare < need) return false;
+ while (need > 0) : (need -= 1) {
+ var giver: usize = 0;
+ for (1..n) |i| if (hs[i] -| mins[i] > hs[giver] -| mins[giver]) {
+ giver = i;
+ };
+ hs[giver] -= 1;
+ }
+ for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i]));
+ insert(p, c, n, id);
+ p.panes[id].?.vweight = @floatFromInt(minRows(p, id));
+ compute(p);
+ return true;
+}
+
/// After placing `id`: whether it, and every pane of its column that the
/// placement shrank, still has its tag and `min_body_rows` (from `before`,
/// the rects as they were). A pane alone in its column always has room: the
@@ -908,6 +973,9 @@ pub fn snapColWeights(p: *Pardes, c: usize) void {
pub fn absorbVWeight(p: *Pardes, id: usize, to: ?usize) ?usize {
const f = findPane(p, id) orelse return null;
if (p.col_n[f.col] <= 1) return null;
+ // A refused pane held no weight: the rows the others' rounding lent it
+ // go back to them as they were, nobody's weight snapped.
+ if (p.panes[id]) |pane| if (!pane.collapsed and pane.vweight == 0) return null;
snapColWeights(p, f.col);
var sib = to orelse if (f.idx > 0) p.col_panes[f.col][f.idx - 1] else p.col_panes[f.col][f.idx + 1];
var k = f.idx;