Skip to content

Commit

Permalink
Fixed scroll bars hiding while content is hovered
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Nov 30, 2024
1 parent 21ef700 commit 59222ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
38 changes: 28 additions & 10 deletions src/widgets/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ScrollBar>()
.expect("a ScrollBar")
.hide(context);
}
}

impl Widget for Scroll {
Expand All @@ -260,13 +252,21 @@ impl Widget for Scroll {
_location: Point<Px>,
context: &mut EventContext<'_>,
) -> Option<CursorIcon> {
self.show_scrollbars(context);
let mut horizontal = self.horizontal_widget.expect_made_mut().widget().lock();
horizontal
.downcast_mut::<ScrollBar>()
.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::<ScrollBar>()
.expect("a ScrollBar")
.unhover(context);
}

fn redraw(&mut self, context: &mut crate::context::GraphicsContext<'_, '_, '_, '_>) {
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 10 additions & 10 deletions src/widgets/virtual_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ScrollBar>()
.expect("a ScrollBar")
.hide(context);
}

fn clear(&mut self, context: &mut LayoutContext<'_, '_, '_, '_>) {
for item in self.items.drain(..) {
context.remove_child(&item.mounted);
Expand Down Expand Up @@ -370,13 +362,21 @@ impl Widget for VirtualList {
_location: Point<Px>,
context: &mut EventContext<'_>,
) -> Option<CursorIcon> {
self.show_scrollbars(context);
let mut horizontal = self.horizontal_scroll.expect_made_mut().widget().lock();
horizontal
.downcast_mut::<ScrollBar>()
.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::<ScrollBar>()
.expect("a ScrollBar")
.unhover(context);
}

fn mounted(&mut self, context: &mut EventContext<'_>) {
Expand Down

0 comments on commit 59222ce

Please sign in to comment.