summaryrefslogtreecommitdiff
path: root/src/theme.rs
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-02-16 15:32:11 +0100
committerpml68 <contact@pml68.dev>2025-02-16 15:32:11 +0100
commiteea6c89ce603d452985581ebea3d42543142ab85 (patch)
tree3c71bd07cf2b99a5542ff19ce3207791a27810da /src/theme.rs
parentrefactor: random stuff (diff)
downloadiced-builder-eea6c89ce603d452985581ebea3d42543142ab85.tar.gz
feat!: add name to `Theme`, `is_dark` -> `dark`
Diffstat (limited to 'src/theme.rs')
-rw-r--r--src/theme.rs42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/theme.rs b/src/theme.rs
index db16372..7cb51c1 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -5,6 +5,9 @@ use iced::Color;
use crate::config::Config;
+const DEFAULT_THEME_CONTENT: &str =
+ include_str!("../assets/themes/rose_pine.toml");
+
pub fn theme_index(theme_name: &str, slice: &[iced::Theme]) -> Option<usize> {
slice
.iter()
@@ -166,20 +169,41 @@ pub struct Appearance {
impl Default for Appearance {
fn default() -> Self {
Self {
- selected: iced::Theme::default(),
- all: iced::Theme::ALL.into(),
+ selected: Theme::default().into(),
+ all: {
+ let mut themes = iced::Theme::ALL.to_owned();
+ themes.push(Theme::default().into());
+ themes.into()
+ },
}
}
}
-#[derive(Debug, Default, serde::Deserialize)]
+#[derive(Debug, serde::Deserialize)]
pub struct Theme {
+ name: String,
palette: ThemePalette,
- is_dark: Option<bool>,
+ dark: Option<bool>,
#[serde(flatten)]
extended: Option<ExtendedThemePalette>,
}
+impl From<Theme> for iced::Theme {
+ fn from(value: Theme) -> Self {
+ iced::Theme::custom_with_fn(
+ value.name.clone(),
+ value.palette.clone().into(),
+ |_| value.into(),
+ )
+ }
+}
+
+impl Default for Theme {
+ fn default() -> Self {
+ toml::from_str(DEFAULT_THEME_CONTENT).expect("parse default theme")
+ }
+}
+
#[derive(Debug, Clone, serde::Deserialize)]
pub struct ThemePalette {
#[serde(with = "color_serde")]
@@ -194,14 +218,6 @@ pub struct ThemePalette {
danger: Color,
}
-impl Theme {
- pub fn into_iced_theme(self, name: String) -> iced::Theme {
- iced::Theme::custom_with_fn(name, self.palette.clone().into(), |_| {
- self.into()
- })
- }
-}
-
impl Default for ThemePalette {
fn default() -> Self {
let palette = iced::Theme::default().palette();
@@ -231,7 +247,7 @@ impl From<Theme> for Extended {
fn from(theme: Theme) -> Self {
let mut extended = Extended::generate(theme.palette.into());
- if let Some(is_dark) = theme.is_dark {
+ if let Some(is_dark) = theme.dark {
extended.is_dark = is_dark;
}