| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::Icon; |
| 3 | use gpui_kit::*; |
| 4 | |
| 5 | use app_base::format; |
| 6 | use app_base::theme; |
| 7 | |
| 8 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 9 | pub enum Unread { |
| 10 | None, |
| 11 | Silent, |
| 12 | Dot, |
| 13 | Count(u32), |
| 14 | } |
| 15 | |
| 16 | impl Unread { |
| 17 | pub fn is_unread(self) -> bool { |
| 18 | self != Unread::None |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | pub fn icon(name: IconName, size: f32, color: Hsla) -> Icon { |
| 23 | Icon::new(name).size(px(size)).text_color(color) |
| 24 | } |
| 25 | |
| 26 | pub fn symbol(name: &str, size: f32, color: Hsla) -> Icon { |
| 27 | Icon::empty() |
| 28 | .path(format!("symbols/{name}.svg")) |
| 29 | .size(px(size)) |
| 30 | .text_color(color) |
| 31 | } |
| 32 | |
| 33 | #[derive(Clone, Copy)] |
| 34 | pub enum Corner { |
| 35 | TopRight, |
| 36 | BottomRight, |
| 37 | } |
| 38 | |
| 39 | pub fn corner_badge(corner: Corner, overhang: f32) -> Div { |
| 40 | let badge = div().absolute().right(px(-overhang)); |
| 41 | match corner { |
| 42 | Corner::TopRight => badge.top(px(-overhang)), |
| 43 | Corner::BottomRight => badge.bottom(px(-overhang)), |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | pub fn count_badge(count: u32, muted: bool) -> Div { |
| 48 | let (background, foreground) = if muted { |
| 49 | (theme::badge_muted(), theme::text_strong()) |
| 50 | } else { |
| 51 | (theme::accent(), theme::on_accent()) |
| 52 | }; |
| 53 | div() |
| 54 | .min_w(px(18.)) |
| 55 | .h(px(18.)) |
| 56 | .px(px(5.)) |
| 57 | .flex() |
| 58 | .flex_none() |
| 59 | .items_center() |
| 60 | .justify_center() |
| 61 | .rounded(px(9.)) |
| 62 | .bg(background) |
| 63 | .text_color(foreground) |
| 64 | .text_size(px(11.)) |
| 65 | .line_height(px(18.)) |
| 66 | .font_weight(FontWeight::BOLD) |
| 67 | .child(format::badge_text(count)) |
| 68 | } |
| 69 | |
| 70 | pub fn page_header(title: &str) -> Div { |
| 71 | div() |
| 72 | .h(px(52.)) |
| 73 | .flex() |
| 74 | .flex_none() |
| 75 | .items_center() |
| 76 | .gap(px(6.)) |
| 77 | .pl(px(16.)) |
| 78 | .pr(px(12.)) |
| 79 | .child( |
| 80 | div() |
| 81 | .flex_1() |
| 82 | .text_size(px(16.)) |
| 83 | .font_weight(FontWeight::BOLD) |
| 84 | .child(title.to_owned()), |
| 85 | ) |
| 86 | } |
| 87 | |
| 88 | pub fn dot(size: f32) -> Div { |
| 89 | div() |
| 90 | .size(px(size)) |
| 91 | .flex_none() |
| 92 | .rounded_full() |
| 93 | .bg(theme::accent()) |
| 94 | } |
| 95 | |
| 96 | pub fn unread_marker(unread: Unread, muted: bool) -> Option<Div> { |
| 97 | match unread { |
| 98 | Unread::None | Unread::Silent => None, |
| 99 | Unread::Dot if muted => Some(dot(8.).bg(theme::badge_muted())), |
| 100 | Unread::Dot => Some(dot(8.)), |
| 101 | Unread::Count(count) => Some(count_badge(count, muted)), |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | const 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>"#; |
| 106 | |
| 107 | #[allow(dead_code)] |
| 108 | pub fn smile_icon(size: f32, color: Hsla) -> Icon { |
| 109 | Icon::default() |
| 110 | .data(SMILE_SVG) |
| 111 | .size(px(size)) |
| 112 | .text_color(color) |
| 113 | } |