diff --git a/src/widgets/scroll.rs b/src/widgets/scroll.rs index 517dd7abc..be753ee87 100644 --- a/src/widgets/scroll.rs +++ b/src/widgets/scroll.rs @@ -236,14 +236,6 @@ impl Scroll { .expect("a ScrollBar") .show(context); } - - fn hide_scrollbars(&mut self, context: &mut EventContext<'_>) { - let mut horizontal = self.horizontal_widget.expect_made_mut().widget().lock(); - horizontal - .downcast_mut::() - .expect("a ScrollBar") - .hide(context); - } } impl Widget for Scroll { @@ -260,13 +252,21 @@ impl Widget for Scroll { _location: Point, context: &mut EventContext<'_>, ) -> Option { - self.show_scrollbars(context); + let mut horizontal = self.horizontal_widget.expect_made_mut().widget().lock(); + horizontal + .downcast_mut::() + .expect("a ScrollBar") + .hover(context); None } fn unhover(&mut self, context: &mut EventContext<'_>) { - self.hide_scrollbars(context); + let mut horizontal = self.horizontal_widget.expect_made_mut().widget().lock(); + horizontal + .downcast_mut::() + .expect("a ScrollBar") + .unhover(context); } fn redraw(&mut self, context: &mut crate::context::GraphicsContext<'_, '_, '_, '_>) { @@ -621,6 +621,24 @@ impl ScrollBar { self.scrollbar_opacity_animation = other.scrollbar_opacity_animation.clone(); } + /// Marks this scroll bar as being hovered. + pub fn hover(&mut self, context: &mut EventContext<'_>) { + self.scrollbar_opacity_animation + .lock() + .hovering + .insert(context.widget().id()); + self.show(context); + } + + /// Unmarks this scroll bar as being hovered. + pub fn unhover(&mut self, context: &mut EventContext<'_>) { + self.scrollbar_opacity_animation + .lock() + .hovering + .remove(&context.widget().id()); + self.hide(context); + } + /// Shows this scroll bar, automatically hiding after a short delay. pub fn show(&mut self, context: &mut EventContext<'_>) { let mut animation_state = self.scrollbar_opacity_animation.lock(); diff --git a/src/widgets/virtual_list.rs b/src/widgets/virtual_list.rs index bf03aa579..cf4b33406 100644 --- a/src/widgets/virtual_list.rs +++ b/src/widgets/virtual_list.rs @@ -184,14 +184,6 @@ impl VirtualList { .show(context); } - fn hide_scrollbars(&mut self, context: &mut EventContext<'_>) { - let mut vertical = self.vertical_scroll.expect_made_mut().widget().lock(); - vertical - .downcast_mut::() - .expect("a ScrollBar") - .hide(context); - } - fn clear(&mut self, context: &mut LayoutContext<'_, '_, '_, '_>) { for item in self.items.drain(..) { context.remove_child(&item.mounted); @@ -370,13 +362,21 @@ impl Widget for VirtualList { _location: Point, context: &mut EventContext<'_>, ) -> Option { - self.show_scrollbars(context); + let mut horizontal = self.horizontal_scroll.expect_made_mut().widget().lock(); + horizontal + .downcast_mut::() + .expect("a ScrollBar") + .hover(context); None } fn unhover(&mut self, context: &mut EventContext<'_>) { - self.hide_scrollbars(context); + let mut horizontal = self.horizontal_scroll.expect_made_mut().widget().lock(); + horizontal + .downcast_mut::() + .expect("a ScrollBar") + .unhover(context); } fn mounted(&mut self, context: &mut EventContext<'_>) {