Make FacePile
a component again (#4143)
This PR turns `FacePile` back into a component. Our usage of it seemed a little weird, with us calling `render` manually. We're now implementing `Styled` on `FacePile` through its inner `Div` so that we can apply the `p_1` at the call site. Release Notes: - N/A
This commit is contained in:
parent
bac2e59eac
commit
e278410fbc
3 changed files with 33 additions and 14 deletions
|
@ -2214,15 +2214,15 @@ impl CollabPanel {
|
||||||
|
|
||||||
let face_pile = if !participants.is_empty() {
|
let face_pile = if !participants.is_empty() {
|
||||||
let extra_count = participants.len().saturating_sub(FACEPILE_LIMIT);
|
let extra_count = participants.len().saturating_sub(FACEPILE_LIMIT);
|
||||||
let result = FacePile {
|
let result = FacePile::new(
|
||||||
faces: participants
|
participants
|
||||||
.iter()
|
.iter()
|
||||||
.map(|user| Avatar::new(user.avatar_uri.clone()).into_any_element())
|
.map(|user| Avatar::new(user.avatar_uri.clone()).into_any_element())
|
||||||
.take(FACEPILE_LIMIT)
|
.take(FACEPILE_LIMIT)
|
||||||
.chain(if extra_count > 0 {
|
.chain(if extra_count > 0 {
|
||||||
Some(
|
Some(
|
||||||
div()
|
div()
|
||||||
.ml_1()
|
.ml_2()
|
||||||
.child(Label::new(format!("+{extra_count}")))
|
.child(Label::new(format!("+{extra_count}")))
|
||||||
.into_any_element(),
|
.into_any_element(),
|
||||||
)
|
)
|
||||||
|
@ -2230,7 +2230,7 @@ impl CollabPanel {
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
.collect::<SmallVec<_>>(),
|
.collect::<SmallVec<_>>(),
|
||||||
};
|
);
|
||||||
|
|
||||||
Some(result)
|
Some(result)
|
||||||
} else {
|
} else {
|
||||||
|
@ -2295,7 +2295,7 @@ impl CollabPanel {
|
||||||
h_flex()
|
h_flex()
|
||||||
.id(channel_id as usize)
|
.id(channel_id as usize)
|
||||||
.child(Label::new(channel.name.clone()))
|
.child(Label::new(channel.name.clone()))
|
||||||
.children(face_pile.map(|face_pile| face_pile.render().p_1())),
|
.children(face_pile.map(|face_pile| face_pile.p_1())),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
|
|
|
@ -495,7 +495,7 @@ impl CollabTitlebarItem {
|
||||||
div.rounded_md().bg(color)
|
div.rounded_md().bg(color)
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
FacePile::default()
|
FacePile::empty()
|
||||||
.child(
|
.child(
|
||||||
Avatar::new(user.avatar_uri.clone())
|
Avatar::new(user.avatar_uri.clone())
|
||||||
.grayscale(!is_present)
|
.grayscale(!is_present)
|
||||||
|
@ -547,8 +547,7 @@ impl CollabTitlebarItem {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
})
|
}),
|
||||||
.render(),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,28 @@
|
||||||
use gpui::{div, AnyElement, Div, ParentElement, Styled};
|
use gpui::AnyElement;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use ui::FluentBuilder;
|
use ui::prelude::*;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(IntoElement)]
|
||||||
pub struct FacePile {
|
pub struct FacePile {
|
||||||
pub faces: SmallVec<[AnyElement; 2]>,
|
base: Div,
|
||||||
|
faces: SmallVec<[AnyElement; 2]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FacePile {
|
impl FacePile {
|
||||||
pub fn render(self) -> Div {
|
pub fn empty() -> Self {
|
||||||
|
Self::new(SmallVec::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(faces: SmallVec<[AnyElement; 2]>) -> Self {
|
||||||
|
Self {
|
||||||
|
base: h_flex(),
|
||||||
|
faces,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderOnce for FacePile {
|
||||||
|
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||||
let player_count = self.faces.len();
|
let player_count = self.faces.len();
|
||||||
let player_list = self.faces.into_iter().enumerate().map(|(ix, player)| {
|
let player_list = self.faces.into_iter().enumerate().map(|(ix, player)| {
|
||||||
let isnt_last = ix < player_count - 1;
|
let isnt_last = ix < player_count - 1;
|
||||||
|
@ -18,7 +32,7 @@ impl FacePile {
|
||||||
.when(isnt_last, |div| div.neg_mr_1())
|
.when(isnt_last, |div| div.neg_mr_1())
|
||||||
.child(player)
|
.child(player)
|
||||||
});
|
});
|
||||||
div().flex().items_center().children(player_list)
|
self.base.children(player_list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,3 +41,9 @@ impl ParentElement for FacePile {
|
||||||
&mut self.faces
|
&mut self.faces
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Styled for FacePile {
|
||||||
|
fn style(&mut self) -> &mut gpui::StyleRefinement {
|
||||||
|
self.base.style()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue