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