Add Facepile
and PlayerStack
components
This commit is contained in:
parent
5e7954f152
commit
f33d41af63
9 changed files with 314 additions and 2 deletions
33
crates/ui2/src/components/facepile.rs
Normal file
33
crates/ui2/src/components/facepile.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{theme, Avatar, Player};
|
||||
|
||||
#[derive(Element)]
|
||||
pub struct Facepile<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
players: Vec<Player>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Facepile<S> {
|
||||
pub fn new<P: Iterator<Item = Player>>(players: P) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
players: players.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
|
||||
let theme = theme(cx);
|
||||
let player_count = self.players.len();
|
||||
let player_list = self.players.iter().enumerate().map(|(ix, player)| {
|
||||
let isnt_last = ix < player_count - 1;
|
||||
|
||||
div()
|
||||
// TODO: Blocked on negative margins.
|
||||
// .when(isnt_last, |div| div.neg_mr_1())
|
||||
.child(Avatar::new(player.avatar_src().to_string()))
|
||||
});
|
||||
div().p_1().flex().items_center().children(player_list)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue