From 602c441ac1a6b96fa8055f1baedfae235982467c Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 4 Feb 2025 11:26:24 +0000 Subject: [PATCH] Fix scrollbars when pointer capture is released Fixes https://github.com/linebender/xilem/issues/857 --- masonry/src/widgets/scroll_bar.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/masonry/src/widgets/scroll_bar.rs b/masonry/src/widgets/scroll_bar.rs index b1a349126..5a565569d 100644 --- a/masonry/src/widgets/scroll_bar.rs +++ b/masonry/src/widgets/scroll_bar.rs @@ -154,7 +154,7 @@ impl Widget for ScrollBar { } ctx.request_render(); } - PointerEvent::PointerUp(_, _) => { + PointerEvent::PointerUp(_, _) | PointerEvent::PointerLeave(_) => { self.grab_anchor = None; ctx.request_render(); } @@ -233,7 +233,7 @@ mod tests { use super::*; use crate::assert_render_snapshot; - use crate::core::PointerButton; + use crate::core::{PointerButton, PointerState}; use crate::testing::{widget_ids, TestHarness, TestWidgetExt}; #[test] @@ -261,6 +261,12 @@ mod tests { harness.mouse_move(Point::new(30.0, 300.0)); assert_render_snapshot!(harness, "scrollbar_bottom"); + + harness.process_pointer_event(PointerEvent::PointerLeave(PointerState::empty())); + // Move the mouse to a place where if the scrollbar was still grabbing, it would move the scrollbar + harness.mouse_move(Point::new(30.0, 100.0)); + // We can reuse the same snapshot, because scrollbars don't currently indicate they are pressed + assert_render_snapshot!(harness, "scrollbar_bottom"); } #[test]