summaryrefslogtreecommitdiff
path: root/dev/gui
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 01:28:47 -0300
committerGabriel Schneider <[email protected]>2026-11-23 01:28:47 -0300
commit5393ce743d7848d26e60fd7d4d27a4119272df9f (patch)
tree1d3a0f1ad74651bdbfcb6fb740099ebce7de3ed9 /dev/gui
parente6dd9c5c3a60e3609e99ab2076b5a2509a014a66 (diff)
parent4bd81bbb42088e9d6f1441094e8feea23064a6c6 (diff)
downloadpardes-5393ce743d7848d26e60fd7d4d27a4119272df9f.tar.gz
pardes-5393ce743d7848d26e60fd7d4d27a4119272df9f.zip
integration: the tree to install: the viewport in the view, a client's way back at an Upgrade, the pair's round 12 and the lanes on the glide: pardes-m61-base (`vzptorpy`: pardes-viewport (`llpwyqul`, the gathered line: a terminal's viewport a view's state, the wire at 31, the terminal put back at a TERM; gated whole as merge59) + pardes-upgrade-back (`krqkqlyo`: a client no longer gives up while its session upgrades; an old build's early rejoin keeps its view) + pardes-pair-12 (`mlutslkp`: a 9P request that changes the core waits for the pty output read before it; the soak with a pair)) and pardes-lane-glide (`nwzurwns` on `nnwosomt`, on pardes-raw-tty: in a window a change's lanes ride their lines' glide, kept with the rows that left, cut to the body); no conflict; core-test 918/1078 (160 skipped), shell-test 1120/1123; its gate: .scratch/sketch/reorg/merge60, the numbers in PARDES.md (2026-11-23)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/gui')
-rw-r--r--dev/gui/gui.zig253
1 files changed, 227 insertions, 26 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index b00073fa..88ba023b 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -455,6 +455,7 @@ const Gui = struct {
scroll_lag: f32 = 0, // picture position - core position, in rows
scroll_edge: []pardes.Cell = &.{}, // the row that just left the pane
scroll_edge_len: u16 = 0,
+ scroll_edge_lanes: pardes.glide.RowLanes = .{}, // and a change's lanes on it
/// Loop steps since the last fractional turn: past `settle_after`, a
/// resting `scroll_lag` eases onto the core's row (stepScroll).
scroll_idle: u8 = 0,
@@ -3349,6 +3350,8 @@ const WheelRun = struct {
mc: MouseCell,
drawn: f32 = 0,
now_ns: u64 = std.time.ns_per_s,
+ /// Each frame given a change's lanes (testLanes), as `Changes` would.
+ lanes: bool = false,
fn init(gpa: std.mem.Allocator, core: *pardes.Pardes) !WheelRun {
var wr: WheelRun = .{ .g = testGui(10, 20, 6, 12), .core = core, .arena = .init(gpa), .mc = undefined };
@@ -3384,6 +3387,7 @@ const WheelRun = struct {
if (!wr.core.needs_frame and !frontendMoving(&wr.g)) return;
_ = wr.arena.reset(.retain_capacity);
const s = try wr.core.render(wr.arena.allocator());
+ if (wr.lanes) try testLanes(gpa, wr.core, s);
wr.g.frame = s;
wr.g.facts = s.facts.*;
wr.g.now_ns = wr.now_ns;
@@ -3559,6 +3563,8 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool {
if (g.scroll_edge.len >= bw) {
@memcpy(g.scroll_edge[0..bw], s.cells[@as(usize, srow) * s.cols + r.x + config.GUTTER ..][0..bw]);
g.scroll_edge_len = bw;
+ g.scroll_edge_lanes = .{};
+ for (s.lanes.items) |lane| if (lane.y == srow and lane.x >= r.x + config.GUTTER and lane.x < r.x + r.w) g.scroll_edge_lanes.add(lane);
}
}
}
@@ -3567,22 +3573,63 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool {
return moved;
}
+/// The body a scroll moves, as its rows are drawn: a glide's at its
+/// offset, else a touchpad's fraction (scroll_lag); its pane's rect (the
+/// rail and the body, Glide.rect's), its body's first row and its rows.
+/// Null when nothing lags, or when it was resized under us.
+const ScrollBody = struct {
+ pane: usize,
+ gliding: bool,
+ lag: f32,
+ rect: pardes.Rect,
+ y0: u16,
+ bh: u16,
+
+ /// The grid row of the `i`th row that left it, nearest first: over its
+ /// moving rows (under the `held` ones) while the picture lags a move
+ /// down, under the body for one up.
+ fn leftRow(sb: ScrollBody, held: u16, i: usize) i32 {
+ return if (sb.lag < 0) @as(i32, sb.y0 + held) - 1 - @as(i32, @intCast(i)) else @as(i32, sb.y0) + sb.bh + @as(i32, @intCast(i));
+ }
+
+ /// A glide's rows that left it drawn: as many as the lag opens.
+ fn glideLeft(sb: ScrollBody, glide: *const Glide) u16 {
+ const gap: u16 = @intFromFloat(@min(@ceil(@abs(sb.lag)), @as(f32, @floatFromInt(@as(u32, sb.bh) * Glide.reach))));
+ return @min(gap, if (sb.lag < 0) glide.nabove else glide.nbelow);
+ }
+};
+
+fn scrollBody(g: *const Gui, surface: *const pardes.Surface) ?ScrollBody {
+ const glide = &g.glide;
+ const gliding = glide.follow.offset != 0;
+ const sb: ScrollBody = .{
+ .pane = if (gliding) glide.pane else g.scroll_pane orelse return null,
+ .gliding = gliding,
+ .lag = if (gliding) glide.follow.offset else g.scroll_lag,
+ .rect = if (gliding) glide.rect else g.scroll_rect,
+ .y0 = if (gliding) glide.body_y else g.scroll_body_y,
+ .bh = if (gliding) glide.body_h else g.scroll_body_h,
+ };
+ const bw = sb.rect.w -| config.GUTTER;
+ if (sb.lag == 0 or bw == 0 or sb.bh == 0 or sb.rect.x + config.GUTTER + bw > surface.cols or sb.y0 + sb.bh > surface.rows) return null;
+ return sb;
+}
+
/// A scrolling body's picture: its rows moved by the lag, a glide's or a
/// touchpad's fraction of a row, and in the gap that opens the rows that
/// left.
fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: [3]u8, held: u16) u32 {
g.scroll_held_px = 0;
const glide = &g.glide;
- const gliding = glide.follow.offset != 0;
- const pane = if (gliding) glide.pane else g.scroll_pane orelse return 0;
- const lag = if (gliding) glide.follow.offset else g.scroll_lag;
- if (lag == 0) return 0;
- const r = if (gliding) glide.rect else g.scroll_rect;
- const bh = if (gliding) glide.body_h else g.scroll_body_h;
- const y0 = if (gliding) glide.body_y else g.scroll_body_y;
- const bw = r.w -| config.GUTTER;
+ const sb = scrollBody(g, surface) orelse return 0;
+ const gliding = sb.gliding;
+ const pane = sb.pane;
+ const lag = sb.lag;
+ const r = sb.rect;
+ const bh = sb.bh;
+ const y0 = sb.y0;
+ const bw = r.w - config.GUTTER;
const x0 = r.x + config.GUTTER;
- if (bw == 0 or bh == 0 or x0 + bw > surface.cols or y0 + bh > surface.rows) return 0; // resized under us
// The scissor the shifted rows are drawn in is the scroll's.
g.scroll_rect = r;
g.scroll_body_y = y0;
@@ -3627,7 +3674,7 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *cons
// A touchpad's fraction opens one row, the one that left: under the
// held rows, where the moving rows start.
if (g.scroll_edge_len >= bw) {
- const erow: u16 = if (lag > 0) y0 + bh else y0 + kept.rows - 1;
+ const erow: u16 = @intCast(sb.leftRow(kept.rows, 0));
var i: u16 = 0;
while (i < bw) : (i += 1) {
emitInstance(g, instances, base + n, x0 + i, erow, shifted, win_w, win_h, cellFontRole(&g.scroll_edge[i]), g.scroll_edge[0..bw], i, null, false, page);
@@ -3638,14 +3685,10 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *cons
}
// A glide's: rows past the top while the picture lags a move down, past
// the bottom for one up; as many as it opens.
- const gap: u16 = @intFromFloat(@min(@ceil(@abs(lag)), @as(f32, @floatFromInt(@as(u32, bh) * Glide.reach))));
- const nkept = if (lag < 0) glide.nabove else glide.nbelow;
const rows = if (lag < 0) glide.above else glide.below;
- for (0..@min(gap, nkept)) |i| {
+ for (0..sb.glideLeft(glide)) |i| {
const cells = rows[i * bw ..][0..bw];
- // Row -1 - i above the moving rows (under the held ones), or bh + i
- // below the body, in grid rows.
- const at_row: i32 = if (lag < 0) @as(i32, y0 + kept.rows) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i));
+ const at_row = sb.leftRow(kept.rows, i);
var at = shifted;
// emitInstance takes an unsigned row: move the layout instead.
at.y_off += @as(f32, @floatFromInt(at_row - @as(i32, y0))) * layout.h;
@@ -4916,16 +4959,7 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g
} else false;
if (grid_bottom < win_h and tag_last) try addDecor(g, gpa, 0, grid_bottom, win_w, win_h, chrome.tag_bg, 1, win_w, win_h);
try paneDecor(g, gpa, regions, surface.rail_ticks[0..surface.nrail_ticks], surface.heat.items, chrome, layout, surface.cols, surface.rows, win_w, win_h);
- // The changes' lanes (jj.paint): a strip a level in the gutter's
- // lane cells, each a third of a cell wide with half that of air
- // before it, so three take one and a half cells (the ruled
- // sample A); whole pixels, so every row's strip lines up.
- for (surface.lanes.items) |lane| {
- const w = @max(1, @round(layout.w / 3));
- const x0 = @round(@as(f32, @floatFromInt(lane.x)) * layout.w + w / 2 + @as(f32, @floatFromInt(lane.level)) * (w + w / 2));
- const y0 = @as(f32, @floatFromInt(lane.y)) * layout.h;
- try addDecor(g, gpa, x0, y0, x0 + w, y0 + layout.h, lane.rgb, 1, win_w, win_h);
- }
+ try laneDecor(g, gpa, surface, layout, win_w, win_h);
// A single spine runs down each column, through every tag and body.
for (regions) |column| {
if (column.kind != .column) continue;
@@ -4955,6 +4989,58 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g
}
}
+/// The changes' lanes (jj.paint): a strip a level in the gutter's lane
+/// cells, each a third of a cell wide with half that of air before it, so
+/// three take one and a half cells (the ruled sample A); whole pixels, so
+/// every row's strip lines up. A scrolling body's ride its rows as
+/// emitScrollRows draws them: the lag less, cut to the body under its held
+/// rows (its scissor), and the rows that left keep theirs in the gap.
+fn laneDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32) !void {
+ const w = @max(1, @round(layout.w / 3));
+ const b = scrollBody(g, surface) orelse {
+ for (surface.lanes.items) |lane| try laneStrip(g, gpa, lane, lane.y, null, w, layout, win_w, win_h);
+ return;
+ };
+ const kept = holdContext(g, surface, b.pane, if (surface.facts.pane(b.pane)) |pane| pane.context_rows else 0, b.bh, layout);
+ const ride: LaneRide = .{
+ .x0 = b.rect.x + config.GUTTER,
+ .x1 = b.rect.x + b.rect.w,
+ .y0 = b.y0 + kept.rows,
+ .y1 = b.y0 + b.bh,
+ .dy = b.lag * layout.h - kept.lift,
+ .top = @as(f32, @floatFromInt(b.y0 + kept.rows)) * layout.h + kept.lift,
+ .bottom = @as(f32, @floatFromInt(b.y0 + b.bh)) * layout.h,
+ };
+ for (surface.lanes.items) |lane| {
+ const rides = lane.x >= ride.x0 and lane.x < ride.x1 and lane.y >= ride.y0 and lane.y < ride.y1;
+ try laneStrip(g, gpa, lane, lane.y, if (rides) &ride else null, w, layout, win_w, win_h);
+ }
+ if (b.gliding) {
+ const rows = if (b.lag < 0) g.glide.above_lanes else g.glide.below_lanes;
+ for (rows[0..b.glideLeft(&g.glide)], 0..) |*row, i| for (row.items()) |lane| try laneStrip(g, gpa, lane, b.leftRow(kept.rows, i), &ride, w, layout, win_w, win_h);
+ } else if (g.scroll_edge_len >= b.rect.w - config.GUTTER) {
+ for (g.scroll_edge_lanes.items()) |lane| try laneStrip(g, gpa, lane, b.leftRow(kept.rows, 0), &ride, w, layout, win_w, win_h);
+ }
+}
+
+/// A scrolling body's moving rows (laneDecor): their columns and rows, how
+/// far up they are drawn, and the pixels they are cut to.
+const LaneRide = struct { x0: u16, x1: u16, y0: u16, y1: u16, dy: f32, top: f32, bottom: f32 };
+
+/// `lane`'s strip, `w` pixels wide, on grid row `row`, riding a scroll's
+/// rows when given one.
+fn laneStrip(g: *Gui, gpa: std.mem.Allocator, lane: pardes.Lane, row: i32, ride: ?*const LaneRide, w: f32, layout: CellLayout, win_w: f32, win_h: f32) !void {
+ const x0 = @round(@as(f32, @floatFromInt(lane.x)) * layout.w + w / 2 + @as(f32, @floatFromInt(lane.level)) * (w + w / 2));
+ var y0 = @as(f32, @floatFromInt(row)) * layout.h;
+ var y1 = y0 + layout.h;
+ if (ride) |r| {
+ y0 = @max(y0 - r.dy, r.top);
+ y1 = @min(y1 - r.dy, r.bottom);
+ if (y1 <= y0) return;
+ }
+ try addDecor(g, gpa, x0, y0, x0 + w, y1, lane.rgb, 1, win_w, win_h);
+}
+
/// Each pane's rule between its tag and body, and its scroll rail: a page
/// coloured gutter with a thin track and its thumb, running down through the
/// pixels past the last whole row.
@@ -6650,6 +6736,121 @@ test "a wheel's caret rides with its line, the text's own glide, never a spring
try std.testing.expectEqual(@as(f32, @floatFromInt(s.cursor.?.y)), caretRow(&g, s, now).?);
}
+/// The active pane's body in a frame.
+fn testBody(core: *pardes.Pardes, s: *const pardes.Surface) pardes.Rect {
+ for (s.regionList()) |region| if (region.kind == .body and region.owner == core.view().active) return region.rect;
+ unreachable;
+}
+
+/// A change's lanes on the active body's rows as jj.paint lays them for a
+/// window (Surface.lanes), for a test: line L's on its row, 1 + L % 3
+/// levels, coloured its line, its level and 0x37, so a strip names its line.
+fn testLanes(gpa: std.mem.Allocator, core: *pardes.Pardes, s: *pardes.Surface) !void {
+ const body = testBody(core, s);
+ const top = core.panes[core.view().active].?.scroll();
+ for (0..body.h) |vr| {
+ const line: usize = @intCast(top + @as(i32, @intCast(vr)));
+ for (0..1 + line % 3) |level|
+ try s.lanes.append(gpa, .{ .x = body.x + 1, .y = body.y + @as(u16, @intCast(vr)), .level = @intCast(level), .rgb = .{ @intCast(line), @intCast(level), 0x37 } });
+ }
+}
+
+/// The frame's lane strips (testLanes') against where their lines are
+/// drawn: line L of a body whose first line is the core's `top`, its rows
+/// `lag` behind (a glide's offset or a touchpad's fraction), at body row
+/// L - top - lag (emitScrollRows), with its strips there, cut to the body;
+/// a line drawn outside it, none.
+fn expectLanesRide(g: *Gui, gpa: std.mem.Allocator, core: *pardes.Pardes, s: *const pardes.Surface, lag: f32) !void {
+ g.decor.clearRetainingCapacity();
+ var groups: Groups = .{};
+ const layout = fixedCellLayout(g);
+ const win_h: f32 = @floatFromInt(@as(u32, s.rows) * g.cell_h);
+ try buildDecor(g, gpa, s, &groups, layout, @floatFromInt(@as(u32, s.cols) * g.cell_w), win_h, false);
+ const body = testBody(core, s);
+ const top = core.panes[core.view().active].?.scroll();
+ const body_y0 = @as(f32, @floatFromInt(body.y)) * layout.h;
+ const body_y1 = @as(f32, @floatFromInt(body.y + body.h)) * layout.h;
+ var strips: [256]u8 = @splat(0);
+ for (g.decor.items) |item| {
+ if (@abs(item.bb * 255 - 0x37) > 0.01 or item.bg * 255 > 2.01) continue;
+ const line: u8 = @intFromFloat(@round(item.br * 255));
+ const at = (@as(f32, @floatFromInt(body.y)) + @as(f32, @floatFromInt(@as(i32, line) - top)) - lag) * layout.h;
+ try std.testing.expectApproxEqAbs(@max(at, body_y0), (1 - item.y0) / 2 * win_h, 0.01);
+ try std.testing.expectApproxEqAbs(@min(at + layout.h, body_y1), (1 - item.y1) / 2 * win_h, 0.01);
+ strips[line] += 1;
+ }
+ for (strips, 0..) |n, line| {
+ const at = (@as(f32, @floatFromInt(body.y)) + @as(f32, @floatFromInt(@as(i32, @intCast(line)) - top)) - lag) * layout.h;
+ const shown = @min(at + layout.h, body_y1) - @max(at, body_y0);
+ // A sliver under a hundredth of a pixel either way.
+ if (@abs(shown) < 0.01) continue;
+ try std.testing.expectEqual(@as(usize, if (shown > 0) 1 + line % 3 else 0), n);
+ }
+}
+
+test "a change's lanes ride their lines: mid-glide (a wheel's notch, Ctrl-d) and under a touchpad's fraction each strip is where its line is drawn, cut to the body, and the rows that left keep theirs" {
+ const gpa = std.testing.allocator;
+ {
+ const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
+ defer core.deinit();
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (0..200) |i| try text.print(gpa, "line {d}\n", .{i});
+ _ = try core.setTestFile(text.items);
+ for ("100G") |ch| core.update(.{ .key = .{ .cp = ch, .text = &.{ch} } });
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var g = testGui(10, 20, 6, 12);
+ defer g.glide.deinit(gpa);
+ defer g.decor.deinit(gpa);
+ const r = core.view().rects[core.view().active];
+ g.scroll_pane = core.view().active;
+ g.scroll_col = r.x + 10;
+ g.scroll_row = r.y + r.h - 2;
+ var now: u64 = std.time.ns_per_s;
+ var mid: usize = 0;
+ // The view drawn once at rest, then a notch down (the wheel's) and
+ // Ctrl-d, each glided to rest, every frame checked.
+ for ([_]?pardes.Key{ null, null, .{ .cp = 'd', .ctrl = true } }, 0..) |key, step| {
+ if (key) |k| core.update(.{ .key = k }) else if (step > 0) g.scroll_notch = 1;
+ var frames: usize = 0;
+ while (true) : (frames += 1) {
+ stepGlide(&g, core);
+ now += std.time.ns_per_s / 60;
+ core.advance(now);
+ _ = arena.reset(.retain_capacity);
+ const s = try core.render(arena.allocator());
+ try testLanes(gpa, core, s);
+ g.now_ns = now;
+ glideFrame(&g, gpa, s);
+ if (g.glide.follow.offset != 0) mid += 1;
+ try expectLanesRide(&g, gpa, core, s, g.glide.follow.offset);
+ if (!g.glide.moving()) break;
+ if (frames > 200) return error.NeverSettled;
+ }
+ }
+ try std.testing.expect(mid > 10);
+ }
+ // A touchpad's half notch down, settled, then up: the text half a row
+ // off its cells, and the row that left in the half row it opens.
+ const core = try wheelRunFile(gpa);
+ defer core.deinit();
+ var wr = try WheelRun.init(gpa, core);
+ defer wr.deinit(gpa);
+ defer wr.g.decor.deinit(gpa);
+ wr.lanes = true;
+ core.needs_frame = true;
+ try wr.frame(gpa, &.{});
+ for ([_]f32{ -0.5, 0.5 }) |turn| {
+ try wr.frame(gpa, &.{turn});
+ try std.testing.expectEqual(turn, wr.g.scroll_lag);
+ try expectLanesRide(&wr.g, gpa, core, wr.g.frame.?, wr.g.scroll_lag);
+ for (0..20) |_| try wr.frame(gpa, &.{});
+ try std.testing.expectEqual(@as(f32, 0), wr.g.scroll_lag);
+ try expectLanesRide(&wr.g, gpa, core, wr.g.frame.?, 0);
+ }
+}
+
test "every scroll glides on one law: a half page, a page, the far jumps, a run of them retargeting" {
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 100, .rows = 40 });