follow_group.rs

 1use gpui2::elements::div;
 2use gpui2::style::StyleHelpers;
 3use gpui2::{Element, IntoElement, ParentElement, ViewContext};
 4
 5use crate::{facepile, indicator, theme, Avatar};
 6
 7#[derive(Element)]
 8pub struct FollowGroup {
 9    player: usize,
10    players: Vec<Avatar>,
11}
12
13pub fn follow_group(players: Vec<Avatar>) -> FollowGroup {
14    FollowGroup { player: 0, players }
15}
16
17impl FollowGroup {
18    pub fn player(mut self, player: usize) -> Self {
19        self.player = player;
20        self
21    }
22
23    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
24        let theme = theme(cx);
25        let player_bg = theme.players[self.player].selection;
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(indicator().player(self.player)),
39            )
40            .child(
41                div()
42                    .flex()
43                    .items_center()
44                    .justify_center()
45                    .h_6()
46                    .px_1()
47                    .rounded_lg()
48                    .fill(player_bg)
49                    .child(facepile(self.players.clone().into_iter())),
50            )
51    }
52}