From 9656105cb4c902213f281e658dd88286cc2df8ed Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 13 Nov 2026 15:10:16 -0300 Subject: debugger: link register hints and profile smooth native rendering --- gui/src/Navigation.zig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'gui/src/Navigation.zig') diff --git a/gui/src/Navigation.zig b/gui/src/Navigation.zig index 7edd4d9..da888ad 100644 --- a/gui/src/Navigation.zig +++ b/gui/src/Navigation.zig @@ -64,3 +64,35 @@ test "large mapping row history keeps individual words reachable" { n.back(); try std.testing.expectEqual(@as(f64, 268435454), n.place.row); } + +/// A retargetable scroll with a fixed 200 ms deadline, independent of frame rate. +pub const Scroll = struct { + from: f64 = 0, + target: f64 = 0, + started: u64 = 0, + + pub fn sample(s: *Scroll, current: f64, target: f64, now: u64, max_travel: f64) f64 { + if (s.target != target) s.* = .{ .from = current, .target = target, .started = now }; + if (@abs(current - target) > max_travel) s.from = target; + const t = @min(1, @as(f64, @floatFromInt(now -| s.started)) / 200_000_000); + const remaining = 1 - t; + return std.math.lerp(s.from, target, 1 - remaining * remaining * remaining); + } +}; + +test "scroll timing is independent of cadence, settles exactly and retargets continuously" { + var a: Scroll = .{}; + var b: Scroll = .{}; + var x = a.sample(0, 12, 1_000_000_000, 100); + var y = b.sample(0, 12, 1_000_000_000, 100); + for (1..21) |i| x = a.sample(x, 12, 1_000_000_000 + i * 10_000_000, 100); + y = b.sample(y, 12, 1_200_000_000, 100); + try std.testing.expectEqual(@as(f64, 12), x); + try std.testing.expectEqual(x, y); + try std.testing.expectEqual(x, a.sample(x, 24, 1_250_000_000, 100)); + x = a.sample(x, 24, 1_350_000_000, 100); + try std.testing.expectEqual(@as(f64, 22.5), x); + try std.testing.expectEqual(x, a.sample(x, 6, 1_350_000_000, 100)); + try std.testing.expectEqual(@as(f64, 6), a.sample(x, 6, 1_550_000_000, 100)); + try std.testing.expectEqual(@as(f64, 1000000), a.sample(6, 1000000, 1_600_000_000, 100)); +} -- cgit v1.3