Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Make `FacePile` a component again (#4143)
Marshall Bowerse278410fbc5a
diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rsindex 4bfb5fe3ae9..4a1c2e372dd 100644--- a/crates/collab_ui/src/collab_panel.rs+++ b/crates/collab_ui/src/collab_panel.rs@@ -2214,15 +2214,15 @@ impl CollabPanel {let face_pile = if !participants.is_empty() {let extra_count = participants.len().saturating_sub(FACEPILE_LIMIT);- let result = FacePile {- faces: participants+ let result = FacePile::new(+ participants.iter().map(|user| Avatar::new(user.avatar_uri.clone()).into_any_element()).take(FACEPILE_LIMIT).chain(if extra_count > 0 {Some(div()- .ml_1()+ .ml_2().child(Label::new(format!("+{extra_count}"))).into_any_element(),)@@ -2230,7 +2230,7 @@ impl CollabPanel {None}).collect::<SmallVec<_>>(),- };+ );Some(result)} else {@@ -2295,7 +2295,7 @@ impl CollabPanel {h_flex().id(channel_id as usize).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(diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rsindex e864c4c54ad..32ab64f77ee 100644--- a/crates/collab_ui/src/collab_titlebar_item.rs+++ b/crates/collab_ui/src/collab_titlebar_item.rs@@ -495,7 +495,7 @@ impl CollabTitlebarItem {div.rounded_md().bg(color)}).child(- FacePile::default()+ FacePile::empty().child(Avatar::new(user.avatar_uri.clone()).grayscale(!is_present)@@ -547,8 +547,7 @@ impl CollabTitlebarItem {)} else {None- })- .render(),+ }),),)}diff --git a/crates/collab_ui/src/face_pile.rs b/crates/collab_ui/src/face_pile.rsindex 3efe17e5a60..eb20814ca75 100644--- a/crates/collab_ui/src/face_pile.rs+++ b/crates/collab_ui/src/face_pile.rs@@ -1,14 +1,28 @@-use gpui::{div, AnyElement, Div, ParentElement, Styled};+use gpui::AnyElement;use smallvec::SmallVec;-use ui::FluentBuilder;+use ui::prelude::*;-#[derive(Default)]+#[derive(IntoElement)]pub struct FacePile {- pub faces: SmallVec<[AnyElement; 2]>,+ base: Div,+ faces: SmallVec<[AnyElement; 2]>,}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_list = self.faces.into_iter().enumerate().map(|(ix, player)| {let isnt_last = ix < player_count - 1;@@ -18,7 +32,7 @@ impl FacePile {.when(isnt_last, |div| div.neg_mr_1()).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}}++impl Styled for FacePile {+ fn style(&mut self) -> &mut gpui::StyleRefinement {+ self.base.style()+ }+}