diff options
Diffstat (limited to 'core/layout.zig')
| -rw-r--r-- | core/layout.zig | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/core/layout.zig b/core/layout.zig index be2d213c..b72d6ec5 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -1678,12 +1678,24 @@ pub fn noticeRowHeight(p: *const Pardes) u16 { 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). +/// The column tags' row: one, as acme's (cols.c:244, colresize, gives a +/// column tag one font height), a newline in one a space +/// (tagline.flattenHeaders); only while there are columns (UX K'2): two +/// or more, a column tag holding the user's text, or no window row for a +/// lone column's words (a native shell's). None on a screen too short. pub fn columnBarHeight(p: *const Pardes) u16 { - if (p.view().screen_h < 3) return 0; - return COLBAR_H; + const v = p.view(); + if (v.screen_h < 3) return 0; + if (v.ncol > 1 or p.topBarHeight() == 0) return COLBAR_H; + for (v.col_tags[0..v.ncol]) |t| if (t.own) |own| if (own.len > 0) return COLBAR_H; + return 0; +} + +/// A lone column's tag is at the window row's left (UX K'2): no column +/// row, and a window row for it. +pub fn columnInWindowRow(p: *const Pardes) bool { + const v = p.view(); + return v.ncol == 1 and v.screen_h >= 3 and p.topBarHeight() > 0 and columnBarHeight(p) == 0; } /// Whether new column `c` (Newcol's) may stay. A narrower @@ -1692,9 +1704,13 @@ pub fn columnBarHeight(p: *const Pardes) u16 { /// minimum `before`, `before_min`, not one dragged short) takes rows back /// from the panes with rows to spare, its column shared out again only /// where that is not enough. False, `c` dropped unannounced, where nothing -/// holds every minimum, as a size too small is refused. +/// holds every minimum, as a size too small is refused, and every pane's +/// rows as they were: the trial's shares are taken back with it (the +/// column row a second column brings, UX K'2, takes a row from every pane). pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_min: *const [MAX_PANES]u16) bool { const v = p.view(); + var weights: [MAX_PANES]f32 = undefined; + for (p.panes, &weights) |slot, *w| w.* = if (slot) |pane| pane.vweight else 0; restoreMinimaFrom(p, before, before_min); for (0..p.view().ncol) |k| { compute(p); @@ -1704,6 +1720,9 @@ pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_m if (!pane.collapsed and v.rects[id].h < minRows(p, id) and before[id].h >= before_min[id]) break true; } else false; if (squeezed and !shareColumn(p, k)) { + for (p.panes, weights) |slot, w| if (slot) |pane| { + pane.vweight = w; + }; dropColumnUnannounced(p, c); return false; } @@ -2590,3 +2609,47 @@ test "free space first (UX J1): a command's output and a Term take an untouched try std.testing.expectEqual(before + 3, f.count()); try std.testing.expect(p.panes[scratch] != null); } + +test "the column row comes with a second column and goes with it, the panes giving it and taking it back; a column tag with the user's text keeps it (UX K'2)" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true }); + defer p.deinit(); + _ = try p.setTestFile("one\n"); + // One column: no column row, its words in the window row, its pane + // under the window row. + try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p)); + try std.testing.expect(columnInWindowRow(p)); + const alone = p.view().rects[0]; + try std.testing.expectEqual(TOPBAR_H, alone.y); + // A second column: the row, under the window row, every column's panes + // starting under it. + try std.testing.expect(p.executeBuiltinLine(0, "Newcol")); + p.sync(); + try std.testing.expectEqual(@as(usize, 2), p.view().ncol); + try std.testing.expectEqual(COLBAR_H, columnBarHeight(p)); + try std.testing.expect(!columnInWindowRow(p)); + try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y); + newScratchIn(p, 0, 1); + p.sync(); + const second = p.view().cols[1].panes[0]; + try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[second].y); + // Delcol back to one: the row goes, the pane has it again. + p.exec_column = 1; + try std.testing.expect(p.executeBuiltinLine(second, "Delcol")); + p.exec_column = null; + p.sync(); + try std.testing.expectEqual(@as(usize, 1), p.view().ncol); + try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p)); + try std.testing.expectEqualDeep(alone, p.view().rects[0]); + // The user's text in the column's tag: the row stays for it, alone. + p.view().col_tags[0].own = try p.gpa.dupe(u8, "Mine"); + p.sync(); + try std.testing.expectEqual(COLBAR_H, columnBarHeight(p)); + try std.testing.expect(!columnInWindowRow(p)); + try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y); + // Emptied, it goes again. + p.gpa.free(p.view().col_tags[0].own.?); + p.view().col_tags[0].own = try p.gpa.dupe(u8, ""); + p.sync(); + try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p)); + try std.testing.expectEqualDeep(alone, p.view().rects[0]); +} |
