| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::h_flex; |
| 3 | use gpui_kit::*; |
| 4 | |
| 5 | use super::ConversationView; |
| 6 | use crate::theme; |
| 7 | use crate::views::widgets::icon; |
| 8 | |
| 9 | pub const ABSENCE_NOTICE_TAG: &str = "conversation/absence-notice"; |
| 10 | const NOTICE_MARGIN_X: f32 = 20.; |
| 11 | const NOTICE_MARGIN_BOTTOM: f32 = 8.; |
| 12 | const NOTICE_PADDING: f32 = 12.; |
| 13 | const NOTICE_HEIGHT: f32 = 36.; |
| 14 | const NOTICE_RADIUS: f32 = 10.; |
| 15 | const CLOSE_SIZE: f32 = 24.; |
| 16 | const NOTICE_TINT: f32 = 0.18; |
| 17 | |
| 18 | impl ConversationView { |
| 19 | pub(super) fn render_absence_notice(&self, cx: &App) -> Option<AnyElement> { |
| 20 | if self.draft_active { |
| 21 | return None; |
| 22 | } |
| 23 | let conversation_id = self.conversation_id()?; |
| 24 | let notice = self.app.read(cx).absence_notice(&conversation_id)?; |
| 25 | let app = self.app.clone(); |
| 26 | Some( |
| 27 | h_flex() |
| 28 | .flex_none() |
| 29 | .mx(px(NOTICE_MARGIN_X)) |
| 30 | .mb(px(NOTICE_MARGIN_BOTTOM)) |
| 31 | .pl(px(NOTICE_PADDING)) |
| 32 | .pr(px(NOTICE_PADDING - (CLOSE_SIZE - 14.) / 2.)) |
| 33 | .h(px(NOTICE_HEIGHT)) |
| 34 | .gap(px(8.)) |
| 35 | .items_center() |
| 36 | .rounded(px(NOTICE_RADIUS)) |
| 37 | .bg(theme::accent().opacity(NOTICE_TINT)) |
| 38 | .debug_selector(|| ABSENCE_NOTICE_TAG.into()) |
| 39 | .child( |
| 40 | div() |
| 41 | .flex_1() |
| 42 | .min_w_0() |
| 43 | .truncate() |
| 44 | .text_size(px(13.)) |
| 45 | .text_color(theme::text()) |
| 46 | .child(notice.text()), |
| 47 | ) |
| 48 | .child( |
| 49 | div() |
| 50 | .id("absence-notice-close") |
| 51 | .size(px(CLOSE_SIZE)) |
| 52 | .flex_none() |
| 53 | .flex() |
| 54 | .items_center() |
| 55 | .justify_center() |
| 56 | .rounded(px(6.)) |
| 57 | .cursor_pointer() |
| 58 | .hover(|button| button.bg(theme::row_hover())) |
| 59 | .child(icon(IconName::Close, 14., theme::text_muted())) |
| 60 | .on_click(move |_, _, cx| { |
| 61 | app.update(cx, |state, cx| { |
| 62 | state.dismiss_absence_notice(&conversation_id, cx) |
| 63 | }); |
| 64 | }), |
| 65 | ) |
| 66 | .into_any_element(), |
| 67 | ) |
| 68 | } |
| 69 | } |