Skip to content

Commit

Permalink
Override MouseArea interaction only when contents are idle
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Feb 7, 2024
1 parent bcdfbf4 commit d756a92
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions widget/src/mouse_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> {
self
}

/// The version of the cursor to use when hovering.
/// The [`mouse::Interaction`] to use when hovering the area.
#[must_use]
pub fn mouse_interaction(
mut self,
Expand Down Expand Up @@ -226,21 +226,22 @@ where
viewport: &Rectangle,
renderer: &Renderer,
) -> mouse::Interaction {
if !cursor.is_over(layout.bounds()) {
return mouse::Interaction::default();
}

if let Some(interaction) = self.interaction {
return interaction;
}

self.content.as_widget().mouse_interaction(
let content_interaction = self.content.as_widget().mouse_interaction(
&tree.children[0],
layout,
cursor,
viewport,
renderer,
)
);

match (self.interaction, content_interaction) {
(Some(interaction), mouse::Interaction::Idle)
if cursor.is_over(layout.bounds()) =>
{
interaction
}
_ => content_interaction,
}
}

fn draw(
Expand Down

0 comments on commit d756a92

Please sign in to comment.