BlueGit

ict rusty-teams

Files

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

theme.rs

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