From 833538ee7f3a60a839304762dfc29b0881d19094 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 7 Mar 2024 20:11:32 +0100 Subject: Leverage `DefaultStyle` traits instead of `Default` --- widget/src/pane_grid.rs | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'widget/src/pane_grid.rs') diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index 5403b2f5..d60d5e3b 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -126,7 +126,7 @@ where view: impl Fn(Pane, &'a T, bool) -> Content<'a, Message, Theme, Renderer>, ) -> Self where - Style: Default, + Theme: DefaultStyle, { 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: Style::default(), + style: Theme::default_style(), } } @@ -219,7 +219,7 @@ where /// Sets the style of the [`PaneGrid`]. pub fn style(mut self, style: fn(&Theme) -> Appearance) -> Self { - self.style = Style(style); + self.style = style; self } @@ -677,7 +677,7 @@ where None }; - let appearance = (self.style.0)(theme); + let appearance = (self.style)(theme); for ((id, (content, tree)), pane_layout) in contents.zip(layout.children()) @@ -1146,26 +1146,23 @@ pub struct Line { } /// The style of a [`PaneGrid`]. -#[derive(Debug, PartialEq, Eq)] -pub struct Style(fn(&Theme) -> Appearance); +pub type Style = fn(&Theme) -> Appearance; -impl Clone for Style { - fn clone(&self) -> Self { - *self - } +/// The default style of a [`PaneGrid`]. +pub trait DefaultStyle { + /// Returns the default style of a [`PaneGrid`]. + fn default_style() -> Style; } -impl Copy for Style {} - -impl Default for Style { - fn default() -> Self { - Style(default) +impl DefaultStyle for Theme { + fn default_style() -> Style { + default } } -impl From Appearance> for Style { - fn from(f: fn(&Theme) -> Appearance) -> Self { - Style(f) +impl DefaultStyle for Appearance { + fn default_style() -> Style { + |appearance| *appearance } } -- cgit