1use gpui2::{AppContext, Hsla, SharedString};
2
3use crate::{ActiveTheme, Appearance};
4
5pub type ColorScale = [Hsla; 12];
6
7pub struct ColorScales {
8 pub gray: ColorScaleSet,
9 pub mauve: ColorScaleSet,
10 pub slate: ColorScaleSet,
11 pub sage: ColorScaleSet,
12 pub olive: ColorScaleSet,
13 pub sand: ColorScaleSet,
14 pub gold: ColorScaleSet,
15 pub bronze: ColorScaleSet,
16 pub brown: ColorScaleSet,
17 pub yellow: ColorScaleSet,
18 pub amber: ColorScaleSet,
19 pub orange: ColorScaleSet,
20 pub tomato: ColorScaleSet,
21 pub red: ColorScaleSet,
22 pub ruby: ColorScaleSet,
23 pub crimson: ColorScaleSet,
24 pub pink: ColorScaleSet,
25 pub plum: ColorScaleSet,
26 pub purple: ColorScaleSet,
27 pub violet: ColorScaleSet,
28 pub iris: ColorScaleSet,
29 pub indigo: ColorScaleSet,
30 pub blue: ColorScaleSet,
31 pub cyan: ColorScaleSet,
32 pub teal: ColorScaleSet,
33 pub jade: ColorScaleSet,
34 pub green: ColorScaleSet,
35 pub grass: ColorScaleSet,
36 pub lime: ColorScaleSet,
37 pub mint: ColorScaleSet,
38 pub sky: ColorScaleSet,
39 pub black: ColorScaleSet,
40 pub white: ColorScaleSet,
41}
42
43impl IntoIterator for ColorScales {
44 type Item = ColorScaleSet;
45
46 type IntoIter = std::vec::IntoIter<Self::Item>;
47
48 fn into_iter(self) -> Self::IntoIter {
49 vec![
50 self.gray,
51 self.mauve,
52 self.slate,
53 self.sage,
54 self.olive,
55 self.sand,
56 self.gold,
57 self.bronze,
58 self.brown,
59 self.yellow,
60 self.amber,
61 self.orange,
62 self.tomato,
63 self.red,
64 self.ruby,
65 self.crimson,
66 self.pink,
67 self.plum,
68 self.purple,
69 self.violet,
70 self.iris,
71 self.indigo,
72 self.blue,
73 self.cyan,
74 self.teal,
75 self.jade,
76 self.green,
77 self.grass,
78 self.lime,
79 self.mint,
80 self.sky,
81 self.black,
82 self.white,
83 ]
84 .into_iter()
85 }
86}
87
88/// A one-based step in a [`ColorScale`].
89pub type ColorScaleStep = usize;
90
91pub struct ColorScaleSet {
92 name: SharedString,
93 light: ColorScale,
94 dark: ColorScale,
95 light_alpha: ColorScale,
96 dark_alpha: ColorScale,
97}
98
99impl ColorScaleSet {
100 pub fn new(
101 name: impl Into<SharedString>,
102 light: ColorScale,
103 light_alpha: ColorScale,
104 dark: ColorScale,
105 dark_alpha: ColorScale,
106 ) -> Self {
107 Self {
108 name: name.into(),
109 light,
110 light_alpha,
111 dark,
112 dark_alpha,
113 }
114 }
115
116 pub fn name(&self) -> &SharedString {
117 &self.name
118 }
119
120 pub fn light(&self, step: ColorScaleStep) -> Hsla {
121 self.light[step - 1]
122 }
123
124 pub fn light_alpha(&self, step: ColorScaleStep) -> Hsla {
125 self.light_alpha[step - 1]
126 }
127
128 pub fn dark(&self, step: ColorScaleStep) -> Hsla {
129 self.dark[step - 1]
130 }
131
132 pub fn dark_alpha(&self, step: ColorScaleStep) -> Hsla {
133 self.dark_alpha[step - 1]
134 }
135
136 pub fn step(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
137 match cx.theme().appearance {
138 Appearance::Light => self.light(step),
139 Appearance::Dark => self.dark(step),
140 }
141 }
142
143 pub fn step_alpha(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
144 match cx.theme().appearance {
145 Appearance::Light => self.light_alpha(step),
146 Appearance::Dark => self.dark_alpha(step),
147 }
148 }
149}