summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-06-14 20:32:45 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-14 20:32:45 +0200
commit267dbf34e94bbdfe99de857aea5930f1fcac7aec (patch)
tree4a95386401a0dd87f5f87c0695a40c58a372ecb2 /core
parent329fbc7b2157b84183849b2e0f600eb039435aed (diff)
parent9803b276ad087846dfc3bb349113c5799ce00141 (diff)
downloadiced-267dbf34e94bbdfe99de857aea5930f1fcac7aec.tar.gz
iced-267dbf34e94bbdfe99de857aea5930f1fcac7aec.tar.bz2
iced-267dbf34e94bbdfe99de857aea5930f1fcac7aec.zip
Merge pull request #1719 from tarkah/feat/nested-overlay
Nested overlays
Diffstat (limited to 'core')
-rw-r--r--core/src/overlay.rs16
-rw-r--r--core/src/overlay/element.rs37
-rw-r--r--core/src/overlay/group.rs26
3 files changed, 72 insertions, 7 deletions
diff --git a/core/src/overlay.rs b/core/src/overlay.rs
index 1fa994e4..2e05db93 100644
--- a/core/src/overlay.rs
+++ b/core/src/overlay.rs
@@ -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.
diff --git a/core/src/overlay/element.rs b/core/src/overlay/element.rs
index be67fc76..c2134343 100644
--- a/core/src/overlay/element.rs
+++ b/core/src/overlay/element.rs
@@ -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,22 @@ 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)
+ }
+
+ fn overlay<'b>(
+ &'b mut self,
+ layout: Layout<'_>,
+ renderer: &Renderer,
+ ) -> Option<Element<'b, B, Renderer>> {
+ self.content
+ .overlay(layout, renderer)
+ .map(|overlay| overlay.map(self.mapper))
}
}
diff --git a/core/src/overlay/group.rs b/core/src/overlay/group.rs
index e770abf8..deffaad0 100644
--- a/core/src/overlay/group.rs
+++ b/core/src/overlay/group.rs
@@ -147,11 +147,33 @@ 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)
+ })
+ }
+
+ fn overlay<'b>(
+ &'b mut self,
+ layout: Layout<'_>,
+ renderer: &Renderer,
+ ) -> Option<overlay::Element<'b, Message, Renderer>> {
+ let children = self
+ .children
+ .iter_mut()
+ .zip(layout.children())
+ .filter_map(|(child, layout)| child.overlay(layout, renderer))
+ .collect::<Vec<_>>();
+
+ (!children.is_empty()).then(|| Group::with_children(children).overlay())
}
}