Use facepile for avatars

This commit is contained in:
Piotr Osiewicz 2023-11-27 14:56:51 +01:00
parent 714b45157b
commit bf4211b03a
3 changed files with 54 additions and 78 deletions

View file

@ -31,9 +31,9 @@ use std::sync::Arc;
use call::ActiveCall; use call::ActiveCall;
use client::{Client, UserStore}; use client::{Client, UserStore};
use gpui::{ use gpui::{
div, px, rems, AppContext, Div, InteractiveElement, IntoElement, Model, MouseButton, div, px, rems, AppContext, Div, Element, InteractiveElement, IntoElement, Model, MouseButton,
ParentElement, Render, Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, ParentElement, Render, RenderOnce, Stateful, StatefulInteractiveElement, Styled, Subscription,
VisualContext, WeakView, WindowBounds, ViewContext, VisualContext, WeakView, WindowBounds,
}; };
use project::Project; use project::Project;
use theme::ActiveTheme; use theme::ActiveTheme;
@ -41,6 +41,8 @@ use ui::{h_stack, Avatar, Button, ButtonVariant, Color, IconButton, KeyBinding,
use util::ResultExt; use util::ResultExt;
use workspace::Workspace; use workspace::Workspace;
use crate::face_pile::FacePile;
// const MAX_PROJECT_NAME_LENGTH: usize = 40; // const MAX_PROJECT_NAME_LENGTH: usize = 40;
// const MAX_BRANCH_NAME_LENGTH: usize = 40; // const MAX_BRANCH_NAME_LENGTH: usize = 40;
@ -178,16 +180,21 @@ impl Render for CollabTitlebarItem {
.when_some( .when_some(
users.zip(current_user.clone()), users.zip(current_user.clone()),
|this, (remote_participants, current_user)| { |this, (remote_participants, current_user)| {
this.children( let mut pile = FacePile::default();
pile.extend(
current_user current_user
.avatar .avatar
.clone() .clone()
.map(|avatar| div().child(Avatar::data(avatar.clone()))) .map(|avatar| {
div().child(Avatar::data(avatar.clone())).into_any_element()
})
.into_iter() .into_iter()
.chain(remote_participants.into_iter().flat_map(|(user, peer_id)| { .chain(remote_participants.into_iter().flat_map(|(user, peer_id)| {
user.avatar.as_ref().map(|avatar| { user.avatar.as_ref().map(|avatar| {
div() div()
.child(Avatar::data(avatar.clone()).into_element()) .child(
Avatar::data(avatar.clone()).into_element().into_any(),
)
.on_mouse_down(MouseButton::Left, { .on_mouse_down(MouseButton::Left, {
let workspace = workspace.clone(); let workspace = workspace.clone();
move |_, cx| { move |_, cx| {
@ -198,9 +205,11 @@ impl Render for CollabTitlebarItem {
.log_err(); .log_err();
} }
}) })
.into_any_element()
}) })
})), })),
) );
this.child(pile.render(cx))
}, },
) )
.child(div().flex_1()) .child(div().flex_1())

View file

@ -1,54 +1,50 @@
// use std::ops::Range; use gpui::{
div, AnyElement, Div, IntoElement as _, ParentElement as _, Render, RenderOnce, Styled,
ViewContext, WindowContext,
};
use ui::Avatar;
// use gpui::{ #[derive(Default)]
// geometry::{ pub(crate) struct FacePile {
// rect::RectF, faces: Vec<AnyElement>,
// vector::{vec2f, Vector2F}, }
// },
// json::ToJson,
// serde_json::{self, json},
// AnyElement, Axis, Element, View, ViewContext,
// };
// pub(crate) struct FacePile<V: View> { impl RenderOnce for FacePile {
// overlap: f32, type Rendered = Div;
// faces: Vec<AnyElement<V>>,
// }
// impl<V: View> FacePile<V> { fn render(self, _: &mut WindowContext) -> Self::Rendered {
// pub fn new(overlap: f32) -> Self { let player_count = self.faces.len();
// Self { let player_list = self.faces.into_iter().enumerate().map(|(ix, player)| {
// overlap, let isnt_last = ix < player_count - 1;
// faces: Vec::new(),
// }
// }
// }
// impl<V: View> Element<V> for FacePile<V> { div().when(isnt_last, |div| div.neg_mr_2()).child(player)
// type LayoutState = (); });
// type PaintState = (); div().p_1().flex().items_center().children(player_list)
}
}
// impl Element for FacePile {
// type State = ();
// fn layout( // fn layout(
// &mut self, // &mut self,
// constraint: gpui::SizeConstraint, // state: Option<Self::State>,
// view: &mut V, // cx: &mut WindowContext,
// cx: &mut ViewContext<V>, // ) -> (LayoutId, Self::State) {
// ) -> (Vector2F, Self::LayoutState) {
// debug_assert!(constraint.max_along(Axis::Horizontal) == f32::INFINITY);
// let mut width = 0.; // let mut width = 0.;
// let mut max_height = 0.; // let mut max_height = 0.;
// let mut faces = Vec::with_capacity(self.faces.len());
// for face in &mut self.faces { // for face in &mut self.faces {
// let layout = face.layout(constraint, view, cx); // let layout = face.layout(cx);
// width += layout.x(); // width += layout.x();
// max_height = f32::max(max_height, layout.y()); // max_height = f32::max(max_height, layout.y());
// faces.push(layout);
// } // }
// width -= self.overlap * self.faces.len().saturating_sub(1) as f32; // width -= self.overlap * self.faces.len().saturating_sub(1) as f32;
// (cx.request_layout(&Style::default(), faces), ())
// ( // // (
// Vector2F::new(width, max_height.clamp(1., constraint.max.y())), // // Vector2F::new(width, max_height.clamp(1., constraint.max.y())),
// (), // // (),
// ) // // ))
// } // }
// fn paint( // fn paint(
@ -77,37 +73,10 @@
// () // ()
// } // }
// fn rect_for_text_range(
// &self,
// _: Range<usize>,
// _: RectF,
// _: RectF,
// _: &Self::LayoutState,
// _: &Self::PaintState,
// _: &V,
// _: &ViewContext<V>,
// ) -> Option<RectF> {
// None
// } // }
// fn debug( impl Extend<AnyElement> for FacePile {
// &self, fn extend<T: IntoIterator<Item = AnyElement>>(&mut self, children: T) {
// bounds: RectF, self.faces.extend(children);
// _: &Self::LayoutState, }
// _: &Self::PaintState, }
// _: &V,
// _: &ViewContext<V>,
// ) -> serde_json::Value {
// json!({
// "type": "FacePile",
// "bounds": bounds.to_json()
// })
// }
// }
// impl<V: View> Extend<AnyElement<V>> for FacePile<V> {
// fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
// self.faces.extend(children);
// }
// }

View file

@ -2003,8 +2003,6 @@ impl Workspace {
self.active_pane.update(cx, |pane, cx| { self.active_pane.update(cx, |pane, cx| {
pane.add_item(shared_screen, false, true, None, cx) pane.add_item(shared_screen, false, true, None, cx)
}); });
} else {
dbg!("WTF");
} }
} }