player_stack.rs

 1use gpui::{Div, RenderOnce};
 2
 3use crate::prelude::*;
 4use crate::{Avatar, Facepile, PlayerWithCallStatus};
 5
 6#[derive(RenderOnce)]
 7pub struct PlayerStack {
 8    player_with_call_status: PlayerWithCallStatus,
 9}
10
11impl<V: 'static> Component<V> for PlayerStack {
12    type Rendered = Div<V>;
13
14    fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
15        let player = self.player_with_call_status.get_player();
16
17        let followers = self
18            .player_with_call_status
19            .get_call_status()
20            .followers
21            .as_ref()
22            .map(|followers| followers.clone());
23
24        // if we have no followers return a slightly different element
25        // if mic_status == muted add a red ring to avatar
26
27        div()
28            .h_full()
29            .flex()
30            .flex_col()
31            .gap_px()
32            .justify_center()
33            .child(
34                div()
35                    .flex()
36                    .justify_center()
37                    .w_full()
38                    .child(div().w_4().h_0p5().rounded_sm().bg(player.cursor_color(cx))),
39            )
40            .child(
41                div()
42                    .flex()
43                    .items_center()
44                    .justify_center()
45                    .h_6()
46                    .pl_1()
47                    .rounded_lg()
48                    .bg(if followers.is_none() {
49                        cx.theme().styles.system.transparent
50                    } else {
51                        player.selection_color(cx)
52                    })
53                    .child(Avatar::new(player.avatar_src().to_string()))
54                    .children(followers.map(|followers| {
55                        div().neg_ml_2().child(Facepile::new(followers.into_iter()))
56                    })),
57            )
58    }
59}
60
61impl PlayerStack {
62    pub fn new(player_with_call_status: PlayerWithCallStatus) -> Self {
63        Self {
64            player_with_call_status,
65        }
66    }
67}