1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
use lazy_static::lazy_static;
use palette::Srgba;
use serde::{Deserialize, Serialize};

lazy_static! {
    /// built in light palette
    pub static ref LIGHT_PALETTE: CosmicPalette =
        ron::from_str(include_str!("light.ron")).unwrap();
    /// built in dark palette
    pub static ref DARK_PALETTE: CosmicPalette =
        ron::from_str(include_str!("dark.ron")).unwrap();
}

/// Palette type
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub enum CosmicPalette {
    /// Dark mode
    Dark(CosmicPaletteInner),
    /// Light mode
    Light(CosmicPaletteInner),
    /// High contrast light mode
    HighContrastLight(CosmicPaletteInner),
    /// High contrast dark mode
    HighContrastDark(CosmicPaletteInner),
}

impl CosmicPalette {
    /// extract the inner palette
    pub fn inner(self) -> CosmicPaletteInner {
        match self {
            CosmicPalette::Dark(p) => p,
            CosmicPalette::Light(p) => p,
            CosmicPalette::HighContrastLight(p) => p,
            CosmicPalette::HighContrastDark(p) => p,
        }
    }
}

impl AsMut<CosmicPaletteInner> for CosmicPalette {
    fn as_mut(&mut self) -> &mut CosmicPaletteInner {
        match self {
            CosmicPalette::Dark(p) => p,
            CosmicPalette::Light(p) => p,
            CosmicPalette::HighContrastLight(p) => p,
            CosmicPalette::HighContrastDark(p) => p,
        }
    }
}

impl AsRef<CosmicPaletteInner> for CosmicPalette {
    fn as_ref(&self) -> &CosmicPaletteInner {
        match self {
            CosmicPalette::Dark(p) => p,
            CosmicPalette::Light(p) => p,
            CosmicPalette::HighContrastLight(p) => p,
            CosmicPalette::HighContrastDark(p) => p,
        }
    }
}

impl CosmicPalette {
    /// check if the palette is dark
    pub fn is_dark(&self) -> bool {
        match self {
            CosmicPalette::Dark(_) | CosmicPalette::HighContrastDark(_) => true,
            CosmicPalette::Light(_) | CosmicPalette::HighContrastLight(_) => false,
        }
    }

    /// check if the palette is high_contrast
    pub fn is_high_contrast(&self) -> bool {
        match self {
            CosmicPalette::HighContrastLight(_) | CosmicPalette::HighContrastDark(_) => true,
            CosmicPalette::Light(_) | CosmicPalette::Dark(_) => false,
        }
    }
}

impl Default for CosmicPalette {
    fn default() -> Self {
        CosmicPalette::Dark(Default::default())
    }
}

/// The palette for Cosmic Theme, from which all color properties are derived
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
pub struct CosmicPaletteInner {
    /// name of the palette
    pub name: String,

    /// basic palette
    /// blue: colors used for various points of emphasis in the UI
    pub blue: Srgba,
    /// red: colors used for various points of emphasis in the UI
    pub red: Srgba,
    /// green: colors used for various points of emphasis in the UI
    pub green: Srgba,
    /// yellow: colors used for various points of emphasis in the UI
    pub yellow: Srgba,

    /// surface grays
    /// colors used for three levels of surfaces in the UI
    pub gray_1: Srgba,
    /// colors used for three levels of surfaces in the UI
    pub gray_2: Srgba,
    /// colors used for three levels of surfaces in the UI
    pub gray_3: Srgba,

    /// System Neutrals
    /// A wider spread of dark colors for more general use.
    pub neutral_0: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_1: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_2: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_3: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_4: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_5: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_6: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_7: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_8: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_9: Srgba,
    /// A wider spread of dark colors for more general use.
    pub neutral_10: Srgba,

    // Utility Colors
    /// Utility bright green
    pub bright_green: Srgba,
    /// Utility bright red
    pub bright_red: Srgba,
    /// Utility bright orange
    pub bright_orange: Srgba,

    /// Extended Color Palette
    /// Colors used for themes, app icons, illustrations, and other brand purposes.
    pub ext_warm_grey: Srgba,
    /// Colors used for themes, app icons, illustrations, and other brand purposes.
    pub ext_orange: Srgba,
    /// Colors used for themes, app icons, illustrations, and other brand purposes.
    pub ext_yellow: Srgba,
    /// Colors used for themes, app icons, illustrations, and other brand purposes.
    pub ext_blue: Srgba,
    /// Colors used for themes, app icons, illustrations, and other brand purposes.
    pub ext_purple: Srgba,
    /// Colors used for themes, app icons, illustrations, and other brand purposes.
    pub ext_pink: Srgba,
    /// Colors used for themes, app icons, illustrations, and other brand purposes.
    pub ext_indigo: Srgba,

    /// Potential Accent Color Combos
    pub accent_blue: Srgba,
    /// Potential Accent Color Combos
    pub accent_red: Srgba,
    /// Potential Accent Color Combos
    pub accent_green: Srgba,
    /// Potential Accent Color Combos
    pub accent_warm_grey: Srgba,
    /// Potential Accent Color Combos
    pub accent_orange: Srgba,
    /// Potential Accent Color Combos
    pub accent_yellow: Srgba,
    /// Potential Accent Color Combos
    pub accent_purple: Srgba,
    /// Potential Accent Color Combos
    pub accent_pink: Srgba,
    /// Potential Accent Color Combos
    pub accent_indigo: Srgba,
}

impl CosmicPalette {
    /// name of the palette
    pub fn name(&self) -> &str {
        match &self {
            CosmicPalette::Dark(p) => &p.name,
            CosmicPalette::Light(p) => &p.name,
            CosmicPalette::HighContrastLight(p) => &p.name,
            CosmicPalette::HighContrastDark(p) => &p.name,
        }
    }
}