Use derive(Default) for theme types

This commit is contained in:
Héctor Ramón Jiménez 2022-11-09 04:07:42 +01:00
parent 18fb74f200
commit 84a1edecea
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -23,8 +23,9 @@ use iced_core::{Background, Color, Vector};
use std::rc::Rc; use std::rc::Rc;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Default)]
pub enum Theme { pub enum Theme {
#[default]
Light, Light,
Dark, Dark,
Custom(Box<Custom>), Custom(Box<Custom>),
@ -52,12 +53,6 @@ impl Theme {
} }
} }
impl Default for Theme {
fn default() -> Self {
Self::Light
}
}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct Custom { pub struct Custom {
palette: Palette, palette: Palette,
@ -73,17 +68,13 @@ impl Custom {
} }
} }
#[derive(Default)]
pub enum Application { pub enum Application {
#[default]
Default, Default,
Custom(Box<dyn application::StyleSheet<Style = Theme>>), Custom(Box<dyn application::StyleSheet<Style = Theme>>),
} }
impl Default for Application {
fn default() -> Self {
Self::Default
}
}
impl application::StyleSheet for Theme { impl application::StyleSheet for Theme {
type Style = Application; type Style = Application;
@ -117,7 +108,9 @@ impl From<fn(&Theme) -> application::Appearance> for Application {
/* /*
* Button * Button
*/ */
#[derive(Default)]
pub enum Button { pub enum Button {
#[default]
Primary, Primary,
Secondary, Secondary,
Positive, Positive,
@ -126,12 +119,6 @@ pub enum Button {
Custom(Box<dyn button::StyleSheet<Style = Theme>>), Custom(Box<dyn button::StyleSheet<Style = Theme>>),
} }
impl Default for Button {
fn default() -> Self {
Self::Primary
}
}
impl button::StyleSheet for Theme { impl button::StyleSheet for Theme {
type Style = Button; type Style = Button;
@ -223,7 +210,9 @@ impl button::StyleSheet for Theme {
/* /*
* Checkbox * Checkbox
*/ */
#[derive(Default)]
pub enum Checkbox { pub enum Checkbox {
#[default]
Primary, Primary,
Secondary, Secondary,
Success, Success,
@ -231,12 +220,6 @@ pub enum Checkbox {
Custom(Box<dyn checkbox::StyleSheet<Style = Theme>>), Custom(Box<dyn checkbox::StyleSheet<Style = Theme>>),
} }
impl Default for Checkbox {
fn default() -> Self {
Self::Primary
}
}
impl checkbox::StyleSheet for Theme { impl checkbox::StyleSheet for Theme {
type Style = Checkbox; type Style = Checkbox;
@ -336,18 +319,14 @@ fn checkbox_appearance(
/* /*
* Container * Container
*/ */
#[derive(Default)]
pub enum Container { pub enum Container {
#[default]
Transparent, Transparent,
Box, Box,
Custom(Box<dyn container::StyleSheet<Style = Theme>>), Custom(Box<dyn container::StyleSheet<Style = Theme>>),
} }
impl Default for Container {
fn default() -> Self {
Self::Transparent
}
}
impl From<fn(&Theme) -> container::Appearance> for Container { impl From<fn(&Theme) -> container::Appearance> for Container {
fn from(f: fn(&Theme) -> container::Appearance) -> Self { fn from(f: fn(&Theme) -> container::Appearance) -> Self {
Self::Custom(Box::new(f)) Self::Custom(Box::new(f))
@ -729,19 +708,15 @@ impl pane_grid::StyleSheet for Theme {
/* /*
* Progress Bar * Progress Bar
*/ */
#[derive(Default)]
pub enum ProgressBar { pub enum ProgressBar {
#[default]
Primary, Primary,
Success, Success,
Danger, Danger,
Custom(Box<dyn progress_bar::StyleSheet<Style = Theme>>), Custom(Box<dyn progress_bar::StyleSheet<Style = Theme>>),
} }
impl Default for ProgressBar {
fn default() -> Self {
Self::Primary
}
}
impl From<fn(&Theme) -> progress_bar::Appearance> for ProgressBar { impl From<fn(&Theme) -> progress_bar::Appearance> for ProgressBar {
fn from(f: fn(&Theme) -> progress_bar::Appearance) -> Self { fn from(f: fn(&Theme) -> progress_bar::Appearance) -> Self {
Self::Custom(Box::new(f)) Self::Custom(Box::new(f))
@ -784,17 +759,13 @@ impl progress_bar::StyleSheet for fn(&Theme) -> progress_bar::Appearance {
/* /*
* Rule * Rule
*/ */
#[derive(Default)]
pub enum Rule { pub enum Rule {
#[default]
Default, Default,
Custom(Box<dyn rule::StyleSheet<Style = Theme>>), Custom(Box<dyn rule::StyleSheet<Style = Theme>>),
} }
impl Default for Rule {
fn default() -> Self {
Self::Default
}
}
impl From<fn(&Theme) -> rule::Appearance> for Rule { impl From<fn(&Theme) -> rule::Appearance> for Rule {
fn from(f: fn(&Theme) -> rule::Appearance) -> Self { fn from(f: fn(&Theme) -> rule::Appearance) -> Self {
Self::Custom(Box::new(f)) Self::Custom(Box::new(f))
@ -895,18 +866,13 @@ impl scrollable::StyleSheet for Theme {
/* /*
* Text * Text
*/ */
#[derive(Clone, Copy)] #[derive(Clone, Copy, Default)]
pub enum Text { pub enum Text {
#[default]
Default, Default,
Color(Color), Color(Color),
} }
impl Default for Text {
fn default() -> Self {
Self::Default
}
}
impl From<Color> for Text { impl From<Color> for Text {
fn from(color: Color) -> Self { fn from(color: Color) -> Self {
Text::Color(color) Text::Color(color)