summaryrefslogtreecommitdiff
path: root/src/layout.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout.zig')
-rw-r--r--src/layout.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/layout.zig b/src/layout.zig
index e674ccbf..efa79394 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -1070,6 +1070,32 @@ pub fn attachFrom(p: *Pardes, owner: usize, id: usize, rows: u16, giver: usize)
return true;
}
+/// A closed pane brought back (Store.reopen) where it was: next to
+/// `gainer`, the pane its rows went to when it closed, below it (under its
+/// group) or above it, `rows` tall, those rows taken from `gainer` alone,
+/// so no other pane moves. False when the gainer is folded or too short
+/// to give a pane its minimum and keep its own.
+pub fn giveBack(p: *Pardes, id: usize, gainer: usize, below: bool, rows: u16) bool {
+ const g = p.panes[gainer] orelse return false;
+ const nw = p.panes[id] orelse return false;
+ if (g.collapsed) return false;
+ compute(p);
+ const f = findPane(p, gainer) orelse return false;
+ // Its tag wraps at the column's width: measured there.
+ p.rects[id].w = p.col_w[f.col];
+ const gh = p.rects[gainer].h;
+ const least = minRows(p, id);
+ const keeps = minRows(p, gainer);
+ if (gh < least + keeps) return false;
+ const give = std.math.clamp(rows, least, gh - keeps);
+ snapColWeights(p, f.col);
+ insert(p, f.col, if (below) groupEnd(p, f.col, f.idx) else f.idx, id);
+ g.vweight = @floatFromInt(gh - give);
+ nw.vweight = @floatFromInt(give);
+ compute(p);
+ return true;
+}
+
/// Collapse on an owner with attachments: the whole group folds to its
/// tags, every row it gave up to the one unfolded neighbour outside it,
/// and unfolds again from that neighbour, as one pane's Collapse does.