From e2166ecad020662d246b364637efc4e6ee3bc1db Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 7 Sep 2022 11:56:11 -0400 Subject: wip: Custom palette for built in theme --- style/src/theme.rs | 9 ++++++++- style/src/theme/palette.rs | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'style') diff --git a/style/src/theme.rs b/style/src/theme.rs index ea538c3a..7d47f1a1 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -1,5 +1,6 @@ pub mod palette; +use self::palette::Extended; pub use self::palette::Palette; use crate::application; @@ -20,10 +21,14 @@ use crate::toggler; use iced_core::{Background, Color}; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum Theme { Light, Dark, + Custom { + palette: Palette, + extended: Extended + } } impl Theme { @@ -31,6 +36,7 @@ impl Theme { match self { Self::Light => Palette::LIGHT, Self::Dark => Palette::DARK, + Self::Custom { palette, .. } => palette } } @@ -38,6 +44,7 @@ impl Theme { match self { Self::Light => &palette::EXTENDED_LIGHT, Self::Dark => &palette::EXTENDED_DARK, + Self::Custom { extended, .. } => extended, } } } diff --git a/style/src/theme/palette.rs b/style/src/theme/palette.rs index 4fb5e4c8..b3a10d28 100644 --- a/style/src/theme/palette.rs +++ b/style/src/theme/palette.rs @@ -58,6 +58,7 @@ impl Palette { }; } +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Extended { pub background: Background, pub primary: Primary, @@ -95,7 +96,7 @@ impl Extended { } } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Pair { pub color: Color, pub text: Color, @@ -110,6 +111,7 @@ impl Pair { } } +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Background { pub base: Pair, pub weak: Pair, @@ -129,6 +131,7 @@ impl Background { } } +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Primary { pub base: Pair, pub weak: Pair, @@ -148,6 +151,7 @@ impl Primary { } } +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Secondary { pub base: Pair, pub weak: Pair, @@ -168,6 +172,7 @@ impl Secondary { } } +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Success { pub base: Pair, pub weak: Pair, @@ -187,6 +192,7 @@ impl Success { } } +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Danger { pub base: Pair, pub weak: Pair, -- cgit From 4f3215f48e72ed36cb77efcb746db1f6adabf84f Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Sat, 10 Sep 2022 22:15:25 -0400 Subject: fix: clippy lint https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant --- style/src/theme.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'style') diff --git a/style/src/theme.rs b/style/src/theme.rs index 7d47f1a1..4e83758b 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -21,13 +21,13 @@ use crate::toggler; use iced_core::{Background, Color}; -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub enum Theme { Light, Dark, Custom { - palette: Palette, - extended: Extended + palette: Box, + extended: Box, } } @@ -36,7 +36,7 @@ impl Theme { match self { Self::Light => Palette::LIGHT, Self::Dark => Palette::DARK, - Self::Custom { palette, .. } => palette + Self::Custom { palette, .. } => *palette } } @@ -78,7 +78,7 @@ impl application::StyleSheet for Theme { background_color: palette.background.base.color, text_color: palette.background.base.text, }, - Application::Custom(f) => f(*self), + Application::Custom(f) => f(self.clone()), } } } -- cgit From 9966c6f8834220e62fd66766d2e11d8a36e334e2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 03:21:26 +0100 Subject: Make `Theme::Custom` fields opaque --- style/src/theme.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'style') diff --git a/style/src/theme.rs b/style/src/theme.rs index 4e83758b..35945aca 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -25,18 +25,19 @@ use iced_core::{Background, Color}; pub enum Theme { Light, Dark, - Custom { - palette: Box, - extended: Box, - } + Custom(Custom), } impl Theme { + pub fn custom(palette: Palette) -> Self { + Self::Custom(Custom::new(palette)) + } + pub fn palette(self) -> Palette { match self { Self::Light => Palette::LIGHT, Self::Dark => Palette::DARK, - Self::Custom { palette, .. } => *palette + Self::Custom(custom) => custom.palette, } } @@ -44,7 +45,7 @@ impl Theme { match self { Self::Light => &palette::EXTENDED_LIGHT, Self::Dark => &palette::EXTENDED_DARK, - Self::Custom { extended, .. } => extended, + Self::Custom(custom) => &custom.extended, } } } @@ -55,6 +56,21 @@ impl Default for Theme { } } +#[derive(Debug, Clone, PartialEq)] +pub struct Custom { + palette: Palette, + extended: Extended, +} + +impl Custom { + pub fn new(palette: Palette) -> Self { + Self { + palette, + extended: Extended::generate(palette), + } + } +} + #[derive(Debug, Clone, Copy)] pub enum Application { Default, -- cgit From 708be32e3da9700afb61ab2f8a6da45b0e2df8ef Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 03:22:55 +0100 Subject: Derive `Copy` for `Theme` --- style/src/theme.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'style') diff --git a/style/src/theme.rs b/style/src/theme.rs index 35945aca..723c60d6 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -21,7 +21,7 @@ use crate::toggler; use iced_core::{Background, Color}; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum Theme { Light, Dark, @@ -56,7 +56,7 @@ impl Default for Theme { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Custom { palette: Palette, extended: Extended, -- cgit From df7877767567cc0c7f48d2d6da4680a55f0f7b6d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 03:27:55 +0100 Subject: Box `Custom` in `Theme` --- style/src/theme.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'style') diff --git a/style/src/theme.rs b/style/src/theme.rs index 723c60d6..a253e990 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -21,19 +21,19 @@ use crate::toggler; use iced_core::{Background, Color}; -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub enum Theme { Light, Dark, - Custom(Custom), + Custom(Box), } impl Theme { pub fn custom(palette: Palette) -> Self { - Self::Custom(Custom::new(palette)) + Self::Custom(Box::new(Custom::new(palette))) } - pub fn palette(self) -> Palette { + pub fn palette(&self) -> Palette { match self { Self::Light => Palette::LIGHT, Self::Dark => Palette::DARK, -- cgit