summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tui/panel_compositor.zig150
1 files changed, 42 insertions, 108 deletions
diff --git a/src/tui/panel_compositor.zig b/src/tui/panel_compositor.zig
index 67d3a6e6..476a21c8 100644
--- a/src/tui/panel_compositor.zig
+++ b/src/tui/panel_compositor.zig
@@ -78,12 +78,14 @@ pub fn compose(
// Stable layout motion first, newly opening panels above it, and closing
// tombstones last. A closing pane no longer owns input or canonical cells,
// but its frozen old content remains the top visual until it slides out.
+ // A slide or a zoom is clipped by nothing but the screen.
+ const screen: Box = .{ .w = @floatFromInt(out.cols), .h = @floatFromInt(out.rows) };
for ([_]animation.Phase{ .moving, .opening, .closing }) |phase| {
for (tracks) |track| {
if (!drawable(source, track) or track.phase != phase) continue;
switch (track.effect) {
.off => {},
- .slide, .zoom => transform(out, source, track),
+ .slide, .zoom => transformClipped(out, source.cols, source.rows, source.cells, track, screen),
.dissolve => dissolve(out, source, track),
// Pardes core has already composed every character effect
// into source.cells — byte walks, glyph motion, and per-cell
@@ -105,33 +107,6 @@ fn drawable(source: *const pardes.Surface, track: Track) bool {
(!track.effect.needsPreviousGrid() or source.hasPanelDiff());
}
-fn transform(out: *pardes.Surface, source: *const pardes.Surface, track: Track) void {
- const shown = track.presented();
- if (shown.w <= 0 or shown.h <= 0) return;
- const dst = clipped(shown, out.cols, out.rows) orelse return;
- var y = dst.y0;
- while (y < dst.y1) : (y += 1) {
- var x = dst.x0;
- while (x < dst.x1) : (x += 1) {
- // The core hit-tests cell CENTRES against this same half-open box.
- // floor/ceil clipping includes boundary cells for iteration, but
- // they are not visible unless their centre is actually inside.
- // Test that containment before division: at large u16 grids f32
- // can round an inside right-edge ratio to exactly 1.0.
- const cx = @as(f32, @floatFromInt(x)) + 0.5;
- const cy = @as(f32, @floatFromInt(y)) + 0.5;
- if (cx < shown.x or cx >= shown.x + shown.w or
- cy < shown.y or cy >= shown.y + shown.h) continue;
- const u = std.math.clamp((cx - shown.x) / shown.w, 0, 0.999_999);
- const v = std.math.clamp((cy - shown.y) / shown.h, 0, 0.999_999);
- const sx: i32 = @intFromFloat(@floor(track.to.x + u * track.to.w));
- const sy: i32 = @intFromFloat(@floor(track.to.y + v * track.to.h));
- if (sx < 0 or sy < 0 or sx >= source.cols or sy >= source.rows) continue;
- out.at(x, y).* = source.cells[@as(usize, @intCast(sy)) * source.cols + @as(usize, @intCast(sx))];
- }
- }
-}
-
fn dissolve(out: *pardes.Surface, source: *const pardes.Surface, track: Track) void {
const area = clipped(track.to, out.cols, out.rows) orelse return;
const amount = track.amount();
@@ -171,9 +146,11 @@ fn vertical(out: *pardes.Surface, source: *const pardes.Surface, track: Track) v
transformClipped(out, source.cols, source.rows, cells, track, track.contentBox());
}
-/// Translate one old/new canonical panel through its fixed lifecycle clip.
-/// Sampling is always relative to contentBox: an opener reads its new target,
-/// while a closer reads the old box retained after that pane was destroyed.
+/// Translate one old/new canonical panel through a clip: a vertical
+/// panel's fixed lifecycle box, or the screen for a slide or a zoom.
+/// Sampling is always relative to contentBox: an opener and a moving panel
+/// read their new target, a closer the old box retained after that pane
+/// was destroyed (only a vertical one closes).
fn transformClipped(
out: *pardes.Surface,
source_cols: u16,
@@ -190,6 +167,11 @@ fn transformClipped(
while (y < dst.y1) : (y += 1) {
var x = dst.x0;
while (x < dst.x1) : (x += 1) {
+ // The core hit-tests cell CENTRES against this same half-open box.
+ // floor/ceil clipping includes boundary cells for iteration, but
+ // they are not visible unless their centre is actually inside.
+ // Test that containment before division: at large u16 grids f32
+ // can round an inside right-edge ratio to exactly 1.0.
const cx = @as(f32, @floatFromInt(x)) + 0.5;
const cy = @as(f32, @floatFromInt(y)) + 0.5;
if (cx < shown.x or cx >= shown.x + shown.w or
@@ -236,20 +218,21 @@ fn clipped(box: Box, cols: u16, rows: u16) ?GridBox {
return if (area.x0 < area.x1 and area.y0 < area.y1) area else null;
}
+/// Each of `cells` a one-byte glyph of `glyphs`, in order.
+fn testGlyphs(cells: []pardes.Cell, glyphs: []const u8) void {
+ for (cells, glyphs) |*cell, glyph| {
+ cell.text[0] = glyph;
+ cell.len = 1;
+ cell.default = false;
+ }
+}
+
test "TTY consumes core-composed ASCII cells without reinterpreting glyphs" {
var cells: [8]pardes.Cell = @splat(.{});
var previous: [8]pardes.Cell = @splat(.{});
const diffs: [8]pardes.PanelCellDiff = @splat(.visual);
- for (&cells) |*cell| {
- cell.text[0] = 'X';
- cell.len = 1;
- cell.default = false;
- }
- for (&previous) |*cell| {
- cell.text[0] = 'O';
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&cells, "XXXXXXXX");
+ testGlyphs(&previous, "OOOOOOOO");
var surface: pardes.Surface = .{
.cols = 4,
.rows = 2,
@@ -275,16 +258,8 @@ test "TTY consumes core-composed ASCII cells without reinterpreting glyphs" {
test "dissolve changes only diff cells from old to new" {
var cells: [2]pardes.Cell = @splat(.{});
var previous: [2]pardes.Cell = @splat(.{});
- for (&cells, "NU") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
- for (&previous, "OU") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&cells, "NU");
+ testGlyphs(&previous, "OU");
const diffs = [_]pardes.PanelCellDiff{ .{ .ascii = .{ .from = 'O', .to = 'N' } }, .unchanged };
var surface: pardes.Surface = .{
.cols = 2,
@@ -316,19 +291,11 @@ test "dissolve changes only diff cells from old to new" {
test "TTY content effects never touch cells outside the published diff" {
var cells: [4]pardes.Cell = @splat(.{});
var previous: [4]pardes.Cell = @splat(.{});
- for (&cells, "NUQV") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&cells, "NUQV");
// Deliberately disagree even where the mask says unchanged. This makes
// the test prove that the compositor obeys the core cell diff rather than
// merely appearing correct because old and new happened to match there.
- for (&previous, "OXRY") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&previous, "OXRY");
const diffs = [_]pardes.PanelCellDiff{ .visual, .unchanged, .visual, .unchanged };
var surface: pardes.Surface = .{
.cols = 4,
@@ -356,8 +323,7 @@ test "TTY content effects never touch cells outside the published diff" {
test "content transition without a diff snaps to canonical surface" {
var cells = [_]pardes.Cell{.{}};
- cells[0].text[0] = 'N';
- cells[0].default = false;
+ testGlyphs(&cells, "N");
var surface: pardes.Surface = .{
.cols = 1,
.rows = 1,
@@ -407,16 +373,8 @@ test "exact transition endpoint preserves the canonical cursor" {
test "vertical opening rises through a fixed old-grid clip" {
var cells: [12]pardes.Cell = @splat(.{});
var previous: [12]pardes.Cell = @splat(.{});
- for (&cells, "aaabbbcccddd") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
- for (&previous, "000111222333") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&cells, "aaabbbcccddd");
+ testGlyphs(&previous, "000111222333");
const diffs: [12]pardes.PanelCellDiff = @splat(.visual);
var surface: pardes.Surface = .{
.cols = 3,
@@ -460,16 +418,8 @@ test "vertical opening rises through a fixed old-grid clip" {
test "vertical closing drops frozen content over canonical cells" {
var cells: [12]pardes.Cell = @splat(.{});
var previous: [12]pardes.Cell = @splat(.{});
- for (&cells, "aaabbbcccddd") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
- for (&previous, "000111222333") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&cells, "aaabbbcccddd");
+ testGlyphs(&previous, "000111222333");
const diffs: [12]pardes.PanelCellDiff = @splat(.visual);
var surface: pardes.Surface = .{
.cols = 3,
@@ -511,10 +461,8 @@ test "vertical closing drops frozen content over canonical cells" {
test "closing content paints after opening content regardless of track order" {
var cells = [_]pardes.Cell{.{}};
var previous = [_]pardes.Cell{.{}};
- cells[0].text[0] = 'N';
- cells[0].default = false;
- previous[0].text[0] = 'O';
- previous[0].default = false;
+ testGlyphs(&cells, "N");
+ testGlyphs(&previous, "O");
const diffs = [_]pardes.PanelCellDiff{.visual};
var surface: pardes.Surface = .{
.cols = 1,
@@ -548,11 +496,7 @@ test "closing content paints after opening content regardless of track order" {
test "opening panel cannot erase an existing panel drawn underneath" {
var cells: [8]pardes.Cell = @splat(.{});
- for (&cells, 0..) |*cell, x| {
- cell.text[0] = if (x < 4) 'A' else 'B';
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&cells, "AAAABBBB");
var surface: pardes.Surface = .{ .cols = 8, .rows = 1, .cells = &cells };
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
@@ -578,10 +522,8 @@ test "opening panel cannot erase an existing panel drawn underneath" {
test "geometry gap is a blank painted in an explicit theme background" {
var cells: [4]pardes.Cell = @splat(.{});
- for (&cells, "ABCD") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
+ testGlyphs(&cells, "ABCD");
+ for (&cells) |*cell| {
cell.style = .{
.fg = .{ .rgb = .{ 220, 210, 200 } },
.bg = .{ .rgb = .{ 30, 20, 10 } },
@@ -615,11 +557,7 @@ test "geometry gap is a blank painted in an explicit theme background" {
test "geometry gap stays terminal-default for a transparent theme" {
var cells: [2]pardes.Cell = @splat(.{});
- for (&cells, "AB") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&cells, "AB");
var surface: pardes.Surface = .{ .cols = 2, .rows = 1, .cells = &cells };
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
@@ -639,11 +577,7 @@ test "geometry gap stays terminal-default for a transparent theme" {
test "fractional geometry draws exactly the cell centres core can hit" {
var cells: [3]pardes.Cell = @splat(.{});
- for (&cells, "ABC") |*cell, glyph| {
- cell.text[0] = glyph;
- cell.len = 1;
- cell.default = false;
- }
+ testGlyphs(&cells, "ABC");
var surface: pardes.Surface = .{ .cols = 3, .rows = 1, .cells = &cells };
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
@@ -673,7 +607,7 @@ test "large-grid right edge uses containment before rounded ratio" {
cell.len = 1;
cell.default = false;
}
- var source: pardes.Surface = .{ .cols = cols, .rows = 1, .cells = source_cells };
+ const source: pardes.Surface = .{ .cols = cols, .rows = 1, .cells = source_cells };
var output: pardes.Surface = .{ .cols = cols, .rows = 1, .cells = output_cells };
const track: Track = .{
.serial = 1,
@@ -684,7 +618,7 @@ test "large-grid right edge uses containment before rounded ratio" {
};
const shown = track.presented();
try std.testing.expect(@as(f32, 63_935.5) < shown.x + shown.w);
- transform(&output, &source, track);
+ transformClipped(&output, source.cols, source.rows, source.cells, track, .{ .w = @floatFromInt(output.cols), .h = @floatFromInt(output.rows) });
try std.testing.expectEqualStrings("X", output.at(63_935, 0).grapheme());
}