summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 22:50:15 -0300
committerGabriel Schneider <[email protected]>2026-10-25 01:30:09 -0300
commit6e8a6a63d45b2caef7b649d358f836e6cc4134d6 (patch)
tree0c1259e1fa04e72a8ccb9df18b2811dd94083098 /src/gui
parent0dc2dc053af20d6811bfbe09ab31b762862a53a6 (diff)
downloadpardes-6e8a6a63d45b2caef7b649d358f836e6cc4134d6.tar.gz
pardes-6e8a6a63d45b2caef7b649d358f836e6cc4134d6.zip
anim 11: a PDF's strip moves in the text's motion system: the integrator is animation.Follow (the Glide's, moved out), here the strip's lag behind document_scroll_y in pixels; whatever moves the core's position (a notch, a spin, PageDown, Ctrl-d/f, ge/gg, a Look at a page, Back, the rail) kicks it, a touchpad's fraction and a relayout move it directly; the pages a glide crosses render in its input's frame, a far jump's only where it comes to rest; a slow stream eases onto its mark (it ran into it at speed and passed it); pictures neither scroll nor pan
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig154
1 files changed, 48 insertions, 106 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 3f7dd7ca..94eabb6c 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -3617,6 +3617,7 @@ fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void {
in.post(.{ .pdf_scroll = .{
.pane = @intCast(id),
.delta_pixels = -w.y * @as(f32, @floatFromInt(g.cell_h)),
+ .glide = notchOf(w.y, w.integer_y) != null,
} });
} else if (!w.mods.shift and pane.isTerminal() and pardes.panes.terminal.ownsWheel(pane)) {
// The program's (codex, htop, less): every whole
@@ -4338,6 +4339,10 @@ fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void {
core.frames.input(now);
wheelAt(g, in, .{ .y = @floatFromInt(-notches), .integer_y = -notches }, .{ .col = r.x + r.w / 2, .row = r.y + r.h / 2 });
},
+ .touch => |lines| {
+ core.frames.input(now);
+ wheelAt(g, in, .{ .y = -lines }, .{ .col = r.x + r.w / 2, .row = r.y + r.h / 2 });
+ },
.key => |key| {
core.frames.input(now);
in.post(.{ .key = key });
@@ -5061,16 +5066,8 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
/// (an ease, a turn through zero); a jump mid-glide adds its rows with the
/// speed kept. The spring's settle only comes once the inputs stop.
const Glide = struct {
- /// The picture's offset from the core's rows now (rows; negative, the
- /// picture still shows what is above), its speed (offset's rows a
- /// second), and when it was last integrated.
- offset: f32 = 0,
- speed: f32 = 0,
- at_ns: u64 = 0,
- /// What has been feeding it: the rows of the last inputs (down
- /// positive), their spacing, the last's time, and how many came as one
- /// stream.
- feed: struct { rows: f32 = 0, gap_ns: u64 = 0, last_ns: u64 = 0, count: u16 = 0 } = .{},
+ /// The picture's lag behind the core's rows and its motion (rows).
+ follow: pardes.animation.Follow = .{},
now_ns: u64 = 0,
pane: usize = 0,
rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 },
@@ -5100,21 +5097,16 @@ const Glide = struct {
/// whatever moved it.
seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i64 = 0, file: u64 = 0, revision: u32 = 0 } = @splat(.{}),
- /// How far the picture may lag, in bodies: the rows kept past each
- /// edge, so a jump made while one glides carries on from where it is.
- const reach = 2;
- const bodies_per_s: f32 = 15;
- /// Inputs this close, each the way the last went, are one stream.
- const stream_ns = 150 * std.time.ns_per_ms;
+ /// The rows kept past each edge, in bodies, so a jump made while one
+ /// glides carries on from where it is: as far as the picture may lag.
+ const reach = pardes.animation.Follow.reach;
fn moving(glide: *const Glide) bool {
- return glide.offset != 0 or glide.speed != 0 or glide.pending;
+ return glide.follow.moving() or glide.pending;
}
fn stop(glide: *Glide) void {
- glide.speed = 0;
- glide.feed = .{};
- glide.offset = 0;
+ glide.follow = .{ .at_ns = glide.follow.at_ns };
glide.pending = false;
glide.nabove = 0;
glide.nbelow = 0;
@@ -5126,8 +5118,8 @@ const Glide = struct {
/// The glide's lag in the core's lines: its rows, scaled by the lines
/// they carried.
fn lagLines(glide: *const Glide) f32 {
- if (glide.rows_moved == 0) return glide.offset;
- return glide.offset * glide.lines_moved / glide.rows_moved;
+ if (glide.rows_moved == 0) return glide.follow.offset;
+ return glide.follow.offset * glide.lines_moved / glide.rows_moved;
}
fn deinit(glide: *Glide, gpa: std.mem.Allocator) void {
@@ -5140,70 +5132,18 @@ const Glide = struct {
return glide.rect.w -| config.GUTTER;
}
- /// An input: the core's rows moved by `rows` (down positive) since the
- /// last frame. The picture now lags by as many more, its speed as it was.
+ /// The rules at this body's size: a tenth of a pixel is 5e-3 rows.
+ fn pace(glide: *const Glide, motion: pardes.animation.Motion) pardes.animation.Follow.Pace {
+ return pardes.animation.Follow.pace(motion, @floatFromInt(glide.body_h), 5e-3);
+ }
+
+ /// An input: the core's rows moved by `rows` (down positive).
fn kick(glide: *Glide, rows: f32, now_ns: u64, motion: pardes.animation.Motion) void {
- glide.advance(now_ns, motion);
- // Never more than `reach` bodies behind: a flick past that jumps.
- const limit: f32 = @floatFromInt(@as(u32, glide.body_h) * reach);
- glide.offset = std.math.clamp(glide.offset - rows, -limit, limit);
- const f = &glide.feed;
- const like = f.count > 0 and (rows > 0) == (f.rows > 0) and now_ns -| f.last_ns < stream_ns;
- if (like) {
- const gap = now_ns -| f.last_ns;
- f.gap_ns = if (f.count == 1) gap else (f.gap_ns + gap) / 2;
- f.rows = (f.rows + rows) / 2;
- f.count +|= 1;
- } else f.* = .{ .rows = rows, .count = 1 };
- f.last_ns = now_ns;
+ glide.follow.kick(rows, now_ns, glide.pace(motion));
}
- /// The system moved on to `now_ns`. Fed by a stream, at the stream's
- /// rate (rows an input over their spacing), held a lag `lead` behind
- /// the text so a late input never finds it stopped and the stream's end
- /// never runs it past its mark; else on the flavour's spring at 1.5x
- /// its pace, critically damped, from the speed it has. Never more than
- /// `bodies_per_s` of the body a second, so moving text stays readable.
fn advance(glide: *Glide, now_ns: u64, motion: pardes.animation.Motion) void {
- const dt: f32 = @floatCast(@as(f64, @floatFromInt(@min(now_ns -| glide.at_ns, 2 * pardes.animation.frame_ns))) / std.time.ns_per_s);
- glide.at_ns = now_ns;
- if (glide.offset == 0 and glide.speed == 0) return;
- const omega = motion.omega * 1.5;
- const cap = @as(f32, @floatFromInt(glide.body_h)) * bodies_per_s;
- const toward: f32 = if (glide.offset < 0) 1 else -1;
- const f = glide.feed;
- if (f.count >= 2 and f.gap_ns > 0 and now_ns -| f.last_ns < f.gap_ns * 3 / 2) {
- const gap: f32 = @floatCast(@as(f64, @floatFromInt(f.gap_ns)) / std.time.ns_per_s);
- const rate = @abs(f.rows) / gap;
- const lead = @max(@abs(f.rows), rate / omega);
- // ponytail: a gentle pull to the lead (a tenth an input), so the
- // per-frame step varies by a tenth; a stream's own jitter beyond
- // that shows. An estimate of the input clock if it ever matters.
- const v = std.math.clamp(rate + 0.1 / gap * (@abs(glide.offset) - lead), 0, cap);
- const step = @min(v * dt, @abs(glide.offset));
- glide.offset += toward * step;
- glide.speed = toward * v;
- return;
- }
- const x = glide.offset;
- // Coming to rest from a stream: never faster than the spring's own
- // pace from here (omega a row of lag a second), so it eases in and
- // does not pass its mark.
- if (glide.speed * x < 0 and @abs(glide.speed) > omega * @abs(x)) glide.speed = std.math.sign(glide.speed) * omega * @abs(x);
- const lead_v = glide.speed + omega * x;
- const decay = @exp(-omega * dt);
- var next = (x + lead_v * dt) * decay;
- var speed = (glide.speed - omega * dt * lead_v) * decay;
- if (@abs(next - x) > cap * dt) {
- next = x + std.math.sign(next - x) * cap * dt;
- speed = std.math.sign(next - x) * cap;
- }
- glide.offset = next;
- glide.speed = speed;
- if (@abs(next) < 5e-3 and @abs(speed) < 5e-2) {
- glide.offset = 0;
- glide.speed = 0;
- }
+ glide.follow.advance(now_ns, glide.pace(motion));
}
/// Finds how far the pane's body rows moved, `dir` rows at a time, by
@@ -5307,11 +5247,11 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
defer core.shell_continuous = glide.moving() or g.sel_glow.fading or g.hover_glow.fading;
glide.now_ns = core.now_ns;
glide.motion = pardes.animation.Motion.of(core.settings.motion);
- if (glide.offset != 0 or glide.speed != 0) {
+ if (glide.follow.offset != 0 or glide.follow.speed != 0) {
glide.advance(core.now_ns, glide.motion);
core.needs_frame = true;
- if (glide.offset == 0) {
- glide.offset = 0;
+ if (glide.follow.offset == 0) {
+ glide.follow.offset = 0;
glide.nabove = 0;
glide.nbelow = 0;
glide.lines_moved = 0;
@@ -5425,16 +5365,16 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde
g.scroll_body_y = y0;
g.scroll_body_h = bh;
var shifted = layout;
- shifted.y_off -= glide.offset * layout.h;
+ shifted.y_off -= glide.follow.offset * layout.h;
const kept = holdContext(g, surface, glide.pane, held, bh, layout);
shifted.y_off += kept.lift;
var n: u32 = 0;
// Only the rows the scissor shows: lagging a body or more, every body
// row is past the edge, and drawing them all was twice the frame's
// instances for the length of a long glide.
- const lag: u16 = @intFromFloat(@min(@floor(@abs(glide.offset)), @as(f32, @floatFromInt(bh))));
- var row = y0 + kept.rows + if (glide.offset > 0) lag else 0;
- const row_end = y0 + bh - if (glide.offset < 0) lag else 0;
+ const lag: u16 = @intFromFloat(@min(@floor(@abs(glide.follow.offset)), @as(f32, @floatFromInt(bh))));
+ var row = y0 + kept.rows + if (glide.follow.offset > 0) lag else 0;
+ const row_end = y0 + bh - if (glide.follow.offset < 0) lag else 0;
while (row < row_end) : (row += 1) {
const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols];
const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null;
@@ -5448,13 +5388,13 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde
}
// The gap: 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(glide.offset)), @as(f32, @floatFromInt(@as(u32, bh) * Glide.reach))));
- const nkept = if (glide.offset < 0) glide.nabove else glide.nbelow;
- const rows = if (glide.offset < 0) glide.above else glide.below;
+ const gap: u16 = @intFromFloat(@min(@ceil(@abs(glide.follow.offset)), @as(f32, @floatFromInt(@as(u32, bh) * Glide.reach))));
+ const nkept = if (glide.follow.offset < 0) glide.nabove else glide.nbelow;
+ const rows = if (glide.follow.offset < 0) glide.above else glide.below;
for (0..@min(gap, nkept)) |i| {
const cells = rows[i * bw ..][0..bw];
// Row -1 - i above the body, or bh + i below it, in grid rows.
- const at_row: i32 = if (glide.offset < 0) @as(i32, y0) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i));
+ const at_row: i32 = if (glide.follow.offset < 0) @as(i32, y0) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(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;
@@ -5514,7 +5454,7 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe
g.glide.measure(gpa, s);
// Its two rows: the picture two rows behind, the rows that left kept,
// nearest first.
- try std.testing.expectApproxEqAbs(@as(f32, -2), g.glide.offset, 1e-4);
+ try std.testing.expectApproxEqAbs(@as(f32, -2), g.glide.follow.offset, 1e-4);
try std.testing.expectEqual(@as(u16, 2), g.glide.nabove);
try std.testing.expect(sameRow(g.glide.above[0 .. r.w - config.GUTTER], row_before));
// Frame by frame it comes back, never past, and settles.
@@ -5523,11 +5463,11 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe
now += 7 * ms;
core.advance(now);
stepGlide(&g, core, gpa);
- try std.testing.expect(g.glide.offset <= 1e-4);
+ try std.testing.expect(g.glide.follow.offset <= 1e-4);
if (frames > 200) return error.NeverSettled;
}
try std.testing.expect(frames > 5);
- try std.testing.expectEqual(@as(f32, 0), g.glide.offset);
+ try std.testing.expectEqual(@as(f32, 0), g.glide.follow.offset);
try std.testing.expect(!core.shell_continuous);
// Motion off: a notch lands at once.
core.settings.motion = .off;
@@ -5560,7 +5500,7 @@ const GlideRun = struct {
const s = try core.render(arena.allocator());
if (g.glide.pending) g.glide.measure(gpa, s);
if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion);
- seq.offsets[frame] = g.glide.offset;
+ seq.offsets[frame] = g.glide.follow.offset;
seq.lines[frame] = @intCast(core.panes[core.active].?.file.?.scroll);
seq.carets[frame] = caretRow(g, s) orelse -1;
seq.cells[frame] = if (s.cursor) |cu| @floatFromInt(cu.y) else -1;
@@ -5809,7 +5749,7 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 {
g.scroll_held_px = 0;
- if (g.glide.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held);
+ if (g.glide.follow.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held);
const scroll_pane = g.scroll_pane orelse return 0;
if (g.scroll_lag == 0) return 0;
for (surface.panelTracks()) |track|
@@ -6436,7 +6376,7 @@ fn renderFrame(
if (chrome.fx & 8 != 0 and chrome.decor_dots != null) for (surface.regionList()) |region| {
if (region.kind != .body or cell_decor.nbodies == cell_decor.bodies.len) continue;
var rows: f32 = @floatFromInt(region.line);
- if (g.glide.moving() and g.glide.pane == region.owner) rows += g.glide.offset;
+ if (g.glide.moving() and g.glide.pane == region.owner) rows += g.glide.follow.offset;
const period = cell_decor.uniforms[4];
cell_decor.bodies[cell_decor.nbodies] = bodyPixels(region, layout);
cell_decor.shifts[cell_decor.nbodies] = @mod(-rows * layout.h * 0.25, period);
@@ -6463,12 +6403,14 @@ fn renderFrame(
const blink_alpha: f32 = if (blinkNow(g, chrome)) |b| b.alpha else 1;
// While a glide moves the text, the caret is its quad, drawn from its
// own springs, not a cell of the moving rows.
- const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1 or g.glide.offset != 0);
+ const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1 or g.glide.follow.offset != 0);
g.cursor_quad_alpha = if (quad_mode) chrome.cursor_alpha * blink_alpha else 0;
// The probe's view of this frame's motion (FrameStats.Frame).
if (core) |p| {
const probe = &@constCast(p).frames;
- probe.scroll = g.glide.offset;
+ // A focused PDF's strip is the core's (pdf_view.draw).
+ const pdf_focus = if (p.panes[p.active]) |pane| pane.hasPdf() else false;
+ if (!pdf_focus) probe.scroll = g.glide.follow.offset;
probe.caret = caretRow(g, surface) orelse 0;
}
const cursors_shown = groups.tracks == 0 and !quad_mode;
@@ -6726,7 +6668,7 @@ fn renderFrame(
for (groups.items[0..groups.len], 0..) |group, index|
std.debug.assert(cell_next[index] == group.cell_start + group.cell_count);
// The body's context rows, which its scroll leaves where they are.
- const scrolling: ?usize = if (g.glide.offset != 0) g.glide.pane else g.scroll_pane;
+ const scrolling: ?usize = if (g.glide.follow.offset != 0) g.glide.pane else g.scroll_pane;
const held: u16 = if (core) |p| if (scrolling) |id| if (p.panes[id]) |pane| pane.context_rows else 0 else 0 else 0;
shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held);
// Over a theme's plaques a see-through cell with no ink blends to
@@ -9620,7 +9562,7 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ti
if (rail.thumb_h != 0 and rail.thumb_span > 0) {
// In pixels, not rows, and with the picture while it glides
// or lags behind the core's rows (both in rows of the body).
- const lag: f32 = if (g.glide.offset != 0 and g.glide.pane == rail.owner)
+ const lag: f32 = if (g.glide.follow.offset != 0 and g.glide.pane == rail.owner)
g.glide.lagLines()
else if (g.scroll_pane != null and g.scroll_pane.? == rail.owner) g.scroll_lag else 0;
const track_px = body_y1 - y0;
@@ -10261,13 +10203,13 @@ test "the scrollbar thumb moves by the pixel and follows a glide" {
// A line of a thousand moves it a fraction of a row, not 0 or 20 px.
try std.testing.expect(at11 > at10 and at11 - at10 < 1);
g.glide.pane = core.active;
- g.glide.offset = -1;
+ g.glide.follow.offset = -1;
try std.testing.expectApproxEqAbs(at10, try thumb.top(&g, core), 1e-3);
// A wrapped line: the picture moved two rows for the one line, and the
// thumb lags the line, not two.
g.glide.lines_moved = 1;
g.glide.rows_moved = 2;
- g.glide.offset = -2;
+ g.glide.follow.offset = -2;
try std.testing.expectApproxEqAbs(at10, try thumb.top(&g, core), 1e-3);
}
@@ -10757,7 +10699,7 @@ const max_cursors = 1 + pardes.MAX_PANES + pardes.MAX_TAG_LAYERS;
fn caretRow(g: *const Gui, surface: *const pardes.Surface) ?f32 {
const chrome = &surface.chrome;
const cursor = surface.cursor orelse return null;
- const quad = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or g.glide.offset != 0);
+ const quad = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or g.glide.follow.offset != 0);
return if (quad) chrome.cursor_quad[1] else @floatFromInt(cursor.y);
}