From 809b843cebcc67baa11da55579031a92445ce073 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 15 Feb 2022 09:17:32 +0100 Subject: [PATCH] Render "Sign in" label only for current user --- crates/workspace/src/workspace.rs | 79 ++++++++++++++++++------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 2203e8cbf7..d5d0af6104 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -17,9 +17,9 @@ use gpui::{ json::{self, to_string_pretty, ToJson}, keymap::Binding, platform::{CursorStyle, WindowOptions}, - AnyModelHandle, AnyViewHandle, AppContext, ClipboardItem, Entity, ModelContext, ModelHandle, - MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, Task, View, ViewContext, - ViewHandle, WeakModelHandle, WeakViewHandle, + AnyModelHandle, AnyViewHandle, AppContext, ClipboardItem, Entity, ImageData, ModelContext, + ModelHandle, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, Task, View, + ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle, }; use language::LanguageRegistry; use log::error; @@ -1139,7 +1139,7 @@ impl Workspace { Flex::row() .with_children(self.render_share_icon(theme, cx)) .with_children(self.render_collaborators(theme, cx)) - .with_child(self.render_avatar( + .with_child(self.render_current_user( self.user_store.read(cx).current_user().as_ref(), self.project.read(cx).replica_id(), theme, @@ -1171,13 +1171,17 @@ impl Workspace { collaborators.sort_unstable_by_key(|collaborator| collaborator.replica_id); collaborators .into_iter() - .map(|collaborator| { - self.render_avatar(Some(&collaborator.user), collaborator.replica_id, theme, cx) + .filter_map(|collaborator| { + Some(self.render_avatar( + collaborator.user.avatar.clone()?, + collaborator.replica_id, + theme, + )) }) .collect() } - fn render_avatar( + fn render_current_user( &self, user: Option<&Arc>, replica_id: ReplicaId, @@ -1185,33 +1189,9 @@ impl Workspace { cx: &mut RenderContext, ) -> ElementBox { if let Some(avatar) = user.and_then(|user| user.avatar.clone()) { - ConstrainedBox::new( - Stack::new() - .with_child( - ConstrainedBox::new( - Image::new(avatar) - .with_style(theme.workspace.titlebar.avatar) - .boxed(), - ) - .with_width(theme.workspace.titlebar.avatar_width) - .aligned() - .boxed(), - ) - .with_child( - AvatarRibbon::new(theme.editor.replica_selection_style(replica_id).cursor) - .constrained() - .with_width(theme.workspace.titlebar.avatar_ribbon.width) - .with_height(theme.workspace.titlebar.avatar_ribbon.height) - .aligned() - .bottom() - .boxed(), - ) - .boxed(), - ) - .with_width(theme.workspace.right_sidebar.width) - .boxed() + self.render_avatar(avatar, replica_id, theme) } else { - MouseEventHandler::new::(0, cx, |state, _| { + MouseEventHandler::new::(cx.view_id(), cx, |state, _| { let style = if state.hovered { &theme.workspace.titlebar.hovered_sign_in_prompt } else { @@ -1229,6 +1209,39 @@ impl Workspace { } } + fn render_avatar( + &self, + avatar: Arc, + replica_id: ReplicaId, + theme: &Theme, + ) -> ElementBox { + ConstrainedBox::new( + Stack::new() + .with_child( + ConstrainedBox::new( + Image::new(avatar) + .with_style(theme.workspace.titlebar.avatar) + .boxed(), + ) + .with_width(theme.workspace.titlebar.avatar_width) + .aligned() + .boxed(), + ) + .with_child( + AvatarRibbon::new(theme.editor.replica_selection_style(replica_id).cursor) + .constrained() + .with_width(theme.workspace.titlebar.avatar_ribbon.width) + .with_height(theme.workspace.titlebar.avatar_ribbon.height) + .aligned() + .bottom() + .boxed(), + ) + .boxed(), + ) + .with_width(theme.workspace.right_sidebar.width) + .boxed() + } + fn render_share_icon(&self, theme: &Theme, cx: &mut RenderContext) -> Option { if self.project().read(cx).is_local() && self.client.user_id().is_some() { enum Share {}