player_stack.rs

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