BlueGit

ict rusty-teams

Files

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

theme.rs

0ff1db96 History
theme.rs 7.1 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
16const 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_TINT: u32 = 0xf5c4a5;
31const ACCENT_STRONG: u32 = 0xa84f27;
32const BUBBLE_OWN: u32 = 0x4f2a1b;
33const BUBBLE_OTHER: u32 = 0x232325;
34const MENTION_BACKGROUND: u32 = 0x3a2a23;
35const MENTION_BACKGROUND_OWN: u32 = 0x3b1d11;
36const OWN_META: u32 = 0xc9a28c;
37const OWN_READ: u32 = 0xf5c4a5;
38const DROP_BACKGROUND: u32 = 0xce6a3b14;
39const SELECTION: u32 = 0xce6a3b66;
40const CODE_BACKGROUND: u32 = 0x0b0b0c;
41const BADGE_MUTED: u32 = 0x3f3f42;
42const TOAST_MENTION: u32 = 0x2e1d15;
43const GREEN: u32 = 0x22c55e;
44const RED: u32 = 0xef4444;
45const CLOSE_BUTTON_HOVER: u32 = 0xc42b1c;
46const CLOSE_BUTTON_PRESSED: u32 = 0xb5271a;
47const CLOSE_BUTTON_ICON: u32 = 0xffffff;
48const RED_SOFT: u32 = 0xf87171;
49const RED_TINT: u32 = 0xfca5a5;
50const AMBER: u32 = 0xfbbf24;
51const AVATAR_PALETTE: [u32; 6] = [0x9a4a22, 0x44606e, 0x8a3434, 0x4f6a3c, 0x6a4f7a, 0x2f6b63];
52
53pub fn color(hex: u32) -> Hsla {
54 rgb(hex).into()
55}
56
57fn color_with_alpha(hex: u32) -> Hsla {
58 rgba(hex).into()
59}
60
61pub fn load_fonts(cx: &mut App) {
62 let fonts = FONT_FILES
63 .iter()
64 .map(|bytes| Cow::Borrowed(*bytes))
65 .collect();
66 let _ = cx.text_system().add_fonts(fonts);
67}
68
69pub fn apply(cx: &mut App) {
70 let installed = cx.text_system().all_font_names();
71 let mono = MONO_FAMILIES
72 .iter()
73 .find(|family| installed.iter().any(|name| name == *family))
74 .map(|family| SharedString::from(*family));
75 Theme::change(ThemeMode::Dark, None, cx);
76 Theme::update(cx, |theme| {
77 theme.font_family = FONT_FAMILY.into();
78 theme.font_size = px(BASE_FONT_SIZE);
79 if let Some(mono) = mono {
80 theme.mono_font_family = mono;
81 }
82 let colors = &mut theme.colors;
83 colors.background = color(BACKGROUND);
84 colors.foreground = color(FOREGROUND);
85 colors.border = color(BORDER);
86 colors.muted = color(BORDER);
87 colors.muted_foreground = color(TEXT_MUTED);
88 colors.sidebar = color(SURFACE);
89 colors.sidebar_foreground = color(FOREGROUND);
90 colors.sidebar_border = color(BORDER);
91 colors.sidebar_accent = color(SURFACE_RAISED);
92 colors.sidebar_accent_foreground = color(FOREGROUND);
93 colors.sidebar_primary = color(ACCENT);
94 colors.popover = color(SURFACE);
95 colors.popover_foreground = color(FOREGROUND);
96 colors.accent = color(SURFACE_RAISED);
97 colors.accent_foreground = color(FOREGROUND);
98 colors.secondary = color(SURFACE_RAISED);
99 colors.secondary_hover = color(BORDER_STRONG);
100 colors.secondary_active = color(BORDER_STRONG);
101 colors.secondary_foreground = color(FOREGROUND);
102 colors.primary = color(ACCENT);
103 colors.primary_hover = color(ACCENT_TEXT);
104 colors.primary_active = color(ACCENT_STRONG);
105 colors.primary_foreground = color(BACKGROUND);
106 colors.link = color(ACCENT_TEXT);
107 colors.link_hover = color(ACCENT_SOFT);
108 colors.link_active = color(ACCENT_STRONG);
109 colors.ring = color(ACCENT);
110 colors.caret = color(ACCENT);
111 colors.input = color(BORDER_STRONG);
112 colors.selection = color_with_alpha(SELECTION);
113 colors.title_bar = color(BACKGROUND);
114 colors.title_bar_border = color(BORDER);
115 colors.status_bar = color(BACKGROUND);
116 colors.status_bar_border = color(BORDER);
117 colors.success = color(GREEN);
118 colors.warning = color(AMBER);
119 colors.danger = color(CLOSE_BUTTON_HOVER);
120 colors.danger_active = color(CLOSE_BUTTON_PRESSED);
121 colors.danger_foreground = color(CLOSE_BUTTON_ICON);
122 colors.drop_target = color_with_alpha(DROP_BACKGROUND);
123 colors.window_border = color(BORDER);
124 colors.scrollbar_thumb = color(BORDER_STRONG);
125 colors.scrollbar_thumb_hover = color(TEXT_FAINT);
126 colors.list = color(BACKGROUND);
127 colors.list_hover = color(ROW_HOVER);
128 colors.list_active = color(SURFACE_RAISED);
129 });
130}
131
132pub fn background() -> Hsla {
133 color(BACKGROUND)
134}
135
136pub fn toast_mention_fill() -> Hsla {
137 color(TOAST_MENTION)
138}
139
140pub fn surface() -> Hsla {
141 color(SURFACE)
142}
143
144pub fn surface_raised() -> Hsla {
145 color(SURFACE_RAISED)
146}
147
148pub fn row_hover() -> Hsla {
149 color(ROW_HOVER)
150}
151
152pub fn border() -> Hsla {
153 color(BORDER)
154}
155
156pub fn border_strong() -> Hsla {
157 color(BORDER_STRONG)
158}
159
160pub fn text() -> Hsla {
161 color(FOREGROUND)
162}
163
164pub fn text_strong() -> Hsla {
165 color(TEXT_STRONG)
166}
167
168pub fn text_soft() -> Hsla {
169 color(TEXT_SOFT)
170}
171
172pub fn text_muted() -> Hsla {
173 color(TEXT_MUTED)
174}
175
176pub fn text_faint() -> Hsla {
177 color(TEXT_FAINT)
178}
179
180pub fn accent() -> Hsla {
181 color(ACCENT)
182}
183
184pub fn accent_text() -> Hsla {
185 color(ACCENT_TEXT)
186}
187
188pub fn accent_soft() -> Hsla {
189 color(ACCENT_SOFT)
190}
191
192pub fn accent_tint() -> Hsla {
193 color(ACCENT_TINT)
194}
195
196pub fn on_accent() -> Hsla {
197 color(BACKGROUND)
198}
199
200pub fn bubble_own() -> Hsla {
201 color(BUBBLE_OWN)
202}
203
204pub fn bubble_other() -> Hsla {
205 color(BUBBLE_OTHER)
206}
207
208pub fn mention_background(own: bool) -> Hsla {
209 color(if own {
210 MENTION_BACKGROUND_OWN
211 } else {
212 MENTION_BACKGROUND
213 })
214}
215
216pub fn own_meta() -> Hsla {
217 color(OWN_META)
218}
219
220pub fn own_read() -> Hsla {
221 color(OWN_READ)
222}
223
224pub fn mention_text() -> Hsla {
225 color(ACCENT_SOFT)
226}
227
228pub fn drop_background() -> Hsla {
229 color_with_alpha(DROP_BACKGROUND)
230}
231
232pub fn code_background() -> Hsla {
233 color(CODE_BACKGROUND)
234}
235
236pub fn badge_muted() -> Hsla {
237 color(BADGE_MUTED)
238}
239
240pub fn green() -> Hsla {
241 color(GREEN)
242}
243
244pub fn red() -> Hsla {
245 color(RED)
246}
247
248pub fn red_soft() -> Hsla {
249 color(RED_SOFT)
250}
251
252pub fn red_tint() -> Hsla {
253 color(RED_TINT)
254}
255
256pub fn amber() -> Hsla {
257 color(AMBER)
258}
259
260pub fn avatar_color(index: usize) -> Hsla {
261 color(AVATAR_PALETTE[index % AVATAR_PALETTE.len()])
262}
263
264pub fn avatar_palette_len() -> usize {
265 AVATAR_PALETTE.len()
266}
267
268#[cfg(test)]
269mod tests {
270 use super::{avatar_color, avatar_palette_len};
271
272 #[test]
273 fn avatar_colors_wrap_around_the_palette() {
274 assert_eq!(avatar_color(0), avatar_color(avatar_palette_len()));
275 assert_ne!(avatar_color(0), avatar_color(1));
276 }
277}