player_stack.rs

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