Introduce internal overlay::Nested for UserInterface
This commit is contained in:
parent
329fbc7b21
commit
55dc3b5619
9 changed files with 406 additions and 41 deletions
|
|
@ -91,9 +91,23 @@ where
|
|||
///
|
||||
/// By default, it returns true if the bounds of the `layout` contain
|
||||
/// the `cursor_position`.
|
||||
fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool {
|
||||
fn is_over(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
_renderer: &Renderer,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
layout.bounds().contains(cursor_position)
|
||||
}
|
||||
|
||||
/// Returns the nested overlay of the [`Overlay`], if there is any.
|
||||
fn overlay<'a>(
|
||||
&'a mut self,
|
||||
_layout: Layout<'_>,
|
||||
_renderer: &Renderer,
|
||||
) -> Option<Element<'a, Message, Renderer>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a [`Group`] of overlay [`Element`] children.
|
||||
|
|
|
|||
|
|
@ -112,8 +112,22 @@ where
|
|||
}
|
||||
|
||||
/// Returns true if the cursor is over the [`Element`].
|
||||
pub fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool {
|
||||
self.overlay.is_over(layout, cursor_position)
|
||||
pub fn is_over(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
self.overlay.is_over(layout, renderer, cursor_position)
|
||||
}
|
||||
|
||||
/// Returns the nested overlay of the [`Element`], if there is any.
|
||||
pub fn overlay<'b>(
|
||||
&'b mut self,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
) -> Option<Element<'b, Message, Renderer>> {
|
||||
self.overlay.overlay(layout, renderer)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,7 +262,12 @@ where
|
|||
self.content.draw(renderer, theme, style, layout, cursor)
|
||||
}
|
||||
|
||||
fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool {
|
||||
self.content.is_over(layout, cursor_position)
|
||||
fn is_over(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
self.content.is_over(layout, renderer, cursor_position)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,11 +147,18 @@ where
|
|||
});
|
||||
}
|
||||
|
||||
fn is_over(&self, layout: Layout<'_>, cursor_position: Point) -> bool {
|
||||
fn is_over(
|
||||
&self,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
cursor_position: Point,
|
||||
) -> bool {
|
||||
self.children
|
||||
.iter()
|
||||
.zip(layout.children())
|
||||
.any(|(child, layout)| child.is_over(layout, cursor_position))
|
||||
.any(|(child, layout)| {
|
||||
child.is_over(layout, renderer, cursor_position)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue