diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 00:29:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:01:28 -0300 |
| commit | 2622b04dcf021ff36862a45b6e9c930e5671b9e2 (patch) | |
| tree | 872b01ce6ce664cd4b9c2190380e1622e4975d46 /src/layout.zig | |
| parent | 1b12f7aadaf0e0a4570a5985900f61d0fb897f79 (diff) | |
| download | pardes-2622b04dcf021ff36862a45b6e9c930e5671b9e2.tar.gz pardes-2622b04dcf021ff36862a45b6e9c930e5671b9e2.zip | |
layout: four wrappers go to their callers: restoreMinima (ctl.zig's size passes restoreMinimaFrom a null), splitRowForExtent (splitAt passes splitRowFor a null), attach (Query.zig and layout's tests pass attachFrom the owner as giver) and columnFitsHalves (exec.zig's first-document column checks the source column's width there)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/src/layout.zig b/src/layout.zig index 91947997..46db6439 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -239,11 +239,8 @@ pub fn targetColumn(p: *Pardes, cur_x: u16) usize { return tc; } -pub fn splitRowForExtent(y: u16, h: u16, cur_y: u16) ?u16 { - return splitRowFor(y, h, cur_y, null); -} - -/// As `splitRowForExtent`, each pane keeping at least `least` rows when +/// The row that splits the `h` rows from `y` nearest `cur_y`, each side +/// keeping MINH rows when there are that many (else one), or `least` when /// given: a pane dragged by its grip within its own column is how a /// terminal resizes, and acme lets either window keep only its tag. fn splitRowFor(y: u16, h: u16, cur_y: u16, least: ?u16) ?u16 { @@ -667,14 +664,6 @@ pub fn shareColumn(p: *Pardes, c: usize) bool { 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 -/// 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 { @@ -686,9 +675,12 @@ pub fn minima(p: *Pardes) [MAX_PANES]u16 { 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. +/// 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 +/// dragged short before keeps what it had. With `before_min`, a pane's +/// minimum before the step (its tag may wrap onto more rows since): one +/// that had that minimum is lifted to its minimum now. pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: ?*const [MAX_PANES]u16) void { compute(p); for (0..p.ncol) |c| { @@ -840,7 +832,7 @@ fn splitAt(p: *Pardes, c: usize, id: usize, y: u16) void { // Each keeps a tag and min_body_rows, where acme's minht keeps one. const lo = r.y +| minRows(p, v); const hi = (r.y + r.h) -| minRows(p, id); - const row = splitRowForExtent(r.y, r.h, if (lo <= hi) std.math.clamp(y, lo, hi) else r.y + r.h / 2) orelse { + const row = splitRowFor(r.y, r.h, if (lo <= hi) std.math.clamp(y, lo, hi) else r.y + r.h / 2, null) orelse { pane.vweight = BOX_H + 1; return; }; @@ -1089,14 +1081,9 @@ pub fn keepGroups(p: *Pardes) void { /// owner is unfolded first. The rows are the attachment's from then on: /// nothing here ever resizes it again; the seam is the user's to drag. /// False, `id` in no column, when the owner has not the rows for its tag -/// and the attachment's minimum. -pub fn attach(p: *Pardes, owner: usize, id: usize, rows: u16) bool { - return attachFrom(p, owner, id, rows, owner); -} - -/// attach, the rows given by `giver`: the owner itself or a pane of its -/// group (a +Preview added under a query pane later takes the text's rows, -/// so the query pane, typed into, keeps its own). +/// and the attachment's minimum. The rows are given by `giver`: the owner +/// itself or a pane of its group (a +Preview added under a query pane later +/// takes the text's rows, so the query pane, typed into, keeps its own). pub fn attachFrom(p: *Pardes, owner: usize, id: usize, rows: u16, giver: usize) bool { const o = p.panes[owner] orelse return false; const g = p.panes[giver] orelse return false; @@ -1648,7 +1635,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, // Under its owner, the rows asked for, the owner's and nobody else's. const s = try testAttachment(p); - try std.testing.expect(attach(p, 0, s, 9)); + try std.testing.expect(attachFrom(p, 0, s, 9, 0)); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s)); try std.testing.expectEqual(s, p.col_panes[0][1]); for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.rects[k]); @@ -1657,7 +1644,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, try std.testing.expectEqual(@as(u16, 9), p.rects[s].h); // A second level (a preview under a query pane): out of the first's rows. const pv = try testAttachment(p); - try std.testing.expect(attach(p, s, pv, 4)); + try std.testing.expect(attachFrom(p, s, pv, 4, s)); try std.testing.expectEqual(pv, p.col_panes[0][2]); try std.testing.expectEqual(@as(usize, 0), groupRoot(p, pv)); try std.testing.expectEqual(@as(usize, 3), groupEnd(p, 0, 0)); @@ -1722,7 +1709,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, // Del of the owner closes what is attached to it. const again = try testAttachment(p); - try std.testing.expect(attach(p, 0, again, 6)); + try std.testing.expect(attachFrom(p, 0, again, 6, 0)); exec.runBuiltin(p, .Del, 0, "", null); try std.testing.expect(p.panes[0] == null and p.panes[again] == null); } @@ -1732,7 +1719,7 @@ test "an attachment survives Dump and Restore, and one left away from its owner defer p.deinit(); _ = try p.setTestFile("alpha\nbeta\nalphabet\n"); const s = try testAttachment(p); - try std.testing.expect(attach(p, 0, s, 8)); + try std.testing.expect(attachFrom(p, 0, s, 8, 0)); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s)); try dump.dumpState(p); const restored = try dump.initFromDump(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }, p.dump_out.?); @@ -1743,7 +1730,7 @@ test "an attachment survives Dump and Restore, and one left away from its owner try std.testing.expect(p.panes[s].?.attached_to == null); // Put above its owner by a route that does not carry groups: detached. const t = try testAttachment(p); - try std.testing.expect(attach(p, 0, t, 8)); + try std.testing.expect(attachFrom(p, 0, t, 8, 0)); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, t)); removePane(p, t); insert(p, 0, 0, t); |
