collab_notification.rs

 1use gpui::{img, prelude::*, AnyElement, SharedUrl};
 2use smallvec::SmallVec;
 3use ui::prelude::*;
 4
 5#[derive(IntoElement)]
 6pub struct CollabNotification {
 7    avatar_uri: SharedUrl,
 8    accept_button: Button,
 9    dismiss_button: Button,
10    children: SmallVec<[AnyElement; 2]>,
11}
12
13impl CollabNotification {
14    pub fn new(
15        avatar_uri: impl Into<SharedUrl>,
16        accept_button: Button,
17        dismiss_button: Button,
18    ) -> Self {
19        Self {
20            avatar_uri: avatar_uri.into(),
21            accept_button,
22            dismiss_button,
23            children: SmallVec::new(),
24        }
25    }
26}
27
28impl ParentElement for CollabNotification {
29    fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
30        &mut self.children
31    }
32}
33
34impl RenderOnce for CollabNotification {
35    fn render(self, cx: &mut WindowContext) -> impl IntoElement {
36        h_stack()
37            .text_ui()
38            .justify_between()
39            .size_full()
40            .overflow_hidden()
41            .elevation_3(cx)
42            .p_2()
43            .gap_2()
44            .child(img(self.avatar_uri).w_12().h_12().rounded_full())
45            .child(v_stack().overflow_hidden().children(self.children))
46            .child(
47                v_stack()
48                    .child(self.accept_button)
49                    .child(self.dismiss_button),
50            )
51    }
52}