BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / theme.rs

theme.rs

theme.rs 8.0 KiB Download Raw
1use std::borrow::Cow;
2
3use gpui_kit::component::{Theme, ThemeMode};
4use gpui_kit::*;
5
6const FONT_FAMILY: &str = "Google Sans Flex";
7const MONO_FAMILIES: [&str; 2] = ["Cascadia Code", "Consolas"];
8const BASE_FONT_SIZE: f32 = 14.;
9const FONT_FILES: [&[u8]; 4] = [
10 include_bytes!("../assets/fonts/GoogleSansFlex-Regular.ttf"),
11 include_bytes!("../assets/fonts/GoogleSansFlex-SemiBold.ttf"),
12 include_bytes!("../assets/fonts/GoogleSansFlex-Bold.ttf"),
13 include_bytes!("../assets/fonts/GoogleSansFlex-Italic.ttf"),
14];
15
16pub const BACKGROUND: u32 = 0x0f0f10;
17const SURFACE: u32 = 0x161617;
18const SURFACE_RAISED: u32 = 0x232325;
19const ROW_HOVER: u32 = 0x1c1c1e;
20const BORDER: u32 = 0x262628;
21const BORDER_STRONG: u32 = 0x3f3f42;
22const FOREGROUND: u32 = 0xf4f4f5;
23const TEXT_STRONG: u32 = 0xe4e4e7;
24const TEXT_SOFT: u32 = 0xd4d4d8;
25const TEXT_MUTED: u32 = 0xa1a1a6;
26const TEXT_FAINT: u32 = 0x8e8e93;
27const ACCENT: u32 = 0xce6a3b;
28const ACCENT_TEXT: u32 = 0xe08a5c;
29const ACCENT_SOFT: u32 = 0xf5c4a5;
30const ACCENT_STRONG: u32 = 0xa84f27;
31const BUBBLE_OWN: u32 = 0x4f2a1b;
32const BUBBLE_OTHER: u32 = 0x232325;
33const REACTION_ON_OWN: u32 = 0x6b3a26;
34const WHITE: u32 = 0xffffff;
35const MENTION_BACKGROUND: u32 = 0x3a2a23;
36const MENTION_BACKGROUND_OWN: u32 = 0x3b1d11;
37const OWN_META: u32 = 0xc9a28c;
38const OWN_READ: u32 = 0xf5c4a5;
39const DROP_BACKGROUND: u32 = 0xce6a3b14;
40const SELECTION: u32 = 0xce6a3b66;
41const CODE_SURFACE: u32 = 0x0000003d;
42const CODE_HEADER_BORDER: u32 = 0xffffff0f;
43const INLINE_CODE_FILL: u32 = 0xffffff14;
44const INLINE_CODE_FILL_OWN: u32 = 0x0000003d;
45const QUOTE_FILL: u32 = 0x00000052;
46const INLINE_CODE_BORDER: u32 = 0xffffff1a;
47const TABLE_HEADER: u32 = 0xffffff0d;
48const RULE_OWN: u32 = 0x6a3a25;
49const BADGE_MUTED: u32 = 0x3f3f42;
50const TOAST_MENTION: u32 = 0x2e1d15;
51const GREEN: u32 = 0x22c55e;
52const RED: u32 = 0xef4444;
53const CLOSE_BUTTON_HOVER: u32 = 0xc42b1c;
54const CLOSE_BUTTON_PRESSED: u32 = 0xb5271a;
55const CLOSE_BUTTON_ICON: u32 = 0xffffff;
56const RED_SOFT: u32 = 0xf87171;
57const RED_TINT: u32 = 0xfca5a5;
58const AMBER: u32 = 0xfbbf24;
59const AVATAR_PALETTE: [u32; 6] = [0x9a4a22, 0x44606e, 0x8a3434, 0x4f6a3c, 0x6a4f7a, 0x2f6b63];
60
61pub fn color(hex: u32) -> Hsla {
62 rgb(hex).into()
63}
64
65fn color_with_alpha(hex: u32) -> Hsla {
66 rgba(hex).into()
67}
68
69pub fn load_fonts(cx: &mut App) {
70 let fonts = FONT_FILES
71 .iter()
72 .map(|bytes| Cow::Borrowed(*bytes))
73 .collect();
74 let _ = cx.text_system().add_fonts(fonts);
75}
76
77pub fn apply(cx: &mut App) {
78 let installed = cx.text_system().all_font_names();
79 let mono = MONO_FAMILIES
80 .iter()
81 .find(|family| installed.iter().any(|name| name == *family))
82 .map(|family| SharedString::from(*family));
83 Theme::change(ThemeMode::Dark, None, cx);
84 Theme::update(cx, |theme| {
85 theme.font_family = FONT_FAMILY.into();
86 theme.font_size = px(BASE_FONT_SIZE);
87 if let Some(mono) = mono {
88 theme.mono_font_family = mono;
89 }
90 let colors = &mut theme.colors;
91 colors.background = color(BACKGROUND);
92 colors.foreground = color(FOREGROUND);
93 colors.border = color(BORDER);
94 colors.muted = color(BORDER);
95 colors.muted_foreground = color(TEXT_MUTED);
96 colors.sidebar = color(SURFACE);
97 colors.sidebar_foreground = color(FOREGROUND);
98 colors.sidebar_border = color(BORDER);
99 colors.sidebar_accent = color(SURFACE_RAISED);
100 colors.sidebar_accent_foreground = color(FOREGROUND);
101 colors.sidebar_primary = color(ACCENT);
102 colors.popover = color(SURFACE);
103 colors.popover_foreground = color(FOREGROUND);
104 colors.accent = color(SURFACE_RAISED);
105 colors.accent_foreground = color(FOREGROUND);
106 colors.secondary = color(SURFACE_RAISED);
107 colors.secondary_hover = color(BORDER_STRONG);
108 colors.secondary_active = color(BORDER_STRONG);
109 colors.secondary_foreground = color(FOREGROUND);
110 colors.primary = color(ACCENT);
111 colors.primary_hover = color(ACCENT_TEXT);
112 colors.primary_active = color(ACCENT_STRONG);
113 colors.primary_foreground = color(BACKGROUND);
114 colors.link = color(ACCENT_TEXT);
115 colors.link_hover = color(ACCENT_SOFT);
116 colors.link_active = color(ACCENT_STRONG);
117 colors.ring = color(ACCENT);
118 colors.caret = color(ACCENT);
119 colors.input = color(BORDER_STRONG);
120 colors.selection = color_with_alpha(SELECTION);
121 colors.title_bar = color(BACKGROUND);
122 colors.title_bar_border = color(BORDER);
123 colors.status_bar = color(BACKGROUND);
124 colors.status_bar_border = color(BORDER);
125 colors.success = color(GREEN);
126 colors.warning = color(AMBER);
127 colors.danger = color(CLOSE_BUTTON_HOVER);
128 colors.danger_active = color(CLOSE_BUTTON_PRESSED);
129 colors.danger_foreground = color(CLOSE_BUTTON_ICON);
130 colors.drop_target = color_with_alpha(DROP_BACKGROUND);
131 colors.window_border = color(BORDER);
132 colors.scrollbar_thumb = color(BORDER_STRONG);
133 colors.scrollbar_thumb_hover = color(TEXT_FAINT);
134 colors.list = color(BACKGROUND);
135 colors.list_hover = color(ROW_HOVER);
136 colors.list_active = color(SURFACE_RAISED);
137 });
138}
139
140pub fn font_family() -> SharedString {
141 FONT_FAMILY.into()
142}
143
144pub fn background() -> Hsla {
145 color(BACKGROUND)
146}
147
148pub fn toast_mention_fill() -> Hsla {
149 color(TOAST_MENTION)
150}
151
152pub fn surface() -> Hsla {
153 color(SURFACE)
154}
155
156pub fn surface_raised() -> Hsla {
157 color(SURFACE_RAISED)
158}
159
160pub fn row_hover() -> Hsla {
161 color(ROW_HOVER)
162}
163
164pub fn border() -> Hsla {
165 color(BORDER)
166}
167
168pub fn border_strong() -> Hsla {
169 color(BORDER_STRONG)
170}
171
172pub fn text() -> Hsla {
173 color(FOREGROUND)
174}
175
176pub fn text_strong() -> Hsla {
177 color(TEXT_STRONG)
178}
179
180pub fn text_soft() -> Hsla {
181 color(TEXT_SOFT)
182}
183
184pub fn text_muted() -> Hsla {
185 color(TEXT_MUTED)
186}
187
188pub fn text_faint() -> Hsla {
189 color(TEXT_FAINT)
190}
191
192pub fn accent() -> Hsla {
193 color(ACCENT)
194}
195
196pub fn accent_text() -> Hsla {
197 color(ACCENT_TEXT)
198}
199
200pub fn accent_soft() -> Hsla {
201 color(ACCENT_SOFT)
202}
203
204pub fn on_accent() -> Hsla {
205 color(BACKGROUND)
206}
207
208pub fn bubble_own() -> Hsla {
209 color(BUBBLE_OWN)
210}
211
212pub fn bubble_other() -> Hsla {
213 color(BUBBLE_OTHER)
214}
215
216pub fn reaction_on_own() -> Hsla {
217 color(REACTION_ON_OWN)
218}
219
220pub fn white() -> Hsla {
221 color(WHITE)
222}
223
224pub fn mention_background(own: bool) -> Hsla {
225 color(if own {
226 MENTION_BACKGROUND_OWN
227 } else {
228 MENTION_BACKGROUND
229 })
230}
231
232pub fn own_meta() -> Hsla {
233 color(OWN_META)
234}
235
236pub fn own_read() -> Hsla {
237 color(OWN_READ)
238}
239
240pub fn mention_text() -> Hsla {
241 color(ACCENT_SOFT)
242}
243
244pub fn drop_background() -> Hsla {
245 color_with_alpha(DROP_BACKGROUND)
246}
247
248pub fn code_surface() -> Hsla {
249 color_with_alpha(CODE_SURFACE)
250}
251
252pub fn code_header_border() -> Hsla {
253 color_with_alpha(CODE_HEADER_BORDER)
254}
255
256pub fn inline_code_fill(own: bool) -> Hsla {
257 color_with_alpha(if own {
258 INLINE_CODE_FILL_OWN
259 } else {
260 INLINE_CODE_FILL
261 })
262}
263
264pub fn quote_fill() -> Hsla {
265 color_with_alpha(QUOTE_FILL)
266}
267
268pub fn inline_code_border() -> Hsla {
269 color_with_alpha(INLINE_CODE_BORDER)
270}
271
272pub fn table_header() -> Hsla {
273 color_with_alpha(TABLE_HEADER)
274}
275
276pub fn rule(own: bool) -> Hsla {
277 if own {
278 color(RULE_OWN)
279 } else {
280 border_strong()
281 }
282}
283
284pub fn badge_muted() -> Hsla {
285 color(BADGE_MUTED)
286}
287
288pub fn green() -> Hsla {
289 color(GREEN)
290}
291
292pub fn red() -> Hsla {
293 color(RED)
294}
295
296pub fn red_soft() -> Hsla {
297 color(RED_SOFT)
298}
299
300pub fn red_tint() -> Hsla {
301 color(RED_TINT)
302}
303
304pub fn amber() -> Hsla {
305 color(AMBER)
306}
307
308pub fn avatar_color(index: usize) -> Hsla {
309 color(AVATAR_PALETTE[index % AVATAR_PALETTE.len()])
310}
311
312pub fn avatar_palette_len() -> usize {
313 AVATAR_PALETTE.len()
314}
315
316#[cfg(test)]
317mod tests {
318 use super::{avatar_color, avatar_palette_len};
319
320 #[test]
321 fn avatar_colors_wrap_around_the_palette() {
322 assert_eq!(avatar_color(0), avatar_color(avatar_palette_len()));
323 assert_ne!(avatar_color(0), avatar_color(1));
324 }
325}