diff options
| author | 2023-01-14 16:08:36 +0100 | |
|---|---|---|
| committer | 2023-01-14 16:08:36 +0100 | |
| commit | 5ef0648bf447aaca8b96782643401e54a2bf7759 (patch) | |
| tree | 634f929a715258a61edfcecd747f95a7d903b3b4 /native | |
| parent | 18552f96df5d1fa72c3c87e96a5765f89c340e19 (diff) | |
| parent | daa3f3324d001b634f73779423da605c213e7626 (diff) | |
| download | iced-5ef0648bf447aaca8b96782643401e54a2bf7759.tar.gz iced-5ef0648bf447aaca8b96782643401e54a2bf7759.tar.bz2 iced-5ef0648bf447aaca8b96782643401e54a2bf7759.zip  | |
Merge pull request #1649 from iced-rs/generic-widget-operations
Introduce `custom` method to `widget::Operation` trait
Diffstat (limited to 'native')
| -rw-r--r-- | native/src/element.rs | 5 | ||||
| -rw-r--r-- | native/src/overlay/element.rs | 6 | ||||
| -rw-r--r-- | native/src/widget/action.rs | 9 | ||||
| -rw-r--r-- | native/src/widget/operation.rs | 4 | 
4 files changed, 24 insertions, 0 deletions
diff --git a/native/src/element.rs b/native/src/element.rs index 2409b1c9..0a677d20 100644 --- a/native/src/element.rs +++ b/native/src/element.rs @@ -9,6 +9,7 @@ use crate::{      Clipboard, Color, Layout, Length, Point, Rectangle, Shell, Widget,  }; +use std::any::Any;  use std::borrow::Borrow;  /// A generic [`Widget`]. @@ -333,6 +334,10 @@ where              ) {                  self.operation.text_input(state, id);              } + +            fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) { +                self.operation.custom(state, id); +            }          }          self.widget.operate( diff --git a/native/src/overlay/element.rs b/native/src/overlay/element.rs index 498e9ae3..41a8a597 100644 --- a/native/src/overlay/element.rs +++ b/native/src/overlay/element.rs @@ -7,6 +7,8 @@ use crate::renderer;  use crate::widget;  use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector}; +use std::any::Any; +  /// A generic [`Overlay`].  #[allow(missing_debug_implementations)]  pub struct Element<'a, Message, Renderer> { @@ -188,6 +190,10 @@ where              ) {                  self.operation.text_input(state, id)              } + +            fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) { +                self.operation.custom(state, id); +            }          }          self.content diff --git a/native/src/widget/action.rs b/native/src/widget/action.rs index 9aa79dec..1e21ff38 100644 --- a/native/src/widget/action.rs +++ b/native/src/widget/action.rs @@ -3,6 +3,7 @@ use crate::widget::Id;  use iced_futures::MaybeSend; +use std::any::Any;  use std::rc::Rc;  /// An operation to be performed on the widget tree. @@ -84,6 +85,10 @@ where              ) {                  self.operation.focusable(state, id);              } + +            fn custom(&mut self, state: &mut dyn Any, id: Option<&Id>) { +                self.operation.custom(state, id); +            }          }          let Self { operation, .. } = self; @@ -118,6 +123,10 @@ where          self.operation.text_input(state, id);      } +    fn custom(&mut self, state: &mut dyn Any, id: Option<&Id>) { +        self.operation.custom(state, id); +    } +      fn finish(&self) -> operation::Outcome<B> {          match self.operation.finish() {              operation::Outcome::None => operation::Outcome::None, diff --git a/native/src/widget/operation.rs b/native/src/widget/operation.rs index a0aa4117..73e6a6b0 100644 --- a/native/src/widget/operation.rs +++ b/native/src/widget/operation.rs @@ -9,6 +9,7 @@ pub use text_input::TextInput;  use crate::widget::Id; +use std::any::Any;  use std::fmt;  /// A piece of logic that can traverse the widget tree of an application in @@ -33,6 +34,9 @@ pub trait Operation<T> {      /// Operates on a widget that has text input.      fn text_input(&mut self, _state: &mut dyn TextInput, _id: Option<&Id>) {} +    /// Operates on a custom widget with some state. +    fn custom(&mut self, _state: &mut dyn Any, _id: Option<&Id>) {} +      /// Finishes the [`Operation`] and returns its [`Outcome`].      fn finish(&self) -> Outcome<T> {          Outcome::None  | 
