From bb07d017e8c8e43ac74f66bf649643bebdc5f71d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 20:07:33 +0200 Subject: Add `Style` variant support to `application::StyleSheet` --- style/src/application.rs | 10 ++++++++-- style/src/theme.rs | 26 ++++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'style/src') diff --git a/style/src/application.rs b/style/src/application.rs index 4aa950fb..d48c6a34 100644 --- a/style/src/application.rs +++ b/style/src/application.rs @@ -1,7 +1,13 @@ use iced_core::Color; pub trait StyleSheet { - fn background_color(&self) -> Color; + type Style: Default + Copy; - fn text_color(&self) -> Color; + fn appearance(&self, style: Self::Style) -> Appearance; +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Appearance { + pub background_color: Color, + pub text_color: Color, } diff --git a/style/src/theme.rs b/style/src/theme.rs index 0bae671e..70b32edf 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -48,17 +48,31 @@ impl Default for Theme { } } -impl application::StyleSheet for Theme { - fn background_color(&self) -> Color { - let palette = self.extended_palette(); +#[derive(Debug, Clone, Copy)] +pub enum Application { + Default, + Custom(fn(Theme) -> application::Appearance), +} - palette.background.base.color +impl Default for Application { + fn default() -> Self { + Self::Default } +} - fn text_color(&self) -> Color { +impl application::StyleSheet for Theme { + type Style = Application; + + fn appearance(&self, style: Self::Style) -> application::Appearance { let palette = self.extended_palette(); - palette.background.base.text + match style { + Application::Default => application::Appearance { + background_color: palette.background.base.color, + text_color: palette.background.base.text, + }, + Application::Custom(f) => f(*self), + } } } -- cgit