diff options
| author | 2022-12-13 09:31:57 +0100 | |
|---|---|---|
| committer | 2022-12-13 09:31:57 +0100 | |
| commit | 2e6d90f141217bad83eacd392562c13d7485881f (patch) | |
| tree | baa2c507076073aed4fd24abc9c7a7949d85c039 /native/src/overlay | |
| parent | ba95042fff378213f5029b2b164d79e768482a47 (diff) | |
| parent | 02182eea45537c9eb5b2bddfdff822bb8a3d143d (diff) | |
| download | iced-2e6d90f141217bad83eacd392562c13d7485881f.tar.gz iced-2e6d90f141217bad83eacd392562c13d7485881f.tar.bz2 iced-2e6d90f141217bad83eacd392562c13d7485881f.zip | |
Merge branch 'master' into feat/slider-orientation
Diffstat (limited to '')
| -rw-r--r-- | native/src/overlay.rs | 34 | ||||
| -rw-r--r-- | native/src/overlay/element.rs | 55 | ||||
| -rw-r--r-- | native/src/overlay/menu.rs | 24 | 
3 files changed, 65 insertions, 48 deletions
| diff --git a/native/src/overlay.rs b/native/src/overlay.rs index 905d3389..0b05b058 100644 --- a/native/src/overlay.rs +++ b/native/src/overlay.rs @@ -11,7 +11,7 @@ use crate::layout;  use crate::mouse;  use crate::renderer;  use crate::widget; -use crate::widget::tree::{self, Tree}; +use crate::widget::Tree;  use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size};  /// An interactive component that can be displayed on top of other widgets. @@ -42,31 +42,9 @@ 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`]. +    /// Applies a [`widget::Operation`] to the [`Overlay`].      fn operate( -        &self, +        &mut self,          _layout: Layout<'_>,          _operation: &mut dyn widget::Operation<Message>,      ) { @@ -115,7 +93,7 @@ where  /// 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>], +    children: &'a mut [crate::Element<'_, Message, Renderer>],      tree: &'a mut Tree,      layout: Layout<'_>,      renderer: &Renderer, @@ -124,11 +102,11 @@ where      Renderer: crate::Renderer,  {      children -        .iter() +        .iter_mut()          .zip(&mut tree.children)          .zip(layout.children())          .filter_map(|((child, state), layout)| { -            child.as_widget().overlay(state, layout, renderer) +            child.as_widget_mut().overlay(state, layout, renderer)          })          .next()  } diff --git a/native/src/overlay/element.rs b/native/src/overlay/element.rs index b919c221..4f5ef32a 100644 --- a/native/src/overlay/element.rs +++ b/native/src/overlay/element.rs @@ -104,9 +104,9 @@ where              .draw(renderer, theme, style, layout, cursor_position)      } -    /// Applies an [`Operation`] to the [`Element`]. +    /// Applies a [`widget::Operation`] to the [`Element`].      pub fn operate( -        &self, +        &mut self,          layout: Layout<'_>,          operation: &mut dyn widget::Operation<Message>,      ) { @@ -141,6 +141,57 @@ where          self.content.layout(renderer, bounds, position)      } +    fn operate( +        &mut self, +        layout: Layout<'_>, +        operation: &mut dyn widget::Operation<B>, +    ) { +        struct MapOperation<'a, B> { +            operation: &'a mut dyn widget::Operation<B>, +        } + +        impl<'a, T, B> widget::Operation<T> for MapOperation<'a, B> { +            fn container( +                &mut self, +                id: Option<&widget::Id>, +                operate_on_children: &mut dyn FnMut( +                    &mut dyn widget::Operation<T>, +                ), +            ) { +                self.operation.container(id, &mut |operation| { +                    operate_on_children(&mut MapOperation { operation }); +                }); +            } + +            fn focusable( +                &mut self, +                state: &mut dyn widget::operation::Focusable, +                id: Option<&widget::Id>, +            ) { +                self.operation.focusable(state, id); +            } + +            fn scrollable( +                &mut self, +                state: &mut dyn widget::operation::Scrollable, +                id: Option<&widget::Id>, +            ) { +                self.operation.scrollable(state, id); +            } + +            fn text_input( +                &mut self, +                state: &mut dyn widget::operation::TextInput, +                id: Option<&widget::Id>, +            ) { +                self.operation.text_input(state, id) +            } +        } + +        self.content +            .operate(layout, &mut MapOperation { operation }); +    } +      fn on_event(          &mut self,          event: Event, diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs index 08135872..099b1a97 100644 --- a/native/src/overlay/menu.rs +++ b/native/src/overlay/menu.rs @@ -9,7 +9,7 @@ use crate::text::{self, Text};  use crate::touch;  use crate::widget::container::{self, Container};  use crate::widget::scrollable::{self, Scrollable}; -use crate::widget::tree::{self, Tree}; +use crate::widget::Tree;  use crate::{      Clipboard, Color, Element, Layout, Length, Padding, Point, Rectangle,      Shell, Size, Vector, Widget, @@ -178,7 +178,7 @@ where              font,              text_size,              padding, -            style, +            style: style.clone(),          }));          state.tree.diff(&container as &dyn Widget<_, _>); @@ -199,18 +199,6 @@ where      Renderer: text::Renderer,      Renderer::Theme: StyleSheet + container::StyleSheet,  { -    fn tag(&self) -> tree::Tag { -        self.container.tag() -    } - -    fn state(&self) -> tree::State { -        self.container.state() -    } - -    fn children(&self) -> Vec<Tree> { -        self.container.children() -    } -      fn layout(          &self,          renderer: &Renderer, @@ -288,7 +276,7 @@ where          layout: Layout<'_>,          cursor_position: Point,      ) { -        let appearance = theme.appearance(self.style); +        let appearance = theme.appearance(&self.style);          let bounds = layout.bounds();          renderer.fill_quad( @@ -299,7 +287,7 @@ where                  },                  border_color: appearance.border_color,                  border_width: appearance.border_width, -                border_radius: appearance.border_radius, +                border_radius: appearance.border_radius.into(),              },              appearance.background,          ); @@ -460,7 +448,7 @@ where          _cursor_position: Point,          viewport: &Rectangle,      ) { -        let appearance = theme.appearance(self.style); +        let appearance = theme.appearance(&self.style);          let bounds = layout.bounds();          let text_size = @@ -491,7 +479,7 @@ where                          bounds,                          border_color: Color::TRANSPARENT,                          border_width: 0.0, -                        border_radius: appearance.border_radius, +                        border_radius: appearance.border_radius.into(),                      },                      appearance.selected_background,                  ); | 
