summaryrefslogtreecommitdiffstats
path: root/native/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-18 16:53:50 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-18 16:53:50 +0700
commit9a4fb82b5818f10e96d2f185a7e5a1f1fce3305c (patch)
tree629b8148155a12ff032accf3af9ba916f852ced4 /native/src
parent14dc750149b6cfaa49ba8fe3533343e0594fc2a3 (diff)
downloadiced-9a4fb82b5818f10e96d2f185a7e5a1f1fce3305c.tar.gz
iced-9a4fb82b5818f10e96d2f185a7e5a1f1fce3305c.tar.bz2
iced-9a4fb82b5818f10e96d2f185a7e5a1f1fce3305c.zip
Implement `Widget::mouse_interaction` for `Scrollable`
Diffstat (limited to 'native/src')
-rw-r--r--native/src/widget/scrollable.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs
index ac5b3e4f..76badbde 100644
--- a/native/src/widget/scrollable.rs
+++ b/native/src/widget/scrollable.rs
@@ -419,6 +419,45 @@ where
event::Status::Ignored
}
+ fn mouse_interaction(
+ &self,
+ layout: Layout<'_>,
+ _viewport: &Rectangle,
+ cursor_position: Point,
+ ) -> mouse::Interaction {
+ let bounds = layout.bounds();
+ let content_layout = layout.children().next().unwrap();
+ let content_bounds = content_layout.bounds();
+ let scrollbar = self.scrollbar(bounds, content_bounds);
+
+ let is_mouse_over = bounds.contains(cursor_position);
+ let is_mouse_over_scrollbar = scrollbar
+ .as_ref()
+ .map(|scrollbar| scrollbar.is_mouse_over(cursor_position))
+ .unwrap_or(false);
+
+ if is_mouse_over_scrollbar || self.state.is_scroller_grabbed() {
+ mouse::Interaction::Idle
+ } else {
+ let offset = self.state.offset(bounds, content_bounds);
+
+ let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar {
+ Point::new(cursor_position.x, cursor_position.y + offset as f32)
+ } else {
+ Point::new(cursor_position.x, -1.0)
+ };
+
+ self.content.mouse_interaction(
+ content_layout,
+ &Rectangle {
+ y: bounds.y + offset as f32,
+ ..bounds
+ },
+ cursor_position,
+ )
+ }
+ }
+
fn draw(
&self,
renderer: &mut Renderer,