1use crate::prelude::*;
2use crate::{Avatar, Player};
3
4#[derive(Component)]
5pub struct Facepile {
6 players: Vec<Player>,
7}
8
9impl Facepile {
10 pub fn new<P: Iterator<Item = Player>>(players: P) -> Self {
11 Self {
12 players: players.collect(),
13 }
14 }
15
16 fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
17 let player_count = self.players.len();
18 let player_list = self.players.iter().enumerate().map(|(ix, player)| {
19 let isnt_last = ix < player_count - 1;
20
21 div()
22 .when(isnt_last, |div| div.neg_mr_1())
23 .child(Avatar::new(player.avatar_src().to_string()))
24 });
25 div().p_1().flex().items_center().children(player_list)
26 }
27}
28
29#[cfg(feature = "stories")]
30pub use stories::*;
31
32#[cfg(feature = "stories")]
33mod stories {
34 use super::*;
35 use crate::{static_players, Story};
36 use gpui::{Div, Render};
37
38 pub struct FacepileStory;
39
40 impl Render for FacepileStory {
41 type Element = Div<Self>;
42
43 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
44 let players = static_players();
45
46 Story::container(cx)
47 .child(Story::title_for::<_, Facepile>(cx))
48 .child(Story::label(cx, "Default"))
49 .child(
50 div()
51 .flex()
52 .gap_3()
53 .child(Facepile::new(players.clone().into_iter().take(1)))
54 .child(Facepile::new(players.clone().into_iter().take(2)))
55 .child(Facepile::new(players.clone().into_iter().take(3))),
56 )
57 }
58 }
59}