From d5a886dbcb50964ce8c6132a4bb3504d6396d01b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 4 Nov 2024 23:05:44 +0100 Subject: Fix `hover` widget not redrawing when hovered --- widget/src/helpers.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'widget') diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index e1474d34..33dff647 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -534,6 +534,7 @@ where top: Element<'a, Message, Theme, Renderer>, is_top_focused: bool, is_top_overlay_active: bool, + is_hovered: bool, } impl<'a, Message, Theme, Renderer> Widget @@ -655,6 +656,8 @@ where let (base_layout, base_tree) = children.next().unwrap(); let (top_layout, top_tree) = children.next().unwrap(); + let is_hovered = cursor.is_over(layout.bounds()); + if matches!(event, Event::Window(window::Event::RedrawRequested(_))) { let mut count_focused = operation::focusable::count(); @@ -670,6 +673,10 @@ where operation::Outcome::Some(count) => count.focused.is_some(), _ => false, }; + + self.is_hovered = is_hovered; + } else if is_hovered != self.is_hovered { + shell.request_redraw(); } if matches!( @@ -678,7 +685,7 @@ where mouse::Event::CursorMoved { .. } | mouse::Event::ButtonReleased(_) ) - ) || cursor.is_over(layout.bounds()) + ) || is_hovered || self.is_top_focused || self.is_top_overlay_active { @@ -767,6 +774,7 @@ where top: top.into(), is_top_focused: false, is_top_overlay_active: false, + is_hovered: false, }) } -- cgit