summaryrefslogtreecommitdiff
path: root/dev/gui/gui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'dev/gui/gui.zig')
-rw-r--r--dev/gui/gui.zig60
1 files changed, 42 insertions, 18 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 2756f69b..0f1fe0e6 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -1773,10 +1773,9 @@ const Input = struct {
/// Pane `id`'s first row shown, after the inputs posted: the session's
/// own window asks (a wheel's rows stop where the pane does); a replica
/// client's speculation may wait on the session, so it never asks.
- fn scrollOf(in: *const Input, id: usize) ?i32 {
+ fn scrollOf(in: *const Input, id: usize) ?[2]i64 {
if (in.client != null) return null;
- const pane = in.core.panes[id] orelse return null;
- return pane.scroll();
+ return topOf(in.core.panes[id] orelse return null);
}
fn close(in: *Input) void {
@@ -3301,6 +3300,12 @@ fn notchOf(raw_y: f32, integer_y: i32) ?i32 {
const Glide = pardes.glide.Glide;
+/// Where a pane's view starts, to tell a wheel's row moved it: its line,
+/// and a file's row of that line's wrapped rows (File.Top).
+fn topOf(pane: *pardes.Pane) [2]i64 {
+ return .{ pane.scroll(), if (pane.file) |f| f.scroll_row else 0 };
+}
+
/// Feeds a wheel's notches to the core, and keeps what moved the view for
/// the frame's glide (Glide.frame).
fn stepGlide(g: *Gui, core: *pardes.Pardes) void {
@@ -3322,10 +3327,10 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes) void {
while (left != 0) {
const down = left > 0;
left += if (down) -1 else 1;
- const was = pane.scroll();
+ const was = topOf(pane);
// Shift: pardes's own scroll, never a program's wheel.
core.update(.{ .mouse = .{ .button = if (down) .wheel_down else .wheel_up, .kind = .press, .col = g.scroll_col, .row = g.scroll_row, .shift = true } });
- if (pane.scroll() == was) break;
+ if (std.mem.eql(i64, &topOf(pane), &was)) break;
wheeled = id;
}
if (wheeled != null) core.needs_frame = true;
@@ -3541,7 +3546,7 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool {
},
});
// A replica client's rows may wait on the session: it never asks.
- if (was != null and in.scrollOf(id) == was) {
+ if (was != null and std.mem.eql(i64, &in.scrollOf(id).?, &was.?)) {
resetScroll(g);
return false;
}
@@ -6544,16 +6549,19 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
try std.testing.expectEqual(@as(i32, -1), g.scroll_notch);
}
-test "a notch scrolls the core at once and the picture glides after it, a wrapped line's rows at a time" {
+test "a notch scrolls the core at once and the picture glides after it, a row a notch: a wrapped line's rows one by one" {
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
defer core.deinit();
- // Lines of two rows each at this width, numbered so no two rows match.
+ // Lines of two rows each at this width, numbered so no two rows match;
+ // line 3 of 80 numbered words, five rows or more.
var text: std.ArrayList(u8) = .empty;
defer text.deinit(gpa);
for (0..60) |i| {
try text.print(gpa, "{d:0>4} ", .{i});
- try text.appendNTimes(gpa, 'a' + @as(u8, @intCast(i % 26)), 100);
+ if (i == 3) {
+ for (0..80) |w| try text.print(gpa, "w{d:0>3} ", .{w});
+ } else try text.appendNTimes(gpa, 'a' + @as(u8, @intCast(i % 26)), 100);
try text.append(gpa, '\n');
}
_ = try core.setTestFile(text.items);
@@ -6570,26 +6578,42 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe
g.scroll_col = r.x + 10;
g.scroll_row = r.y + r.h - 2;
const body_y = core.bodyTop(core.panes[core.view().active].?, r);
- const row_before = try gpa.dupe(pardes.Cell, s.cells[@as(usize, body_y + 1) * s.cols + r.x + config.GUTTER ..][0 .. r.w - config.GUTTER]);
+ const row_before = try gpa.dupe(pardes.Cell, s.cells[@as(usize, body_y) * s.cols + r.x + config.GUTTER ..][0 .. r.w - config.GUTTER]);
defer gpa.free(row_before);
// The window has drawn the view once (Glide.frame finds a view that moved).
g.now_ns = now;
glideFrame(&g, gpa, s);
- // One notch down: the core is a line on at once.
+ // One notch down: the core is a row on at once, line 0's second.
g.scroll_notch = 1;
- const scrolled = core.panes[core.view().active].?.scroll();
+ const f = &core.panes[core.view().active].?.file.?;
stepGlide(&g, core);
- try std.testing.expectEqual(scrolled + 1, core.panes[core.view().active].?.scroll());
+ try std.testing.expectEqual(@as(usize, 0), f.scroll);
+ try std.testing.expectEqual(@as(u32, 1), f.scroll_row);
_ = arena.reset(.retain_capacity);
s = try core.render(arena.allocator());
glideFrame(&g, gpa, s);
// The window's own motion: it draws its frames while it moves.
try std.testing.expect(frontendMoving(&g));
- // Its two rows: the picture two rows behind, the rows that left kept,
- // nearest first.
- try std.testing.expectApproxEqAbs(@as(f32, -2), g.glide.follow.offset, 1e-4);
- try std.testing.expectEqual(@as(u16, 2), g.glide.nabove);
+ // Its row: the picture a row behind, the row that left kept.
+ try std.testing.expectApproxEqAbs(@as(f32, -1), g.glide.follow.offset, 1e-4);
+ try std.testing.expectEqual(@as(u16, 1), g.glide.nabove);
try std.testing.expect(pardes.glide.sameRow(g.glide.above[0 .. r.w - config.GUTTER], row_before));
+ // Notch by notch to line 5, through line 3's rows: a row more
+ // behind each, never a line's rows at once.
+ var lag = g.glide.follow.offset;
+ var notches: usize = 1;
+ while (f.scroll < 5) : (notches += 1) {
+ g.scroll_notch = 1;
+ stepGlide(&g, core);
+ _ = arena.reset(.retain_capacity);
+ s = try core.render(arena.allocator());
+ glideFrame(&g, gpa, s);
+ try std.testing.expectApproxEqAbs(lag - 1, g.glide.follow.offset, 1e-4);
+ lag = g.glide.follow.offset;
+ }
+ const line3: usize = pardes.panes.File.lineRows(core.settings.tab, core.panes[core.view().active].?, 3);
+ try std.testing.expect(line3 >= 5);
+ try std.testing.expectEqual(2 + 2 + 2 + line3 + 2, notches);
// Frame by frame it comes back, never past, and settles.
var frames: usize = 0;
while (g.glide.moving()) : (frames += 1) {
@@ -7746,7 +7770,7 @@ test "a body tells its first line" {
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
defer core.deinit();
const pane = try core.setTestFile(std.mem.asBytes(&@as([80][5]u8, @splat("line\n".*))));
- pane.scrollBy(8);
+ pane.scrollBy(core.settings.tab, 8);
core.sync();
const s = try core.render(core.scratch.allocator());
const body = for (s.regionList()) |region| {