Skip to content

Commit

Permalink
Ignore redraws of invisible content in hover widget
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Feb 3, 2025
1 parent 599d8b5 commit 3029481
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 12 additions & 0 deletions core/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ impl<'a, Message> Shell<'a, Message> {
self.redraw_request
}

/// Replaces the redraw request of the [`Shell`]; without conflict resolution.
///
/// This is useful if you want to overwrite the redraw request to a previous value.
/// Since it's a fairly advanced use case and should rarely be used, it is a static
/// method.
pub fn replace_redraw_request(
shell: &mut Self,
redraw_request: Option<window::RedrawRequest>,
) {
shell.redraw_request = redraw_request;
}

/// Returns whether the current layout is invalid or not.
pub fn is_layout_invalid(&self) -> bool {
self.is_layout_invalid
Expand Down
14 changes: 11 additions & 3 deletions widget/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,16 +871,19 @@ where
shell.request_redraw();
}

let is_visible =
is_hovered || self.is_top_focused || self.is_top_overlay_active;

if matches!(
event,
Event::Mouse(
mouse::Event::CursorMoved { .. }
| mouse::Event::ButtonReleased(_)
)
) || is_hovered
|| self.is_top_focused
|| self.is_top_overlay_active
) || is_visible
{
let redraw_request = shell.redraw_request();

self.top.as_widget_mut().update(
top_tree,
event.clone(),
Expand All @@ -891,6 +894,11 @@ where
shell,
viewport,
);

// Ignore redraw requests of invisible content
if !is_visible {
Shell::replace_redraw_request(shell, redraw_request);
}
};

if shell.is_event_captured() {
Expand Down

0 comments on commit 3029481

Please sign in to comment.