Leverage DefaultStyle traits instead of Default
This commit is contained in:
parent
44f002f64a
commit
833538ee7f
30 changed files with 393 additions and 437 deletions
|
|
@ -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 DefaultStyle for Theme {
|
||||
fn default_style() -> Style<Self> {
|
||||
primary
|
||||
}
|
||||
}
|
||||
|
||||
impl<Theme> Copy for Style<Theme> {}
|
||||
|
||||
impl Default for Style<Theme> {
|
||||
fn default() -> Self {
|
||||
Style(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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue