face_pile.rs

 1use gpui::AnyElement;
 2use smallvec::SmallVec;
 3use ui::prelude::*;
 4
 5#[derive(IntoElement)]
 6pub struct FacePile {
 7    base: Div,
 8    faces: SmallVec<[AnyElement; 2]>,
 9}
10
11impl FacePile {
12    pub fn empty() -> Self {
13        Self::new(SmallVec::new())
14    }
15
16    pub fn new(faces: SmallVec<[AnyElement; 2]>) -> Self {
17        Self {
18            base: h_flex(),
19            faces,
20        }
21    }
22}
23
24impl RenderOnce for FacePile {
25    fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
26        let player_count = self.faces.len();
27        let player_list = self.faces.into_iter().enumerate().map(|(ix, player)| {
28            let isnt_last = ix < player_count - 1;
29
30            div()
31                .z_index((player_count - ix) as u16)
32                .when(isnt_last, |div| div.neg_mr_1())
33                .child(player)
34        });
35        self.base.children(player_list)
36    }
37}
38
39impl ParentElement for FacePile {
40    fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
41        self.faces.extend(elements);
42    }
43}
44
45impl Styled for FacePile {
46    fn style(&mut self) -> &mut gpui::StyleRefinement {
47        self.base.style()
48    }
49}