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/src') 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