summaryrefslogtreecommitdiffstats
path: root/native/src/overlay.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-07-27 06:49:20 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-07-27 06:49:20 +0200
commitff2519b1d43d481987351a83b6dd7237524c21f0 (patch)
tree5731eeb7eb1247d4a8951de0d5bc5d8102640559 /native/src/overlay.rs
parentc44267b85f7aaa2997e3caf1323b837d95818c22 (diff)
downloadiced-ff2519b1d43d481987351a83b6dd7237524c21f0.tar.gz
iced-ff2519b1d43d481987351a83b6dd7237524c21f0.tar.bz2
iced-ff2519b1d43d481987351a83b6dd7237524c21f0.zip
Replace stateful widgets with new `iced_pure` API
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()
+}