diff options
author | 2024-03-12 15:42:41 +0100 | |
---|---|---|
committer | 2024-03-12 15:42:41 +0100 | |
commit | fd7a23ca47b556ad82f2a8a9e3f849deb9f72f1b (patch) | |
tree | 697335eb2f0ea28928e13400ef11f45fb999d97a /widget | |
parent | d1e40495410049aedb6756be1febd83bae5eee1e (diff) | |
download | iced-fd7a23ca47b556ad82f2a8a9e3f849deb9f72f1b.tar.gz iced-fd7a23ca47b556ad82f2a8a9e3f849deb9f72f1b.tar.bz2 iced-fd7a23ca47b556ad82f2a8a9e3f849deb9f72f1b.zip |
Use closures for `PaneGrid::style`
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/pane_grid.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index bdeb4250..beac0bd8 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -110,7 +110,7 @@ pub struct PaneGrid< on_click: Option<Box<dyn Fn(Pane) -> Message + 'a>>, on_drag: Option<Box<dyn Fn(DragEvent) -> Message + 'a>>, on_resize: Option<(f32, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>, - style: Style<Theme>, + style: Style<'a, Theme>, } impl<'a, Message, Theme, Renderer> PaneGrid<'a, Message, Theme, Renderer> @@ -126,7 +126,7 @@ where view: impl Fn(Pane, &'a T, bool) -> Content<'a, Message, Theme, Renderer>, ) -> Self where - Theme: DefaultStyle, + Theme: DefaultStyle + 'a, { let contents = if let Some((pane, pane_state)) = state.maximized.and_then(|pane| { @@ -158,7 +158,7 @@ where on_click: None, on_drag: None, on_resize: None, - style: Theme::default_style(), + style: Box::new(Theme::default_style), } } @@ -218,8 +218,8 @@ where } /// Sets the style of the [`PaneGrid`]. - pub fn style(mut self, style: fn(&Theme) -> Appearance) -> Self { - self.style = style; + pub fn style(mut self, style: impl Fn(&Theme) -> Appearance + 'a) -> Self { + self.style = Box::new(style); self } @@ -1146,23 +1146,23 @@ pub struct Line { } /// The style of a [`PaneGrid`]. -pub type Style<Theme> = fn(&Theme) -> Appearance; +pub type Style<'a, Theme> = Box<dyn Fn(&Theme) -> Appearance + 'a>; /// The default style of a [`PaneGrid`]. pub trait DefaultStyle { /// Returns the default style of a [`PaneGrid`]. - fn default_style() -> Style<Self>; + fn default_style(&self) -> Appearance; } impl DefaultStyle for Theme { - fn default_style() -> Style<Self> { - default + fn default_style(&self) -> Appearance { + default(self) } } impl DefaultStyle for Appearance { - fn default_style() -> Style<Self> { - |appearance| *appearance + fn default_style(&self) -> Appearance { + *self } } |