diff options
| author | 2022-12-02 18:53:21 +0100 | |
|---|---|---|
| committer | 2022-12-02 18:53:21 +0100 | |
| commit | 4029a1cdaaac1abbdcc141b20469a49670cd99b6 (patch) | |
| tree | 71fa9d9c4aa1f02ce05771db43a4bb7bc6570e77 /native/src/widget/action.rs | |
| parent | 676d8efe03ebdbeeb95aef96b8097395b788b1ab (diff) | |
| parent | 8b55e9b9e6ba0b83038dd491dd34d95b4f9a381b (diff) | |
| download | iced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.tar.gz iced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.tar.bz2 iced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.zip | |
Merge branch 'master' into non-uniform-border-radius-for-quads
Diffstat (limited to 'native/src/widget/action.rs')
| -rw-r--r-- | native/src/widget/action.rs | 67 | 
1 files changed, 57 insertions, 10 deletions
| diff --git a/native/src/widget/action.rs b/native/src/widget/action.rs index 766e902b..9aa79dec 100644 --- a/native/src/widget/action.rs +++ b/native/src/widget/action.rs @@ -1,8 +1,10 @@ -use crate::widget::operation::{self, Operation}; +use crate::widget::operation::{self, Focusable, Operation, Scrollable};  use crate::widget::Id;  use iced_futures::MaybeSend; +use std::rc::Rc; +  /// An operation to be performed on the widget tree.  #[allow(missing_debug_implementations)]  pub struct Action<T>(Box<dyn Operation<T>>); @@ -24,7 +26,7 @@ impl<T> Action<T> {      {          Action(Box::new(Map {              operation: self.0, -            f: Box::new(f), +            f: Rc::new(f),          }))      } @@ -37,7 +39,7 @@ impl<T> Action<T> {  #[allow(missing_debug_implementations)]  struct Map<A, B> {      operation: Box<dyn Operation<A>>, -    f: Box<dyn Fn(A) -> B>, +    f: Rc<dyn Fn(A) -> B>,  }  impl<A, B> Operation<B> for Map<A, B> @@ -50,30 +52,44 @@ where          id: Option<&Id>,          operate_on_children: &mut dyn FnMut(&mut dyn Operation<B>),      ) { -        struct MapRef<'a, A, B> { +        struct MapRef<'a, A> {              operation: &'a mut dyn Operation<A>, -            f: &'a dyn Fn(A) -> B,          } -        impl<'a, A, B> Operation<B> for MapRef<'a, A, B> { +        impl<'a, A, B> Operation<B> for MapRef<'a, A> {              fn container(                  &mut self,                  id: Option<&Id>,                  operate_on_children: &mut dyn FnMut(&mut dyn Operation<B>),              ) { -                let Self { operation, f } = self; +                let Self { operation, .. } = self;                  operation.container(id, &mut |operation| { -                    operate_on_children(&mut MapRef { operation, f }); +                    operate_on_children(&mut MapRef { operation });                  });              } + +            fn scrollable( +                &mut self, +                state: &mut dyn Scrollable, +                id: Option<&Id>, +            ) { +                self.operation.scrollable(state, id); +            } + +            fn focusable( +                &mut self, +                state: &mut dyn Focusable, +                id: Option<&Id>, +            ) { +                self.operation.focusable(state, id); +            }          } -        let Self { operation, f } = self; +        let Self { operation, .. } = self;          MapRef {              operation: operation.as_mut(), -            f,          }          .container(id, operate_on_children);      } @@ -85,4 +101,35 @@ where      ) {          self.operation.focusable(state, id);      } + +    fn scrollable( +        &mut self, +        state: &mut dyn operation::Scrollable, +        id: Option<&Id>, +    ) { +        self.operation.scrollable(state, id); +    } + +    fn text_input( +        &mut self, +        state: &mut dyn operation::TextInput, +        id: Option<&Id>, +    ) { +        self.operation.text_input(state, id); +    } + +    fn finish(&self) -> operation::Outcome<B> { +        match self.operation.finish() { +            operation::Outcome::None => operation::Outcome::None, +            operation::Outcome::Some(output) => { +                operation::Outcome::Some((self.f)(output)) +            } +            operation::Outcome::Chain(next) => { +                operation::Outcome::Chain(Box::new(Map { +                    operation: next, +                    f: self.f.clone(), +                })) +            } +        } +    }  } | 
