diff options
author | 2022-11-03 04:54:46 +0100 | |
---|---|---|
committer | 2022-11-03 04:54:46 +0100 | |
commit | a8f510c39917b2ac42fcc854f0a7eff13aee9838 (patch) | |
tree | 66773a33f34b2d31b10d3d1bee69e264760160a0 /style | |
parent | 231d2fd8454eb9d24ba970131d4d7339cc0c8d51 (diff) | |
parent | df7877767567cc0c7f48d2d6da4680a55f0f7b6d (diff) | |
download | iced-a8f510c39917b2ac42fcc854f0a7eff13aee9838.tar.gz iced-a8f510c39917b2ac42fcc854f0a7eff13aee9838.tar.bz2 iced-a8f510c39917b2ac42fcc854f0a7eff13aee9838.zip |
Merge pull request #1432 from wash2/custom-theme
Add custom palette to built in theme
Diffstat (limited to '')
-rw-r--r-- | style/src/theme.rs | 29 | ||||
-rw-r--r-- | style/src/theme/palette.rs | 8 |
2 files changed, 33 insertions, 4 deletions
diff --git a/style/src/theme.rs b/style/src/theme.rs index ea538c3a..a253e990 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,17 +21,23 @@ use crate::toggler; use iced_core::{Background, Color}; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq)] pub enum Theme { Light, Dark, + Custom(Box<Custom>), } impl Theme { - pub fn palette(self) -> Palette { + pub fn custom(palette: Palette) -> Self { + Self::Custom(Box::new(Custom::new(palette))) + } + + pub fn palette(&self) -> Palette { match self { Self::Light => Palette::LIGHT, Self::Dark => Palette::DARK, + Self::Custom(custom) => custom.palette, } } @@ -38,6 +45,7 @@ impl Theme { match self { Self::Light => &palette::EXTENDED_LIGHT, Self::Dark => &palette::EXTENDED_DARK, + Self::Custom(custom) => &custom.extended, } } } @@ -48,6 +56,21 @@ impl Default for Theme { } } +#[derive(Debug, Clone, Copy, 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, @@ -71,7 +94,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()), } } } 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, |