BlueGit

ict rusty-teams

Files

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

theme.rs

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