summaryrefslogtreecommitdiffstats
path: root/native/src/overlay.rs
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/overlay.rs')
-rw-r--r--native/src/overlay.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/native/src/overlay.rs b/native/src/overlay.rs
index 792d2905..c2a98693 100644
--- a/native/src/overlay.rs
+++ b/native/src/overlay.rs
@@ -10,6 +10,7 @@ use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::renderer;
+use crate::widget::tree::{self, Tree};
use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size};
/// An interactive component that can be displayed on top of other widgets.
@@ -40,6 +41,28 @@ where
cursor_position: Point,
);
+ /// Returns the [`Tag`] of the [`Widget`].
+ ///
+ /// [`Tag`]: tree::Tag
+ fn tag(&self) -> tree::Tag {
+ tree::Tag::stateless()
+ }
+
+ /// Returns the [`State`] of the [`Widget`].
+ ///
+ /// [`State`]: tree::State
+ fn state(&self) -> tree::State {
+ tree::State::None
+ }
+
+ /// Returns the state [`Tree`] of the children of the [`Widget`].
+ fn children(&self) -> Vec<Tree> {
+ Vec::new()
+ }
+
+ /// Reconciliates the [`Widget`] with the provided [`Tree`].
+ fn diff(&self, _tree: &mut Tree) {}
+
/// Processes a runtime [`Event`].
///
/// It receives:
@@ -77,3 +100,26 @@ where
mouse::Interaction::Idle
}
}
+
+/// Obtains the first overlay [`Element`] found in the given children.
+///
+/// This method will generally only be used by advanced users that are
+/// implementing the [`Widget`](crate::Widget) trait.
+pub fn from_children<'a, Message, Renderer>(
+ children: &'a [crate::Element<'_, Message, Renderer>],
+ tree: &'a mut Tree,
+ layout: Layout<'_>,
+ renderer: &Renderer,
+) -> Option<Element<'a, Message, Renderer>>
+where
+ Renderer: crate::Renderer,
+{
+ children
+ .iter()
+ .zip(&mut tree.children)
+ .zip(layout.children())
+ .filter_map(|((child, state), layout)| {
+ child.as_widget().overlay(state, layout, renderer)
+ })
+ .next()
+}