BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / widgets.rs

widgets.rs

Initial commit
metis Daniel Däschle · pushed by metis · 7 weeks ago
06e0ae51 History
widgets.rs 1.8 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::Icon;
3use gpui_kit::*;
4
5use crate::format;
6use crate::sidebar_model::Unread;
7use crate::theme;
8
9pub fn icon(name: IconName, size: f32, color: Hsla) -> Icon {
10 Icon::new(name).size(px(size)).text_color(color)
11}
12
13pub fn symbol(name: &str, size: f32, color: Hsla) -> Icon {
14 Icon::empty()
15 .path(format!("symbols/{name}.svg"))
16 .size(px(size))
17 .text_color(color)
18}
19
20pub fn count_badge(count: u32, muted: bool) -> Div {
21 let (background, foreground) = if muted {
22 (theme::badge_muted(), theme::text_strong())
23 } else {
24 (theme::accent(), theme::on_accent())
25 };
26 div()
27 .min_w(px(18.))
28 .h(px(18.))
29 .px(px(5.))
30 .flex()
31 .flex_none()
32 .items_center()
33 .justify_center()
34 .rounded(px(9.))
35 .bg(background)
36 .text_color(foreground)
37 .text_size(px(11.))
38 .line_height(px(18.))
39 .font_weight(FontWeight::BOLD)
40 .child(format::badge_text(count))
41}
42
43pub fn dot(size: f32) -> Div {
44 div()
45 .size(px(size))
46 .flex_none()
47 .rounded_full()
48 .bg(theme::accent())
49}
50
51pub fn unread_marker(unread: Unread) -> Option<Div> {
52 match unread {
53 Unread::None => None,
54 Unread::Dot => Some(dot(8.)),
55 Unread::Count(count) => Some(count_badge(count, false)),
56 }
57}
58
59const SMILE_SVG: &[u8] = br#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M8.5 14.5a4.5 4.5 0 0 0 7 0M9 9.5h.01M15 9.5h.01"/></svg>"#;
60
61#[allow(dead_code)]
62pub fn smile_icon(size: f32, color: Hsla) -> Icon {
63 Icon::default()
64 .data(SMILE_SVG)
65 .size(px(size))
66 .text_color(color)
67}