From 23652f2ba69e2cc01f90f62bd9a749b51c6b519a Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 20 Sep 2021 20:04:48 +0200 Subject: [PATCH] Start on `PeoplePanel::render` Co-Authored-By: Max Brunsfeld Co-Authored-By: Nathan Sobo --- zed/src/people_panel.rs | 98 +++++++++++++++++++++++++++++++++++++---- zed/src/theme.rs | 11 +++++ zed/src/workspace.rs | 6 ++- 3 files changed, 105 insertions(+), 10 deletions(-) diff --git a/zed/src/people_panel.rs b/zed/src/people_panel.rs index 246a5e0491..38673edefd 100644 --- a/zed/src/people_panel.rs +++ b/zed/src/people_panel.rs @@ -1,17 +1,99 @@ use gpui::{ - elements::Empty, Element, ElementBox, Entity, ModelHandle, RenderContext, View, ViewContext, + elements::*, Element, ElementBox, Entity, ModelHandle, RenderContext, View, ViewContext, +}; +use postage::watch; + +use crate::{ + theme::Theme, + user::{Collaborator, UserStore}, + Settings, }; -use crate::user::UserStore; - pub struct PeoplePanel { + collaborators: ListState, user_store: ModelHandle, } impl PeoplePanel { - pub fn new(user_store: ModelHandle, cx: &mut ViewContext) -> Self { - cx.observe(&user_store, |_, _, cx| cx.notify()); - Self { user_store } + pub fn new( + user_store: ModelHandle, + settings: watch::Receiver, + cx: &mut ViewContext, + ) -> Self { + cx.observe(&user_store, Self::update_collaborators); + Self { + collaborators: ListState::new( + user_store.read(cx).collaborators().len(), + Orientation::Top, + 1000., + { + let user_store = user_store.clone(); + move |ix, cx| { + let user_store = user_store.read(cx); + let settings = settings.borrow(); + Self::render_collaborator(&user_store.collaborators()[ix], &settings.theme) + } + }, + ), + user_store, + } + } + + fn update_collaborators(&mut self, _: ModelHandle, cx: &mut ViewContext) { + self.collaborators + .reset(self.user_store.read(cx).collaborators().len()); + cx.notify(); + } + + fn render_collaborator(collaborator: &Collaborator, theme: &Theme) -> ElementBox { + Flex::column() + .with_child( + Flex::row() + .with_children(collaborator.user.avatar.clone().map(|avatar| { + ConstrainedBox::new( + Image::new(avatar) + .with_style(theme.people_panel.worktree_host_avatar) + .boxed(), + ) + .with_width(20.) + .boxed() + })) + .with_child( + Label::new( + collaborator.user.github_login.clone(), + theme.people_panel.collaborator_username.clone(), + ) + .boxed(), + ) + .boxed(), + ) + .with_children(collaborator.worktrees.iter().map(|worktree| { + Flex::row() + .with_child( + Container::new( + Label::new( + worktree.root_name.clone(), + theme.people_panel.worktree_name.text.clone(), + ) + .boxed(), + ) + .with_style(theme.people_panel.worktree_name.container) + .boxed(), + ) + .with_children(worktree.participants.iter().filter_map(|participant| { + participant.avatar.clone().map(|avatar| { + ConstrainedBox::new( + Image::new(avatar) + .with_style(theme.people_panel.worktree_guest_avatar) + .boxed(), + ) + .with_width(16.) + .boxed() + }) + })) + .boxed() + })) + .boxed() } } @@ -26,7 +108,7 @@ impl View for PeoplePanel { "PeoplePanel" } - fn render(&mut self, _: &mut RenderContext) -> ElementBox { - Empty::new().boxed() + fn render(&mut self, cx: &mut RenderContext) -> ElementBox { + List::new(self.collaborators.clone()).boxed() } } diff --git a/zed/src/theme.rs b/zed/src/theme.rs index a96945fecc..38c93db14b 100644 --- a/zed/src/theme.rs +++ b/zed/src/theme.rs @@ -23,6 +23,7 @@ pub struct Theme { pub name: String, pub workspace: Workspace, pub chat_panel: ChatPanel, + pub people_panel: PeoplePanel, pub selector: Selector, pub editor: EditorStyle, pub syntax: SyntaxTheme, @@ -103,6 +104,16 @@ pub struct ChatPanel { pub hovered_sign_in_prompt: TextStyle, } +#[derive(Deserialize)] +pub struct PeoplePanel { + #[serde(flatten)] + pub container: ContainerStyle, + pub collaborator_username: TextStyle, + pub worktree_name: ContainedText, + pub worktree_host_avatar: ImageStyle, + pub worktree_guest_avatar: ImageStyle, +} + #[derive(Deserialize)] pub struct ChatMessage { #[serde(flatten)] diff --git a/zed/src/workspace.rs b/zed/src/workspace.rs index 3182fc3aab..baf14936cc 100644 --- a/zed/src/workspace.rs +++ b/zed/src/workspace.rs @@ -381,8 +381,10 @@ impl Workspace { ); right_sidebar.add_item( "icons/user-16.svg", - cx.add_view(|cx| PeoplePanel::new(app_state.user_store.clone(), cx)) - .into(), + cx.add_view(|cx| { + PeoplePanel::new(app_state.user_store.clone(), app_state.settings.clone(), cx) + }) + .into(), ); let mut current_user = app_state.user_store.read(cx).watch_current_user().clone();