BlueGit

ict rusty-teams

Files

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

theme.rs

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