From 3488111273764c17a42870484fabc36abb0634a1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 13:56:13 -0300 Subject: effects out, the core's motion: the view's glide is the frontends' alone, and the core keeps no motion and no clock but its deadlines; glide.zig is a frontend's picture of a scroll, measured on the frame it is about to draw against the last it drew (a body's first line and the text it shows in its region, Region.doc new; the last frame's cells kept by the glide itself), on the frontend's own clock, the tty drawing it at whole rows and the window at the pixel; each frontend draws its own motions' frames from the last frame (the tty's poll presents it again, the window's loop renders it again, as its blink did) and paces its own waits, so the core's continuous path goes (Pardes.continuous and shell_continuous, the pump's one-millisecond wait, the view's drawn fields, the tape's watch of it); the Motion word and its five flavours go (the glide and the caret move at the default's pace, and no switch for reduced motion is left), and animation.zig with them (Motion and Spring gone, Follow now glide.zig's with its test, CursorGlide gone with the core's caret, Blink the window's with its test, Box and layout.panelBox gone, the frame's length now Pardes.frame_ns); a PDF strip no longer glides, its scroll landing at once (its follow, stripAt's motion and Pdf.moving go); the window's glide tests are fed frame by frame as the window feeds them; the window monkey runs by seed, not by flavour, and the 9P monkey loses Motion; the tty wakes a frame at a time while its glide or trail moves, as the core's continuous path woke it; all 109 snapshot goldens and the 16 GUI goldens unchanged; tests gone: a carried spring keeps its speed; a spring settles without overshoot; each flavour is its own motion; a cursor eases a cell at a time (animation.zig's); a PDF strip glides a notch and a page to their marks; a PDF glide renders the pages it crosses Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/pdf_view.zig | 137 ++++++++----------------------------------------------- 1 file changed, 18 insertions(+), 119 deletions(-) (limited to 'src/pdf_view.zig') diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 5a371720..e615521d 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -193,81 +193,6 @@ test "PDF selections retain their owning page across page focus" { try std.testing.expectEqual(@as(usize, 0), state.selection_text.len); } -test "a PDF strip glides a notch and a page to their marks, eased and never past them, and follows a touchpad's fraction at once" { - if (comptime !enabled) return; - const gpa = std.testing.allocator; - var state = try State.open(gpa, "docs/design.pdf", 1); - defer state.deinit(gpa); - const view: Viewport = .{ .pixel_w = 800, .pixel_h = 600 }; - const motion = pardes.animation.Motion.of(.smooth); - ensureLayout(&state, view); - var now: u64 = std.time.ns_per_s; - try std.testing.expectEqual(state.document_scroll_y, stripAt(&state, view, motion, now)); - for ([_]f64{ 20, 600 }) |step| { - const from = state.document_scroll_y; - _ = scrollDocument(&state, view, step); - const mark = state.document_scroll_y; - // The input's frame still shows where it was; then it eases in. - var shown = stripAt(&state, view, motion, now); - try std.testing.expectEqual(from, shown); - var last_step: f64 = 0; - var peaked = false; - for (0..60) |_| { - now += pardes.animation.frame_ns; - const next = stripAt(&state, view, motion, now); - const moved = next - shown; - try std.testing.expect(moved >= 0 and next <= mark); - // Past its fastest, each frame's step is no longer than the last. - if (moved < last_step) peaked = true; - if (peaked) try std.testing.expect(moved <= last_step + 1e-9); - last_step = moved; - shown = next; - } - try std.testing.expectEqual(mark, shown); - try std.testing.expect(!state.follow.moving()); - try std.testing.expect(last_step <= 1); - } - // A touchpad's fraction: drawn where the core is, the same frame. - const from = state.document_scroll_y; - _ = scrollDocument(&state, view, 0.25); - state.direct_y += state.document_scroll_y - from; - try std.testing.expectEqual(from + 0.25, stripAt(&state, view, motion, now)); -} - -test "a PDF glide renders the pages it crosses in its input's frame, but a far jump's only where it comes to rest" { - if (comptime !enabled) return; - const gpa = std.testing.allocator; - var state = try State.open(gpa, "docs/design.pdf", 1); - defer state.deinit(gpa); - var arena: std.heap.ArenaAllocator = .init(gpa); - defer arena.deinit(); - const view: Viewport = .{ .pixel_w = 400, .pixel_h = 300 }; - const motion = pardes.animation.Motion.of(.smooth); - const key: TintKey = .{ .mode = .disabled, .colors = undefined }; - const none: HighlightInput = .{ .hover_color = .{ 0, 0, 0 }, .selection_color = .{ 0, 0, 0 } }; - ensureLayout(&state, view); - const frame = struct { - fn f(st: *State, a: *std.heap.ArenaAllocator, m: pardes.animation.Motion, k: TintKey, h: HighlightInput) void { - const v: Viewport = .{ .pixel_w = 400, .pixel_h = 300 }; - const shown = stripAt(st, v, m, std.time.ns_per_s); - st.document_scroll_y = shown; - _ = renderFrame(st, std.testing.allocator, a.allocator(), v, pardes.pdf_raster_policy, k, h, st.drawn_y - shown, st.far); - st.document_scroll_y = st.drawn_y; - } - }.f; - frame(&state, &arena, motion, key, none); - // A body down, onto page one's lower part: what it crosses is drawn. - _ = scrollDocument(&state, view, 300); - frame(&state, &arena, motion, key, none); - try std.testing.expect(!state.far and rasterForPage(&state, 0) != null); - // Far, to page three: only it; the slide comes in over page two's place. - state.document_scroll_y = @floatFromInt(state.page_starts[3]); - frame(&state, &arena, motion, key, none); - try std.testing.expect(state.far); - try std.testing.expect(rasterForPage(&state, 3) != null); - try std.testing.expect(rasterForPage(&state, 2) == null); -} - test "off the loop: pages land from lanes, a stale request's raster never lands, and a job nobody waits for is aborted" { if (comptime !enabled) return; const gpa = std.testing.allocator; @@ -631,11 +556,8 @@ pub const State = if (enabled) struct { layout_fit: FitMode = .width, layout_valid: bool = false, document_scroll_y: f64 = 0, - /// The strip as drawn lags `document_scroll_y` by `follow` (anim 11, - /// the text's motion system, in pixels): `drawn_y` is where the core - /// stood at the last frame, `direct_y` what moved it since that the - /// picture takes as it comes (a touchpad, a relayout). - follow: pardes.animation.Follow = .{}, + /// Where the core stood at the last frame (`drawn_y`), and what moved + /// it since by the pixel (`direct_y`: a touchpad, a relayout). drawn_y: f64 = 0, direct_y: f64 = 0, /// The last kick was a jump past a body (renderFrame's `far`). @@ -2540,7 +2462,6 @@ pub fn ensureLayout(state: *State, viewport: Viewport) void { state.drawn_y += state.document_scroll_y - before; state.relayout_keeps_motion = false; } else if (relaid) { - state.follow = .{}; state.drawn_y = state.document_scroll_y; state.direct_y = 0; } @@ -2973,10 +2894,9 @@ pub fn placeY(pane: *const pardes.Pane, at: Place) ?f64 { @as(f64, @floatFromInt(at.at)) / place_scale * @as(f64, @floatFromInt(state.page_heights[page])); } -/// A jump to `at` (Back, Forward): the core is there at once and the strip -/// follows through the motion system, a far one as one body's slide, the -/// page rendered where it comes to rest. Not laid out yet (a pane just -/// reopened), it is anchored there for the first layout. +/// A jump to `at` (Back, Forward): the strip is there at once. Not laid +/// out yet (a pane just reopened), it is anchored there for the first +/// layout. pub fn landAt(core: *pardes.Pardes, pane: *pardes.Pane, at: Place) void { if (comptime !enabled) return; const state = pane.pdf orelse return; @@ -3330,8 +3250,8 @@ pub fn highlightInput( }; } -/// `glide`: a notch, which the strip glides; else a touchpad's fraction, -/// which it follows as it comes. +/// `glide`: a notch; else a touchpad's fraction, counted as moved by the +/// pixel (`direct_y`). pub fn scrollPane(core: *pardes.Pardes, pane: *pardes.Pane, delta_pixels: f64, glide: bool) bool { if (comptime !enabled) return false; const tz = tracy.zone(@src(), "pdf.scroll_notch"); @@ -3345,33 +3265,16 @@ pub fn scrollPane(core: *pardes.Pardes, pane: *pardes.Pane, delta_pixels: f64, g return true; } -/// Where the strip is drawn this frame (anim 11): what moved the core's -/// position since the last frame kicks its follow, as a scroll kicks the -/// text's, all but what moved it directly; the follow then moves on to now. -fn stripAt(state: *State, view: Viewport, motion: pardes.animation.Motion, now_ns: u64) f64 { - const pace = pardes.animation.Follow.pace(motion, @floatFromInt(view.pixel_h), 0.1); - const moved = state.document_scroll_y - state.drawn_y - state.direct_y; +/// Where the strip is drawn this frame: where the core stands, a scroll +/// landing at once; which way it went, for the page rendered ahead. +fn stripAt(state: *State, view: Viewport) f64 { + const moved = state.document_scroll_y - state.drawn_y; + if (moved != 0) state.ahead = if (moved > 0) 1 else -1; state.drawn_y = state.document_scroll_y; state.direct_y = 0; - if (motion.instant) { - state.follow = .{}; - } else if (moved != 0) { - // A move past a body slides one, as a text's far jump does (G6): - // the pages between are rendered for the slide, not crossed. - const body: f64 = @floatFromInt(view.pixel_h); - state.far = @abs(moved) > body; - state.ahead = if (moved > 0) 1 else -1; - state.follow.kick(@floatCast(std.math.clamp(moved, -body, body)), now_ns, pace); - } else state.follow.advance(now_ns, pace); + state.far = false; const max_scroll = @as(f64, @floatFromInt(state.document_height -| view.pixel_h)); - return std.math.clamp(state.drawn_y + state.follow.offset, 0, max_scroll); -} - -/// A PDF strip is still on its way to where the core stands. -pub fn moving(core: *const pardes.Pardes) bool { - if (comptime !enabled) return false; - for (core.panes) |slot| if (slot) |pane| if (pane.pdf) |state| if (state.follow.moving()) return true; - return false; + return std.math.clamp(state.drawn_y, 0, max_scroll); } pub fn verticalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) void { @@ -3413,10 +3316,9 @@ pub fn draw( const key = TintKey{ .mode = state.tint, .colors = tintColors(core) }; applySizes(state, core.pdf_gpa); ensureLayout(state, view); - // Drawn where the strip's follow is; the core's position comes back - // after (`drawn_y`), unless a search's reveal moved it as it drew, - // which is then drawn there at once. - const shown = stripAt(state, view, pardes.animation.Motion.of(core.settings.motion), core.now_ns); + // Drawn where the core stands (`drawn_y`), unless a search's reveal + // moved it as it drew, which is then drawn there. + const shown = stripAt(state, view); state.document_scroll_y = shown; defer state.document_scroll_y = state.drawn_y; if (pane_id == core.active) core.frames.scroll = @floatCast(shown); @@ -3435,10 +3337,7 @@ pub fn draw( state.drawn_y - shown, state.far, ); - if (state.document_scroll_y != shown) { - state.follow = .{}; - state.drawn_y = state.document_scroll_y; - } + if (state.document_scroll_y != shown) state.drawn_y = state.document_scroll_y; var placed_any = false; var page = visible.first; const visible_end = visible.first + visible.len; -- cgit v1.3