summaryrefslogtreecommitdiff
path: root/core/layout.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/layout.zig')
-rw-r--r--core/layout.zig91
1 files changed, 82 insertions, 9 deletions
diff --git a/core/layout.zig b/core/layout.zig
index 3f6bea51..c8fb91f9 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -402,7 +402,7 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void {
if (missing == 0) break;
}
setColumnWeights(p, at.col, &heights);
- p.sync();
+ p.layOut();
}
pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void {
@@ -592,12 +592,18 @@ pub const min_body_rows = 2;
/// wants a row more.
pub fn wantedTagRows(p: *Pardes, id: usize) u16 {
const pane = p.panes[id] orelse return BOX_H;
+ return tagRows(p, id, tagline.computedWords(pane));
+}
+
+/// The rows pane `id`'s tag at rest takes with computed words `words`.
+fn tagRows(p: *Pardes, id: usize, words: []const u8) u16 {
+ const pane = p.panes[id] orelse return BOX_H;
if (pane.collapsed or !pane.tag_expanded) return BOX_H;
if (p.view().rects[id].w == 0) return pane.tag_rows; // never laid out
var wrap_room: [32 * 1024]u8 = undefined;
var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room);
const wa = wrap_fba.allocator();
- const prefix = tagline.restPrefix(p, wa, pane) catch return pane.tag_rows;
+ const prefix = tagline.prefixWith(p, wa, pane, words) catch return pane.tag_rows;
const whole = std.mem.concat(wa, u8, &.{ prefix, tagline.curTail(pane) }) catch return pane.tag_rows;
const shown = tagline.wrapTag(p.settings.tab, wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows;
return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS)));
@@ -622,7 +628,11 @@ pub fn headRows(p: *Pardes, id: usize) u16 {
/// The rows a placement, and a `size`, leave a pane: its tag at its width
/// and `min_body_rows`. The one minimum both ask.
pub fn minRows(p: *Pardes, id: usize) u16 {
- return wantedTagRows(p, id) + min_body_rows;
+ const pane = p.panes[id] orelse return BOX_H + min_body_rows;
+ // Its tag with the widest computed words it can come to show (UX
+ // K'3): an edit that brings Save and Undo never takes a row its
+ // column did not give.
+ return tagRows(p, id, tagline.widestWords(p, pane)) + min_body_rows;
}
/// Whether every column has the rows for each of its unfolded panes'
@@ -1668,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
@@ -1682,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);
@@ -1694,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;
}
@@ -2580,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]);
+}