summaryrefslogtreecommitdiffstats
path: root/style
diff options
context:
space:
mode:
Diffstat (limited to 'style')
-rw-r--r--style/Cargo.toml4
-rw-r--r--style/src/theme.rs29
-rw-r--r--style/src/theme/palette.rs19
3 files changed, 40 insertions, 12 deletions
diff --git a/style/Cargo.toml b/style/Cargo.toml
index cf9d328b..4a482a4f 100644
--- a/style/Cargo.toml
+++ b/style/Cargo.toml
@@ -18,5 +18,5 @@ features = ["palette"]
[dependencies.palette]
version = "0.6"
-[dependencies.lazy_static]
-version = "1.4"
+[dependencies.once_cell]
+version = "1.15"
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 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,