| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::Icon; |
| 3 | use gpui_kit::*; |
| 4 | |
| 5 | use crate::format; |
| 6 | use crate::sidebar_model::Unread; |
| 7 | use crate::theme; |
| 8 | |
| 9 | pub fn icon(name: IconName, size: f32, color: Hsla) -> Icon { |
| 10 | Icon::new(name).size(px(size)).text_color(color) |
| 11 | } |
| 12 | |
| 13 | pub 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 | pub 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 | |
| 43 | pub fn dot(size: f32) -> Div { |
| 44 | div() |
| 45 | .size(px(size)) |
| 46 | .flex_none() |
| 47 | .rounded_full() |
| 48 | .bg(theme::accent()) |
| 49 | } |
| 50 | |
| 51 | pub fn unread_marker(unread: Unread, muted: bool) -> Option<Div> { |
| 52 | match unread { |
| 53 | Unread::None => None, |
| 54 | Unread::Dot if muted => Some(dot(8.).bg(theme::badge_muted())), |
| 55 | Unread::Dot => Some(dot(8.)), |
| 56 | Unread::Count(count) => Some(count_badge(count, muted)), |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | 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>"#; |
| 61 | |
| 62 | #[allow(dead_code)] |
| 63 | pub fn smile_icon(size: f32, color: Hsla) -> Icon { |
| 64 | Icon::default() |
| 65 | .data(SMILE_SVG) |
| 66 | .size(px(size)) |
| 67 | .text_color(color) |
| 68 | } |