From fd7a23ca47b556ad82f2a8a9e3f849deb9f72f1b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 12 Mar 2024 15:42:41 +0100 Subject: Use closures for `PaneGrid::style` --- widget/src/pane_grid.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'widget/src/pane_grid.rs') 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 Message + 'a>>, on_drag: Option Message + 'a>>, on_resize: Option<(f32, Box Message + 'a>)>, - style: Style, + 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 = fn(&Theme) -> Appearance; +pub type Style<'a, Theme> = Box Appearance + 'a>; /// The default style of a [`PaneGrid`]. pub trait DefaultStyle { /// Returns the default style of a [`PaneGrid`]. - fn default_style() -> Style; + fn default_style(&self) -> Appearance; } impl DefaultStyle for Theme { - fn default_style() -> Style { - default + fn default_style(&self) -> Appearance { + default(self) } } impl DefaultStyle for Appearance { - fn default_style() -> Style { - |appearance| *appearance + fn default_style(&self) -> Appearance { + *self } } -- cgit