diff options
Diffstat (limited to 'core/layout.zig')
| -rw-r--r-- | core/layout.zig | 73 |
1 files changed, 61 insertions, 12 deletions
diff --git a/core/layout.zig b/core/layout.zig index f9b9ef81..c12780d8 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -613,7 +613,7 @@ pub fn minRows(p: *Pardes, id: usize) u16 { pub fn minimaFit(p: *Pardes) bool { const v = p.view(); compute(p); - const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p)); + const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p) + noticeRowHeight(p)); for (0..p.view().ncol) |c| { if (v.cols[c].n < 2) continue; var need: u32 = 0; @@ -647,7 +647,7 @@ pub fn shareColumn(p: *Pardes, c: usize) bool { compute(p); const n = v.cols[c].n; if (n == 0) return false; - const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p)); + const avail = v.screen_h -| (p.topBarHeight() + columnBarHeight(p) + noticeRowHeight(p)); var mins: [MAX_PANES]u16 = undefined; var need: u32 = 0; for (v.cols[c].panes[0..n], 0..) |k, i| { @@ -860,8 +860,46 @@ fn blankRows(p: *const Pardes, id: usize) u16 { } /// What a new pane is, and who asked: each rule places them differently. -/// `scratch` is New's, `fs` 9P's pane/new, `errors` a +Errors pane. -pub const NewPane = enum { scratch, fs, shell, doc, command, errors }; +/// `scratch` is New's, `fs` 9P's pane/new, `errors` a +Errors pane, +/// `reader` a held pane's reader (Trail.zig). +pub const NewPane = enum { scratch, fs, shell, doc, command, errors, reader }; + +/// The body rows a held pane keeps above its reader: with fewer, the +/// reader goes to the next column (pick-ui SPEC §6.1). +pub const reader_keeps = 8; + +/// A reader's place (pick-ui SPEC §6.1): under its held pane `from`, +/// taking half its rows, unless that leaves it fewer than `reader_keeps` +/// body rows; then at the bottom of the next column, the previous one +/// when `from`'s is the last, as New takes the bottom of a column. +fn readerPlace(p: *Pardes, from: usize, id: usize) void { + const v = p.view(); + const c = columnOf(p, from); + const r = v.rects[from]; + if (findPane(p, from) != null and r.h / 2 >= p.panes[from].?.tag_rows + reader_keeps) return splitAt(p, c, id, r.y + r.h / 2); + acmePlace(p, if (c + 1 < v.ncol) c + 1 else c -| 1, null, id); +} + +/// Pane `new` in pane `old`'s place in every view, with its rows: a +/// reader's step to another file (Trail.zig). `old` leaves no layout. +pub fn replacePane(p: *Pardes, old: usize, new: usize) void { + const was = p.panes[old].?; + const now = p.panes[new].?; + now.vweight = was.vweight; + now.collapsed = was.collapsed; + for (0..pardes.views.max) |k| if (now.pv_known & was.pv_known & (@as(u8, 1) << @intCast(k)) != 0) { + now.pv[k].vweight = was.pv[k].vweight; + now.pv[k].collapsed = was.pv[k].collapsed; + }; + for (&p.views) |*slot| { + const v = &(slot.* orelse continue); + for (v.cols[0..v.ncol]) |*col| for (col.panes[0..col.n]) |*k| if (k.* == old) { + k.* = new; + }; + v.rects[new] = v.rects[old]; + if (v.active == old) v.active = new; + } +} /// Put new pane `id` in the layout: every new pane comes through here, as /// acme's makenewwindow places it, and every one but a command pane takes @@ -888,6 +926,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan // makenewwindow(nil) for 9P's new (acme.c:877), else (t). .fs => acmePlace(p, acmeColumn(p, from), null, id), .shell, .doc => acmePlace(p, acmeColumn(p, from), asked, id), + .reader => readerPlace(p, from, id), } // No pane is made shorter than its tag and two rows: where the place // chosen has not the room, the column's tallest pane gives it, and @@ -1333,7 +1372,8 @@ pub fn expandedNeighbor(p: *const Pardes, col: usize, index: usize, side: enum { fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usize) void { const v = p.view(); var y: u16 = p.topBarHeight() + columnBarHeight(p); - const available = v.screen_h -| y; + const bottom = v.screen_h -| noticeRowHeight(p); + const available = bottom -| y; var expanded_left: usize = 0; var weight: f32 = 0; for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (p.panes[id]) |pane| { @@ -1347,7 +1387,7 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz var folded_left = folded; for (v.cols[c].panes[0..p.view().cols[c].n]) |id| { const pane = p.panes[id] orelse continue; - const room = v.screen_h -| y; + const room = bottom -| y; const height: u16 = if (pane.collapsed) blk: { folded_left -= 1; break :blk @min(room, BOX_H); @@ -1401,7 +1441,8 @@ pub fn compute(p: *Pardes) void { var y: u16 = p.topBarHeight() + columnBarHeight(p); const top = y; - const avail_h = v.screen_h -| y; + const bottom = v.screen_h -| noticeRowHeight(p); + const avail_h = bottom -| y; var hs: [MAX_PANES]u16 = undefined; const n = v.cols[c].n; for (0..n) |k| { @@ -1412,7 +1453,7 @@ pub fn compute(p: *Pardes) void { }; const lastk = k + 1 == n; const fh = @as(f32, @floatFromInt(avail_h)) * pane.vweight / vsum; - const room = v.screen_h -| y; + const room = bottom -| y; hs[k] = if (lastk) room else @min(room, @max(1, @as(u16, @intFromFloat(@round(fh))))); y +|= hs[k]; } @@ -1476,6 +1517,14 @@ pub fn topBarHeight(p: *const Pardes) u16 { return TOPBAR_H; } +/// The notice row's height: one row at the window's foot (pick-ui SPEC +/// §10.3), the index of the live messages, under every column; none on a +/// screen too short for it, as the column tags have none. +pub fn noticeRowHeight(p: *const Pardes) u16 { + if (p.view().screen_h < 3) return 0; + return 1; +} + /// The column tags' height: one row, as acme's (cols.c:244, colresize, /// gives a column tag one font height); a newline in one is a space /// (tagline.flattenHeaders). @@ -1673,14 +1722,14 @@ test "collapse transfers height upward and restores the original layout" { toggleCollapse(p, 1); try std.testing.expectEqual(@as(u16, 1), p.view().rects[1].h); try std.testing.expectEqual(@as(f32, @floatFromInt(original[1].h)), p.panes[1].?.vweight); - try std.testing.expectEqual(p.view().screen_h, p.view().rects[2].y + p.view().rects[2].h); + try std.testing.expectEqual(p.view().screen_h - noticeRowHeight(p), p.view().rects[2].y + p.view().rects[2].h); try std.testing.expect(p.view().rects[0].h > original[0].h); try std.testing.expectEqualDeep(original[2], p.view().rects[2]); toggleCollapse(p, 1); try std.testing.expectEqualDeep(original, p.view().rects); toggleCollapse(p, 2); try std.testing.expectEqual(@as(u16, 1), p.view().rects[2].h); - try std.testing.expectEqual(p.view().screen_h, p.view().rects[2].y + p.view().rects[2].h); + try std.testing.expectEqual(p.view().screen_h - noticeRowHeight(p), p.view().rects[2].y + p.view().rects[2].h); } test "collapse changes only one neighbor at the top middle and bottom" { @@ -1798,7 +1847,7 @@ test "collapse single and all panes leave unused column space" { try std.testing.expectEqual(p.view().rects[0].y + 1, p.view().rects[1].y); try std.testing.expect(p.view().rects[1].y + 1 < p.view().screen_h); toggleCollapse(p, 0); - try std.testing.expectEqual(p.view().screen_h - 1, p.view().rects[1].y); + try std.testing.expectEqual(p.view().screen_h - noticeRowHeight(p) - 1, p.view().rects[1].y); } test "collapse survives tiny resizes" { @@ -1859,7 +1908,7 @@ test "collapse dump restores folded state and retained expansion weight" { try std.testing.expectEqual(@as(f32, @floatFromInt(original_height)), restored.panes[0].?.vweight); try std.testing.expectEqual(@as(u16, 1), restored.view().rects[0].h); toggleCollapse(restored, 0); - try std.testing.expectEqual(restored.view().screen_h - restored.view().rects[0].y, restored.view().rects[0].h); + try std.testing.expectEqual(restored.view().screen_h - noticeRowHeight(restored) - restored.view().rects[0].y, restored.view().rects[0].h); } test "column reorder moves only crossed state and preserves weights" { |
