cosmic_theme/model/
cosmic_palette.rs

1use lazy_static::lazy_static;
2use palette::Srgba;
3use serde::{Deserialize, Serialize};
4
5lazy_static! {
6    /// built in light palette
7    pub static ref LIGHT_PALETTE: CosmicPalette =
8        ron::from_str(include_str!("light.ron")).unwrap();
9    /// built in dark palette
10    pub static ref DARK_PALETTE: CosmicPalette =
11        ron::from_str(include_str!("dark.ron")).unwrap();
12}
13
14/// Palette type
15#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
16pub enum CosmicPalette {
17    /// Dark mode
18    Dark(CosmicPaletteInner),
19    /// Light mode
20    Light(CosmicPaletteInner),
21    /// High contrast light mode
22    HighContrastLight(CosmicPaletteInner),
23    /// High contrast dark mode
24    HighContrastDark(CosmicPaletteInner),
25}
26
27impl CosmicPalette {
28    /// extract the inner palette
29    #[inline]
30    pub fn inner(self) -> CosmicPaletteInner {
31        match self {
32            CosmicPalette::Dark(p) => p,
33            CosmicPalette::Light(p) => p,
34            CosmicPalette::HighContrastLight(p) => p,
35            CosmicPalette::HighContrastDark(p) => p,
36        }
37    }
38}
39
40impl AsMut<CosmicPaletteInner> for CosmicPalette {
41    #[inline]
42    fn as_mut(&mut self) -> &mut CosmicPaletteInner {
43        match self {
44            CosmicPalette::Dark(p) => p,
45            CosmicPalette::Light(p) => p,
46            CosmicPalette::HighContrastLight(p) => p,
47            CosmicPalette::HighContrastDark(p) => p,
48        }
49    }
50}
51
52impl AsRef<CosmicPaletteInner> for CosmicPalette {
53    #[inline]
54    fn as_ref(&self) -> &CosmicPaletteInner {
55        match self {
56            CosmicPalette::Dark(p) => p,
57            CosmicPalette::Light(p) => p,
58            CosmicPalette::HighContrastLight(p) => p,
59            CosmicPalette::HighContrastDark(p) => p,
60        }
61    }
62}
63
64impl CosmicPalette {
65    /// check if the palette is dark
66    #[inline]
67    pub fn is_dark(&self) -> bool {
68        match self {
69            CosmicPalette::Dark(_) | CosmicPalette::HighContrastDark(_) => true,
70            CosmicPalette::Light(_) | CosmicPalette::HighContrastLight(_) => false,
71        }
72    }
73
74    /// check if the palette is high_contrast
75    #[inline]
76    pub fn is_high_contrast(&self) -> bool {
77        match self {
78            CosmicPalette::HighContrastLight(_) | CosmicPalette::HighContrastDark(_) => true,
79            CosmicPalette::Light(_) | CosmicPalette::Dark(_) => false,
80        }
81    }
82}
83
84impl Default for CosmicPalette {
85    #[inline]
86    fn default() -> Self {
87        CosmicPalette::Dark(Default::default())
88    }
89}
90
91/// The palette for Cosmic Theme, from which all color properties are derived
92#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
93pub struct CosmicPaletteInner {
94    /// name of the palette
95    pub name: String,
96
97    /// Utility Colors
98    /// Colors used for various points of emphasis in the UI.
99    pub bright_red: Srgba,
100    /// Colors used for various points of emphasis in the UI.
101    pub bright_green: Srgba,
102    /// Colors used for various points of emphasis in the UI.
103    pub bright_orange: Srgba,
104
105    /// Surface Grays
106    /// Colors used for three levels of surfaces in the UI.
107    pub gray_1: Srgba,
108    /// Colors used for three levels of surfaces in the UI.
109    pub gray_2: Srgba,
110
111    /// System Neutrals
112    /// A wider spread of dark colors for more general use.
113    pub neutral_0: Srgba,
114    /// A wider spread of dark colors for more general use.
115    pub neutral_1: Srgba,
116    /// A wider spread of dark colors for more general use.
117    pub neutral_2: Srgba,
118    /// A wider spread of dark colors for more general use.
119    pub neutral_3: Srgba,
120    /// A wider spread of dark colors for more general use.
121    pub neutral_4: Srgba,
122    /// A wider spread of dark colors for more general use.
123    pub neutral_5: Srgba,
124    /// A wider spread of dark colors for more general use.
125    pub neutral_6: Srgba,
126    /// A wider spread of dark colors for more general use.
127    pub neutral_7: Srgba,
128    /// A wider spread of dark colors for more general use.
129    pub neutral_8: Srgba,
130    /// A wider spread of dark colors for more general use.
131    pub neutral_9: Srgba,
132    /// A wider spread of dark colors for more general use.
133    pub neutral_10: Srgba,
134
135    /// Potential Accent Color Combos
136    pub accent_blue: Srgba,
137    /// Potential Accent Color Combos
138    pub accent_indigo: Srgba,
139    /// Potential Accent Color Combos
140    pub accent_purple: Srgba,
141    /// Potential Accent Color Combos
142    pub accent_pink: Srgba,
143    /// Potential Accent Color Combos
144    pub accent_red: Srgba,
145    /// Potential Accent Color Combos
146    pub accent_orange: Srgba,
147    /// Potential Accent Color Combos
148    pub accent_yellow: Srgba,
149    /// Potential Accent Color Combos
150    pub accent_green: Srgba,
151    /// Potential Accent Color Combos
152    pub accent_warm_grey: Srgba,
153
154    /// Extended Color Palette
155    /// Colors used for themes, app icons, illustrations, and other brand purposes.
156    pub ext_warm_grey: Srgba,
157    /// Colors used for themes, app icons, illustrations, and other brand purposes.
158    pub ext_orange: Srgba,
159    /// Colors used for themes, app icons, illustrations, and other brand purposes.
160    pub ext_yellow: Srgba,
161    /// Colors used for themes, app icons, illustrations, and other brand purposes.
162    pub ext_blue: Srgba,
163    /// Colors used for themes, app icons, illustrations, and other brand purposes.
164    pub ext_purple: Srgba,
165    /// Colors used for themes, app icons, illustrations, and other brand purposes.
166    pub ext_pink: Srgba,
167    /// Colors used for themes, app icons, illustrations, and other brand purposes.
168    pub ext_indigo: Srgba,
169}
170
171impl CosmicPalette {
172    /// name of the palette
173    #[inline]
174    pub fn name(&self) -> &str {
175        match &self {
176            CosmicPalette::Dark(p) => &p.name,
177            CosmicPalette::Light(p) => &p.name,
178            CosmicPalette::HighContrastLight(p) => &p.name,
179            CosmicPalette::HighContrastDark(p) => &p.name,
180        }
181    }
182}