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, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
21        let system_color = SystemColor::new();
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().flex().justify_center().w_full().child(
43                    div()
44                        .w_4()
45                        .h_0p5()
46                        .rounded_sm()
47                        .fill(player.cursor_color(cx)),
48                ),
49            )
50            .child(
51                div()
52                    .flex()
53                    .items_center()
54                    .justify_center()
55                    .h_6()
56                    .pl_1()
57                    .rounded_lg()
58                    .fill(if followers.is_none() {
59                        system_color.transparent
60                    } else {
61                        player.selection_color(cx)
62                    })
63                    .child(Avatar::new(player.avatar_src().to_string()))
64                    .children(followers.map(|followers| {
65                        div().neg_ml_2().child(Facepile::new(followers.into_iter()))
66                    })),
67            )
68    }
69}