summaryrefslogtreecommitdiffstats
path: root/widget/src/checkbox.rs
diff options
context:
space:
mode:
Diffstat (limited to 'widget/src/checkbox.rs')
-rw-r--r--widget/src/checkbox.rs33
1 files changed, 15 insertions, 18 deletions
diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs
index a297627b..c837ab3f 100644
--- a/widget/src/checkbox.rs
+++ b/widget/src/checkbox.rs
@@ -71,7 +71,7 @@ where
/// * a boolean describing whether the [`Checkbox`] is checked or not
pub fn new(label: impl Into<String>, is_checked: bool) -> Self
where
- Style<Theme>: Default,
+ Theme: DefaultStyle,
{
Checkbox {
is_checked,
@@ -91,7 +91,7 @@ where
line_height: text::LineHeight::default(),
shaping: text::Shaping::Basic,
},
- style: Style::default(),
+ style: Theme::default_style(),
}
}
@@ -175,7 +175,7 @@ where
/// Sets the style of the [`Checkbox`].
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
- self.style = Style(style);
+ self.style = style;
self
}
}
@@ -301,7 +301,7 @@ where
Status::Active { is_checked }
};
- let appearance = (self.style.0)(theme, status);
+ let appearance = (self.style)(theme, status);
{
let layout = children.next().unwrap();
@@ -424,26 +424,23 @@ pub struct Appearance {
}
/// The style of a [`Checkbox`].
-#[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 [`Checkbox`].
+pub trait DefaultStyle {
+ /// Returns the default style of a [`Checkbox`].
+ fn default_style() -> Style<Self>;
}
-impl<Theme> Copy for Style<Theme> {}
-
-impl Default for Style<Theme> {
- fn default() -> Self {
- Style(primary)
+impl DefaultStyle for Theme {
+ fn default_style() -> Style<Self> {
+ primary
}
}
-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
}
}