summaryrefslogtreecommitdiffstats
path: root/style/src/theme.rs
diff options
context:
space:
mode:
Diffstat (limited to 'style/src/theme.rs')
-rw-r--r--style/src/theme.rs79
1 files changed, 71 insertions, 8 deletions
diff --git a/style/src/theme.rs b/style/src/theme.rs
index 7d420c8a..91a9e921 100644
--- a/style/src/theme.rs
+++ b/style/src/theme.rs
@@ -1,6 +1,10 @@
+mod palette;
+
+pub use self::palette::Palette;
+
use crate::button;
-use iced_core::{Color, Vector};
+use iced_core::Background;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Theme {
@@ -8,6 +12,22 @@ pub enum Theme {
Dark,
}
+impl Theme {
+ pub fn palette(self) -> Palette {
+ match self {
+ Self::Light => Palette::LIGHT,
+ Self::Dark => Palette::DARK,
+ }
+ }
+
+ fn extended_palette(&self) -> &palette::Extended {
+ match self {
+ Self::Light => &palette::EXTENDED_LIGHT,
+ Self::Dark => &palette::EXTENDED_DARK,
+ }
+ }
+}
+
impl Default for Theme {
fn default() -> Self {
Self::Light
@@ -32,14 +52,57 @@ impl Default for Button {
impl button::StyleSheet for Theme {
type Variant = Button;
- fn active(&self, _variant: Self::Variant) -> button::Style {
+ fn active(&self, variant: Self::Variant) -> button::Style {
+ let palette = self.extended_palette();
+
+ let style = button::Style {
+ border_radius: 2.0,
+ ..button::Style::default()
+ };
+
+ match variant {
+ Button::Primary => button::Style {
+ background: Some(palette.primary.strong.into()),
+ text_color: palette.primary.text,
+ ..style
+ },
+ Button::Secondary => button::Style {
+ background: Some(palette.background.weak.into()),
+ text_color: palette.background.text,
+ ..style
+ },
+ Button::Positive => button::Style {
+ background: Some(palette.success.base.into()),
+ text_color: palette.success.text,
+ ..style
+ },
+ Button::Destructive => button::Style {
+ background: Some(palette.danger.base.into()),
+ text_color: palette.danger.text,
+ ..style
+ },
+ Button::Text => button::Style {
+ text_color: palette.background.text,
+ ..style
+ },
+ }
+ }
+
+ fn hovered(&self, variant: Self::Variant) -> button::Style {
+ let active = self.active(variant);
+ let palette = self.extended_palette();
+
+ let background = match variant {
+ Button::Primary => Some(palette.primary.base),
+ Button::Secondary => Some(palette.background.strong),
+ Button::Positive => Some(palette.success.strong),
+ Button::Destructive => Some(palette.danger.strong),
+ Button::Text => None,
+ };
+
button::Style {
- shadow_offset: Vector::default(),
- background: None,
- border_radius: 0.0,
- border_width: 0.0,
- border_color: Color::TRANSPARENT,
- text_color: Color::BLACK,
+ background: background.map(Background::from),
+ ..active
}
}
}