From 84a1edecea8ab7d7b8aa76b77f2f44042602dd67 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 9 Nov 2022 04:07:42 +0100 Subject: Use `derive(Default)` for `theme` types --- style/src/theme.rs | 66 +++++++++++++----------------------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/style/src/theme.rs b/style/src/theme.rs index a5a78ab1..ca2d1904 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -23,8 +23,9 @@ use iced_core::{Background, Color, Vector}; use std::rc::Rc; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Default)] pub enum Theme { + #[default] Light, Dark, Custom(Box), @@ -52,12 +53,6 @@ impl Theme { } } -impl Default for Theme { - fn default() -> Self { - Self::Light - } -} - #[derive(Debug, Clone, Copy, PartialEq)] pub struct Custom { palette: Palette, @@ -73,17 +68,13 @@ impl Custom { } } +#[derive(Default)] pub enum Application { + #[default] Default, Custom(Box>), } -impl Default for Application { - fn default() -> Self { - Self::Default - } -} - impl application::StyleSheet for Theme { type Style = Application; @@ -117,7 +108,9 @@ impl From application::Appearance> for Application { /* * Button */ +#[derive(Default)] pub enum Button { + #[default] Primary, Secondary, Positive, @@ -126,12 +119,6 @@ pub enum Button { Custom(Box>), } -impl Default for Button { - fn default() -> Self { - Self::Primary - } -} - impl button::StyleSheet for Theme { type Style = Button; @@ -223,7 +210,9 @@ impl button::StyleSheet for Theme { /* * Checkbox */ +#[derive(Default)] pub enum Checkbox { + #[default] Primary, Secondary, Success, @@ -231,12 +220,6 @@ pub enum Checkbox { Custom(Box>), } -impl Default for Checkbox { - fn default() -> Self { - Self::Primary - } -} - impl checkbox::StyleSheet for Theme { type Style = Checkbox; @@ -336,18 +319,14 @@ fn checkbox_appearance( /* * Container */ +#[derive(Default)] pub enum Container { + #[default] Transparent, Box, Custom(Box>), } -impl Default for Container { - fn default() -> Self { - Self::Transparent - } -} - impl From container::Appearance> for Container { fn from(f: fn(&Theme) -> container::Appearance) -> Self { Self::Custom(Box::new(f)) @@ -729,19 +708,15 @@ impl pane_grid::StyleSheet for Theme { /* * Progress Bar */ +#[derive(Default)] pub enum ProgressBar { + #[default] Primary, Success, Danger, Custom(Box>), } -impl Default for ProgressBar { - fn default() -> Self { - Self::Primary - } -} - impl From progress_bar::Appearance> for ProgressBar { fn from(f: fn(&Theme) -> progress_bar::Appearance) -> Self { Self::Custom(Box::new(f)) @@ -784,17 +759,13 @@ impl progress_bar::StyleSheet for fn(&Theme) -> progress_bar::Appearance { /* * Rule */ +#[derive(Default)] pub enum Rule { + #[default] Default, Custom(Box>), } -impl Default for Rule { - fn default() -> Self { - Self::Default - } -} - impl From rule::Appearance> for Rule { fn from(f: fn(&Theme) -> rule::Appearance) -> Self { Self::Custom(Box::new(f)) @@ -895,18 +866,13 @@ impl scrollable::StyleSheet for Theme { /* * Text */ -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Default)] pub enum Text { + #[default] Default, Color(Color), } -impl Default for Text { - fn default() -> Self { - Self::Default - } -} - impl From for Text { fn from(color: Color) -> Self { Text::Color(color) -- cgit