summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-07 20:53:47 -0300
committerGabriel Schneider <[email protected]>2026-11-07 20:54:11 -0300
commit48903ba5bfd1017377040474ec269197d7ac8eae (patch)
treefd4c13622b5c75ca52c6e4da93efc45aa8075baf /src
parentd1cc6d5e33107396d1e34fdf0ec4fdbed3814199 (diff)
downloadpardes-48903ba5bfd1017377040474ec269197d7ac8eae.tar.gz
pardes-48903ba5bfd1017377040474ec269197d7ac8eae.zip
gui: a fine wheel's or a touchpad's turns that stop at a fraction settle onto a whole row: two loop steps with no turn (SDL tells no gesture's end), scroll_lag eases onto the core's row on the glide's law, which is the next row the way the turns went, so the settle never moves against them, and a turn mid-settle goes on from where it got; the picture no longer rests a fraction of a row off its cells; a gui test ends a burst at a quarter row and turns again mid-settle
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui.zig67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 80fdb39b..1873778a 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1021,6 +1021,9 @@ 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,
+ /// 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,
/// G6: a wheel's notches, whole lines, scroll the core at once and the
/// picture follows on a spring (Glide), never the other way round.
scroll_notch: i32 = 0,
@@ -4649,6 +4652,45 @@ test "a wheel turned down then up never draws the picture moving against the tur
}
}
+test "a fine wheel's turns that stop at a fraction leave the text on a whole row, and a turn mid-settle is not lost" {
+ const gpa = std.testing.allocator;
+ const core = try wheelRunFile(gpa);
+ defer core.deinit();
+ var wr = try WheelRun.init(gpa, core);
+ defer wr.deinit(gpa);
+ const line = struct {
+ fn of(p: *pardes.Pardes) i64 {
+ return @intCast(p.panes[p.view().active].?.scroll());
+ }
+ }.of;
+ const first = line(core);
+ // Three quarter notches down, a frame each: the core a line on, the
+ // picture a quarter row behind it. Then nothing: it eases onto the
+ // core's row (never back against the turns) and rests there, drawn.
+ for (0..3) |_| try wr.frame(gpa, &.{-0.25});
+ try std.testing.expect(wr.g.scroll_lag != 0);
+ var frames: usize = 0;
+ while (wr.g.scroll_lag != 0) : (frames += 1) {
+ const was = wr.drawn;
+ try wr.frame(gpa, &.{});
+ try std.testing.expect(wr.drawn >= was);
+ try std.testing.expect(frames < 20);
+ }
+ try std.testing.expectEqual(first + 1, line(core));
+ try std.testing.expectEqual(wr.picture(), wr.drawn);
+ try std.testing.expectEqual(@as(f32, @floatFromInt(first + 1)), wr.drawn);
+ // Again, and a quarter notch more arrives mid-settle: it counts, and
+ // the settle ends on the row after it.
+ for (0..3) |_| try wr.frame(gpa, &.{-0.25});
+ for (0..4) |_| try wr.frame(gpa, &.{});
+ try std.testing.expect(wr.g.scroll_lag != 0);
+ try wr.frame(gpa, &.{-0.25});
+ for (0..20) |_| try wr.frame(gpa, &.{});
+ try std.testing.expectEqual(@as(f32, 0), wr.g.scroll_lag);
+ try std.testing.expectEqual(first + 3, line(core));
+ try std.testing.expectEqual(@as(f32, @floatFromInt(first + 3)), wr.drawn);
+}
+
test "a bar cursor is drawn on its line while a wheel's fraction holds the text off its row, as a block is" {
const gpa = std.testing.allocator;
const core = try wheelRunFile(gpa);
@@ -4659,9 +4701,8 @@ test "a bar cursor is drawn on its line while a wheel's fraction holds the text
defer wr.deinit(gpa);
defer wr.g.decor.deinit(gpa);
// Half a notch down: the core a line on, the text drawn half a row
- // below its cells, and resting there.
+ // below its cells until the settle.
try wr.frame(gpa, &.{-0.5});
- for (0..4) |_| try wr.frame(gpa, &.{});
try std.testing.expectEqual(@as(f32, -0.5), wr.g.scroll_lag);
_ = wr.arena.reset(.retain_capacity);
const s = try core.render(wr.arena.allocator());
@@ -4910,11 +4951,20 @@ fn resetScroll(g: *Gui) void {
g.scroll_pane = null;
g.scroll_delta = 0;
g.scroll_lag = 0;
+ g.scroll_idle = 0;
g.scroll_edge_len = 0;
g.scroll_notch = 0;
g.glide.stop();
}
+/// Loop steps with no turn before a resting fraction settles; the share of
+/// what is left a step takes (the glide's spring over a 60 Hz frame,
+/// Follow.omega); and what is close enough to land on at once (under a
+/// pixel of a row).
+const settle_after = 2;
+const settle_step: f32 = 1 - @exp(-pardes.glide.Follow.omega / 60.0);
+const settle_land: f32 = 0.02;
+
fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
stepGlide(g, core);
const id = g.scroll_pane orelse return;
@@ -4922,6 +4972,19 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
resetScroll(g);
return;
};
+ // A fine wheel's or a touchpad's turns stopped (SDL tells no gesture's
+ // end): the picture eases the rest of the way onto the core's row, on
+ // the glide's law, a step a frame, so it never rests a fraction of a
+ // row off its cells. The core's row is the next whole row the way the
+ // turns went (the lag is behind it going down, ahead going up), so the
+ // settle never moves against them; a turn mid-settle goes on from it.
+ if (g.scroll_delta != 0) {
+ g.scroll_idle = 0;
+ } else if (g.scroll_lag != 0 and g.glide.follow.offset == 0) {
+ g.scroll_idle +|= 1;
+ if (g.scroll_idle > settle_after)
+ g.scroll_delta = if (@abs(g.scroll_lag) < settle_land) -g.scroll_lag else -g.scroll_lag * settle_step;
+ }
const queued_delta = g.scroll_delta;
g.scroll_delta = 0;
if (queued_delta == 0) {