this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

vxfw(ListView): fix scroll up

We set the value of pending_lines to -n, which has the side effect of
ignoring any subsequent scroll up events before the next draw. Subtract
the scroll up quantity from the current value, instead.

+91 -1
+91 -1
src/vxfw/ListView.zig
··· 43 43 44 44 fn linesUp(self: *Scroll, n: u8) bool { 45 45 if (self.top == 0 and self.offset == 0) return false; 46 - self.pending_lines = -1 * @as(i17, @intCast(n)); 46 + self.pending_lines -= @intCast(n); 47 47 return true; 48 48 } 49 49 }; ··· 665 665 try std.testing.expectEqual(0, list_view.scroll.offset); 666 666 try std.testing.expectEqual(3, surface.children.len); 667 667 try std.testing.expectEqual(3, list_view.cursor); 668 + } 669 + 670 + // @reykjalin found an issue on mac with ghostty where the scroll up and scroll down were uneven. 671 + // Ghostty has high precision scrolling and sends a lot of wheel events for each tick 672 + test "ListView: uneven scroll" { 673 + // Create child widgets 674 + const Text = @import("Text.zig"); 675 + const zero: Text = .{ .text = "0" }; 676 + const one: Text = .{ .text = "1" }; 677 + const two: Text = .{ .text = "2" }; 678 + const three: Text = .{ .text = "3" }; 679 + const four: Text = .{ .text = "4" }; 680 + const five: Text = .{ .text = "5" }; 681 + const six: Text = .{ .text = "6" }; 682 + // 0 | 683 + // 1 | 684 + // 2 | 685 + // 3 | 686 + // 4 687 + // 5 688 + // 6 689 + 690 + // Create the list view 691 + const list_view: ListView = .{ 692 + .wheel_scroll = 1, // Set wheel scroll to one 693 + .children = .{ .slice = &.{ 694 + zero.widget(), 695 + one.widget(), 696 + two.widget(), 697 + three.widget(), 698 + four.widget(), 699 + five.widget(), 700 + six.widget(), 701 + } }, 702 + }; 703 + 704 + // Boiler plate draw context 705 + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); 706 + defer arena.deinit(); 707 + const ucd = try vaxis.Unicode.init(arena.allocator()); 708 + vxfw.DrawContext.init(&ucd, .unicode); 709 + 710 + const list_widget = list_view.widget(); 711 + const draw_ctx: vxfw.DrawContext = .{ 712 + .arena = arena.allocator(), 713 + .min = .{}, 714 + .max = .{ .width = 16, .height = 4 }, 715 + }; 716 + 717 + var surface = try list_widget.draw(draw_ctx); 718 + 719 + var mouse_event: vaxis.Mouse = .{ 720 + .col = 0, 721 + .row = 0, 722 + .button = .wheel_up, 723 + .mods = .{}, 724 + .type = .press, 725 + }; 726 + // Event handlers need a context 727 + var ctx: vxfw.EventContext = .{ 728 + .cmds = std.ArrayList(vxfw.Command).init(std.testing.allocator), 729 + }; 730 + defer ctx.cmds.deinit(); 731 + 732 + // Send a wheel down x 3 733 + mouse_event.button = .wheel_down; 734 + try list_widget.handleEvent(&ctx, .{ .mouse = mouse_event }); 735 + try list_widget.handleEvent(&ctx, .{ .mouse = mouse_event }); 736 + try list_widget.handleEvent(&ctx, .{ .mouse = mouse_event }); 737 + // We have to draw the widget for scrolls to take effect 738 + surface = try list_widget.draw(draw_ctx); 739 + // 0 740 + // 1 741 + // 2 742 + // 3 | 743 + // 4 | 744 + // 5 | 745 + // 6 | 746 + try std.testing.expectEqual(3, list_view.scroll.top); 747 + try std.testing.expectEqual(0, list_view.scroll.offset); 748 + try std.testing.expectEqual(4, surface.children.len); 749 + 750 + // Now wheel_up two times should move us two lines up 751 + mouse_event.button = .wheel_up; 752 + try list_widget.handleEvent(&ctx, .{ .mouse = mouse_event }); 753 + try list_widget.handleEvent(&ctx, .{ .mouse = mouse_event }); 754 + surface = try list_widget.draw(draw_ctx); 755 + try std.testing.expectEqual(1, list_view.scroll.top); 756 + try std.testing.expectEqual(0, list_view.scroll.offset); 757 + try std.testing.expectEqual(4, surface.children.len); 668 758 } 669 759 670 760 test "refAllDecls" {