BlueGit

ict rusty-teams

Files

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

widgets.rs

widgets.rs 2.6 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
20#[derive(Clone, Copy)]
21pub enum Corner {
22 TopRight,
23 BottomRight,
24}
25
26pub fn corner_badge(corner: Corner, overhang: f32) -> Div {
27 let badge = div().absolute().right(px(-overhang));
28 match corner {
29 Corner::TopRight => badge.top(px(-overhang)),
30 Corner::BottomRight => badge.bottom(px(-overhang)),
31 }
32}
33
34pub fn count_badge(count: u32, muted: bool) -> Div {
35 let (background, foreground) = if muted {
36 (theme::badge_muted(), theme::text_strong())
37 } else {
38 (theme::accent(), theme::on_accent())
39 };
40 div()
41 .min_w(px(18.))
42 .h(px(18.))
43 .px(px(5.))
44 .flex()
45 .flex_none()
46 .items_center()
47 .justify_center()
48 .rounded(px(9.))
49 .bg(background)
50 .text_color(foreground)
51 .text_size(px(11.))
52 .line_height(px(18.))
53 .font_weight(FontWeight::BOLD)
54 .child(format::badge_text(count))
55}
56
57pub fn page_header(title: &str) -> Div {
58 div()
59 .h(px(52.))
60 .flex()
61 .flex_none()
62 .items_center()
63 .gap(px(6.))
64 .pl(px(16.))
65 .pr(px(12.))
66 .child(
67 div()
68 .flex_1()
69 .text_size(px(16.))
70 .font_weight(FontWeight::BOLD)
71 .child(title.to_owned()),
72 )
73}
74
75pub fn dot(size: f32) -> Div {
76 div()
77 .size(px(size))
78 .flex_none()
79 .rounded_full()
80 .bg(theme::accent())
81}
82
83pub fn unread_marker(unread: Unread, muted: bool) -> Option<Div> {
84 match unread {
85 Unread::None | Unread::Silent => None,
86 Unread::Dot if muted => Some(dot(8.).bg(theme::badge_muted())),
87 Unread::Dot => Some(dot(8.)),
88 Unread::Count(count) => Some(count_badge(count, muted)),
89 }
90}
91
92const 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>"#;
93
94#[allow(dead_code)]
95pub fn smile_icon(size: f32, color: Hsla) -> Icon {
96 Icon::default()
97 .data(SMILE_SVG)
98 .size(px(size))
99 .text_color(color)
100}