From 717e93d795a2c03dc0724b2128e659298b3b4cb6 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 20 Dec 2024 22:04:00 +0800 Subject: [PATCH] . --- crates/ui/src/scroll/scrollable_mask.rs | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/ui/src/scroll/scrollable_mask.rs b/crates/ui/src/scroll/scrollable_mask.rs index ddf8023e..ce4e52a6 100644 --- a/crates/ui/src/scroll/scrollable_mask.rs +++ b/crates/ui/src/scroll/scrollable_mask.rs @@ -126,13 +126,14 @@ impl Element for ScrollableMask { let hitbox = hitbox.clone(); let mouse_position = cx.mouse_position(); let scroll_handle = self.scroll_handle.clone(); - let old_offset = scroll_handle.offset(); + let last_offset = scroll_handle.offset(); let view_id = self.view.entity_id(); - let is_horizontal = self.axis == ScrollableAxis::Horizontal; + let is_horizontal = matches!(self.axis, ScrollableAxis::Horizontal); move |event: &ScrollWheelEvent, phase, cx| { if bounds.contains(&mouse_position) && phase.bubble() && hitbox.is_hovered(cx) { let mut delta = event.delta.pixel_delta(line_height); + let mut offset = scroll_handle.offset(); // Limit for only one way scrolling at same time. // When use MacBook touchpad we may get both x and y delta, @@ -145,21 +146,18 @@ impl Element for ScrollableMask { } } - if is_horizontal && !delta.x.is_zero() { - // When is horizontal scroll, move the horizontal scroll handle to make scrolling. - let mut offset = scroll_handle.offset(); - offset.x += delta.x; - scroll_handle.set_offset(offset); + if is_horizontal { + if !delta.x.is_zero() { + offset.x += delta.x; + } + } else { + if !delta.y.is_zero() { + offset.y += delta.y; + } } - if !is_horizontal && !delta.y.is_zero() { - // When is vertical scroll, move the vertical scroll handle to make scrolling. - let mut offset = scroll_handle.offset(); - offset.y += delta.y; + if last_offset != offset { scroll_handle.set_offset(offset); - } - - if old_offset != scroll_handle.offset() { cx.notify(Some(view_id)); cx.stop_propagation(); }