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 crate::{static_players, Story};
35
36 use super::*;
37
38 #[derive(Component)]
39 pub struct FacepileStory;
40
41 impl FacepileStory {
42 pub fn new() -> Self {
43 Self
44 }
45
46 fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
47 let players = static_players();
48
49 Story::container(cx)
50 .child(Story::title_for::<_, Facepile>(cx))
51 .child(Story::label(cx, "Default"))
52 .child(
53 div()
54 .flex()
55 .gap_3()
56 .child(Facepile::new(players.clone().into_iter().take(1)))
57 .child(Facepile::new(players.clone().into_iter().take(2)))
58 .child(Facepile::new(players.clone().into_iter().take(3))),
59 )
60 }
61 }
62}