summaryrefslogtreecommitdiffstats
path: root/native/src/overlay.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2022-08-06 00:32:57 +0200
committerLibravatar GitHub <noreply@github.com>2022-08-06 00:32:57 +0200
commit1923dbf7f0769d55e5283f572fde0ce752e28b86 (patch)
tree7be9b36f941f6e13ddc8884f715c04555b1e77db /native/src/overlay.rs
parent1b4f38c71f6e05e26599ee75ea9c91dde96e71ae (diff)
parentc23ed7e4a0a2b62a0d7cabe6e35d7323eac543d2 (diff)
downloadiced-1923dbf7f0769d55e5283f572fde0ce752e28b86.tar.gz
iced-1923dbf7f0769d55e5283f572fde0ce752e28b86.tar.bz2
iced-1923dbf7f0769d55e5283f572fde0ce752e28b86.zip
Merge pull request #1393 from iced-rs/deprecate-stateful-widgets
Replace stateful widgets with the new `iced_pure` API
Diffstat (limited to 'native/src/overlay.rs')
-rw-r--r--native/src/overlay.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/native/src/overlay.rs b/native/src/overlay.rs
index 792d2905..905d3389 100644
--- a/native/src/overlay.rs
+++ b/native/src/overlay.rs
@@ -10,6 +10,8 @@ use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::renderer;
+use crate::widget;
+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 +42,36 @@ 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) {}
+
+ /// Applies an [`Operation`] to the [`Widget`].
+ fn operate(
+ &self,
+ _layout: Layout<'_>,
+ _operation: &mut dyn widget::Operation<Message>,
+ ) {
+ }
+
/// Processes a runtime [`Event`].
///
/// It receives:
@@ -77,3 +109,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()
+}