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 theme = theme(cx);
18        let player = self.player_with_call_status.get_player();
19        self.player_with_call_status.get_call_status();
20
21        let followers = self
22            .player_with_call_status
23            .get_call_status()
24            .followers
25            .as_ref()
26            .map(|followers| followers.clone());
27
28        // if we have no followers return a slightly different element
29        // if mic_status == muted add a red ring to avatar
30
31        div()
32            .h_full()
33            .flex()
34            .flex_col()
35            .gap_px()
36            .justify_center()
37            .child(
38                div()
39                    .flex()
40                    .justify_center()
41                    .w_full()
42                    .child(div().w_4().h_0p5().rounded_sm().bg(player.cursor_color(cx))),
43            )
44            .child(
45                div()
46                    .flex()
47                    .items_center()
48                    .justify_center()
49                    .h_6()
50                    .pl_1()
51                    .rounded_lg()
52                    .bg(if followers.is_none() {
53                        theme.transparent
54                    } else {
55                        player.selection_color(cx)
56                    })
57                    .child(Avatar::new(player.avatar_src().to_string()))
58                    .children(followers.map(|followers| {
59                        div().neg_ml_2().child(Facepile::new(followers.into_iter()))
60                    })),
61            )
62    }
63}