diff options
Diffstat (limited to 'widget/src/toggler.rs')
-rw-r--r-- | widget/src/toggler.rs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index adc82f73..6b540f1c 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -72,7 +72,7 @@ where f: F, ) -> Self where - Style<Theme>: Default, + Theme: DefaultStyle, F: 'a + Fn(bool) -> Message, { Toggler { @@ -87,7 +87,7 @@ where text_shaping: text::Shaping::Basic, spacing: Self::DEFAULT_SIZE / 2.0, font: None, - style: Style::default(), + style: Theme::default_style(), } } @@ -299,7 +299,7 @@ where } }; - let appearance = (self.style.0)(theme, status); + let appearance = (self.style)(theme, status); let border_radius = bounds.height / BORDER_RADIUS_RATIO; let space = SPACE_RATIO * bounds.height; @@ -398,26 +398,23 @@ pub struct Appearance { } /// The style of a [`Toggler`]. -#[derive(Debug, PartialEq, Eq)] -pub struct Style<Theme>(fn(&Theme, Status) -> Appearance); +pub type Style<Theme> = fn(&Theme, Status) -> Appearance; -impl<Theme> Clone for Style<Theme> { - fn clone(&self) -> Self { - *self - } +/// The default style of a [`Toggler`]. +pub trait DefaultStyle { + /// Returns the default style of a [`Toggler`]. + fn default_style() -> Style<Self>; } -impl<Theme> Copy for Style<Theme> {} - -impl Default for Style<Theme> { - fn default() -> Self { - Style(default) +impl DefaultStyle for Theme { + fn default_style() -> Style<Self> { + default } } -impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> { - fn from(f: fn(&Theme, Status) -> Appearance) -> Self { - Style(f) +impl DefaultStyle for Appearance { + fn default_style() -> Style<Self> { + |appearance, _status| *appearance } } |