New method to determine if overlay contains cursor
This is needed for "container" overlay's such as `Group` which should only consider it's childrens layouts and not it's own when determining if the cursor is captured by the overlay.
This commit is contained in:
parent
b2a3a85acb
commit
3ab6797255
4 changed files with 48 additions and 2 deletions
|
|
@ -89,6 +89,15 @@ where
|
|||
) -> mouse::Interaction {
|
||||
mouse::Interaction::Idle
|
||||
}
|
||||
|
||||
/// Whether the [`Overlay`] contains the cursor
|
||||
fn contains_cursor(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
layout.bounds().contains(cursor_position)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a [`Group`] of overlay [`Element`] children.
|
||||
|
|
|
|||
|
|
@ -115,6 +115,15 @@ where
|
|||
) {
|
||||
self.overlay.operate(layout, renderer, operation);
|
||||
}
|
||||
|
||||
/// Whether the [`Overlay`] contains the cursor
|
||||
pub fn contains_cursor(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
self.overlay.contains_cursor(layout, cursor_position)
|
||||
}
|
||||
}
|
||||
|
||||
struct Map<'a, A, B, Renderer> {
|
||||
|
|
@ -252,4 +261,12 @@ where
|
|||
self.content
|
||||
.draw(renderer, theme, style, layout, cursor_position)
|
||||
}
|
||||
|
||||
fn contains_cursor(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
self.content.contains_cursor(layout, cursor_position)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,6 +151,19 @@ where
|
|||
)
|
||||
});
|
||||
}
|
||||
|
||||
fn contains_cursor(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
self.children
|
||||
.iter()
|
||||
.zip(layout.children())
|
||||
.any(|(child, layout)| {
|
||||
child.contains_cursor(layout, cursor_position)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Group<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -261,7 +261,11 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
let base_cursor = if layout.bounds().contains(cursor_position) {
|
||||
let base_cursor = if manual_overlay
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.contains_cursor(Layout::new(&layout), cursor_position)
|
||||
{
|
||||
// TODO: Type-safe cursor availability
|
||||
Point::new(-1.0, -1.0)
|
||||
} else {
|
||||
|
|
@ -504,7 +508,10 @@ where
|
|||
);
|
||||
});
|
||||
|
||||
if overlay_bounds.contains(cursor_position) {
|
||||
if overlay.contains_cursor(
|
||||
Layout::new(layout),
|
||||
cursor_position,
|
||||
) {
|
||||
overlay_interaction
|
||||
} else {
|
||||
base_interaction
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue