summaryrefslogtreecommitdiffstats
path: root/style/src
diff options
context:
space:
mode:
Diffstat (limited to 'style/src')
-rw-r--r--style/src/radio.rs4
-rw-r--r--style/src/theme.rs43
-rw-r--r--style/src/theme/palette.rs19
-rw-r--r--style/src/toggler.rs2
4 files changed, 52 insertions, 16 deletions
diff --git a/style/src/radio.rs b/style/src/radio.rs
index a4d4a83b..d14ea33e 100644
--- a/style/src/radio.rs
+++ b/style/src/radio.rs
@@ -15,7 +15,7 @@ pub struct Appearance {
pub trait StyleSheet {
type Style: Default + Copy;
- fn active(&self, style: Self::Style) -> Appearance;
+ fn active(&self, style: Self::Style, is_selected: bool) -> Appearance;
- fn hovered(&self, style: Self::Style) -> Appearance;
+ fn hovered(&self, style: Self::Style, is_selected: bool) -> Appearance;
}
diff --git a/style/src/theme.rs b/style/src/theme.rs
index 9e9abfa0..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()),
}
}
}
@@ -415,7 +438,11 @@ impl pick_list::StyleSheet for Theme {
impl radio::StyleSheet for Theme {
type Style = ();
- fn active(&self, _style: Self::Style) -> radio::Appearance {
+ fn active(
+ &self,
+ _style: Self::Style,
+ _is_selected: bool,
+ ) -> radio::Appearance {
let palette = self.extended_palette();
radio::Appearance {
@@ -427,8 +454,12 @@ impl radio::StyleSheet for Theme {
}
}
- fn hovered(&self, style: Self::Style) -> radio::Appearance {
- let active = self.active(style);
+ fn hovered(
+ &self,
+ style: Self::Style,
+ is_selected: bool,
+ ) -> radio::Appearance {
+ let active = self.active(style, is_selected);
let palette = self.extended_palette();
radio::Appearance {
diff --git a/style/src/theme/palette.rs b/style/src/theme/palette.rs
index 81aa9cc7..b3a10d28 100644
--- a/style/src/theme/palette.rs
+++ b/style/src/theme/palette.rs
@@ -1,6 +1,6 @@
use iced_core::Color;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use palette::{FromColor, Hsl, Mix, RelativeContrast, Srgb};
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -58,6 +58,7 @@ impl Palette {
};
}
+#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Extended {
pub background: Background,
pub primary: Primary,
@@ -66,11 +67,10 @@ pub struct Extended {
pub danger: Danger,
}
-lazy_static! {
- pub static ref EXTENDED_LIGHT: Extended =
- Extended::generate(Palette::LIGHT);
- pub static ref EXTENDED_DARK: Extended = Extended::generate(Palette::DARK);
-}
+pub static EXTENDED_LIGHT: Lazy<Extended> =
+ Lazy::new(|| Extended::generate(Palette::LIGHT));
+pub static EXTENDED_DARK: Lazy<Extended> =
+ Lazy::new(|| Extended::generate(Palette::DARK));
impl Extended {
pub fn generate(palette: Palette) -> Self {
@@ -96,7 +96,7 @@ impl Extended {
}
}
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Pair {
pub color: Color,
pub text: Color,
@@ -111,6 +111,7 @@ impl Pair {
}
}
+#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Background {
pub base: Pair,
pub weak: Pair,
@@ -130,6 +131,7 @@ impl Background {
}
}
+#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Primary {
pub base: Pair,
pub weak: Pair,
@@ -149,6 +151,7 @@ impl Primary {
}
}
+#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Secondary {
pub base: Pair,
pub weak: Pair,
@@ -169,6 +172,7 @@ impl Secondary {
}
}
+#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Success {
pub base: Pair,
pub weak: Pair,
@@ -188,6 +192,7 @@ impl Success {
}
}
+#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Danger {
pub base: Pair,
pub weak: Pair,
diff --git a/style/src/toggler.rs b/style/src/toggler.rs
index 4ee7db46..0acf8e97 100644
--- a/style/src/toggler.rs
+++ b/style/src/toggler.rs
@@ -2,7 +2,7 @@
use iced_core::Color;
/// The appearance of a toggler.
-#[derive(Debug)]
+#[derive(Debug, Clone, Copy)]
pub struct Appearance {
pub background: Color,
pub background_border: Option<Color>,