Add mockup accurate avatar background

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Julia 2023-02-21 17:14:32 -05:00
parent 7f4da80386
commit 9b92a8e3fe
4 changed files with 56 additions and 30 deletions

View file

@ -610,6 +610,16 @@ impl CollabTitlebarItem {
) -> ElementBox { ) -> ElementBox {
let room = ActiveCall::global(cx).read(cx).room(); let room = ActiveCall::global(cx).read(cx).room();
let is_being_followed = workspace.read(cx).is_being_followed(peer_id); let is_being_followed = workspace.read(cx).is_being_followed(peer_id);
let followed_by_self = room
.map(|room| {
is_being_followed
&& room
.read(cx)
.followers_for(peer_id)
.iter()
.any(|&follower| Some(follower) == workspace.read(cx).client().peer_id())
})
.unwrap_or(false);
let avatar_style; let avatar_style;
if let Some(location) = location { if let Some(location) = location {
@ -626,10 +636,28 @@ impl CollabTitlebarItem {
avatar_style = &theme.workspace.titlebar.avatar; avatar_style = &theme.workspace.titlebar.avatar;
} }
let mut background_color = theme
.workspace
.titlebar
.container
.background_color
.unwrap_or_default();
if let Some(replica_id) = replica_id {
if followed_by_self {
let selection = dbg!(theme.editor.replica_selection_style(replica_id).selection);
background_color = dbg!(Color::blend(selection, background_color));
background_color.a = 255;
}
}
let content = Stack::new() let content = Stack::new()
.with_children(user.avatar.as_ref().map(|avatar| { .with_children(user.avatar.as_ref().map(|avatar| {
let face_pile = FacePile::new(theme.workspace.titlebar.follower_avatar_overlap) let face_pile = FacePile::new(theme.workspace.titlebar.follower_avatar_overlap)
.with_child(Self::render_face(avatar.clone(), avatar_style.clone())) .with_child(Self::render_face(
avatar.clone(),
avatar_style.clone(),
background_color,
))
.with_children( .with_children(
(|| { (|| {
let room = room?.read(cx); let room = room?.read(cx);
@ -656,6 +684,7 @@ impl CollabTitlebarItem {
Some(Self::render_face( Some(Self::render_face(
avatar.clone(), avatar.clone(),
theme.workspace.titlebar.follower_avatar.clone(), theme.workspace.titlebar.follower_avatar.clone(),
background_color,
)) ))
})) }))
})() })()
@ -663,15 +692,7 @@ impl CollabTitlebarItem {
.flatten(), .flatten(),
); );
if let (Some(replica_id), Some(room)) = (replica_id, room) { if let Some(replica_id) = replica_id {
let followed_by_self = is_being_followed
&& room
.read(cx)
.followers_for(peer_id)
.iter()
.any(|&follower| {
Some(follower) == workspace.read(cx).client().peer_id()
});
if followed_by_self { if followed_by_self {
let color = theme.editor.replica_selection_style(replica_id).selection; let color = theme.editor.replica_selection_style(replica_id).selection;
return face_pile.contained().with_background_color(color).boxed(); return face_pile.contained().with_background_color(color).boxed();
@ -744,14 +765,20 @@ impl CollabTitlebarItem {
} }
} }
fn render_face(avatar: Arc<ImageData>, avatar_style: AvatarStyle) -> ElementBox { fn render_face(
avatar: Arc<ImageData>,
avatar_style: AvatarStyle,
background_color: Color,
) -> ElementBox {
Image::new(avatar) Image::new(avatar)
.with_style(avatar_style.image) .with_style(avatar_style.image)
.constrained() .aligned()
.with_width(avatar_style.width)
.contained() .contained()
.with_background_color(Color::white()) .with_background_color(background_color)
.with_corner_radius(avatar_style.image.corner_radius) .with_corner_radius(avatar_style.outer_corner_radius)
.constrained()
.with_width(avatar_style.outer_width)
.with_height(avatar_style.outer_width)
.aligned() .aligned()
.boxed() .boxed()
} }

View file

@ -59,7 +59,9 @@ impl Element for FacePile {
for face in self.faces.iter_mut().rev() { for face in self.faces.iter_mut().rev() {
let size = face.size(); let size = face.size();
origin_x -= size.x(); origin_x -= size.x();
face.paint(vec2f(origin_x, origin_y), visible_bounds, cx); cx.paint_layer(None, |cx| {
face.paint(vec2f(origin_x, origin_y), visible_bounds, cx);
});
origin_x += self.overlap; origin_x += self.overlap;
} }

View file

@ -93,7 +93,8 @@ pub struct Titlebar {
pub struct AvatarStyle { pub struct AvatarStyle {
#[serde(flatten)] #[serde(flatten)]
pub image: ImageStyle, pub image: ImageStyle,
pub width: f32, pub outer_width: f32,
pub outer_corner_radius: f32,
} }
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]

View file

@ -41,7 +41,9 @@ export default function workspace(colorScheme: ColorScheme) {
}, },
}; };
const avatarWidth = 18; const avatarWidth = 18;
const avatarOuterWidth = avatarWidth + 4;
const followerAvatarWidth = 14; const followerAvatarWidth = 14;
const followerAvatarOuterWidth = followerAvatarWidth + 4;
return { return {
background: background(layer), background: background(layer),
@ -96,30 +98,24 @@ export default function workspace(colorScheme: ColorScheme) {
// Collaborators // Collaborators
avatar: { avatar: {
width: avatarWidth, width: avatarWidth,
outerWidth: avatarOuterWidth,
cornerRadius: avatarWidth / 2, cornerRadius: avatarWidth / 2,
border: { outerCornerRadius: avatarOuterWidth / 2,
color: "#00000088",
width: 1,
},
}, },
inactiveAvatar: { inactiveAvatar: {
width: avatarWidth, width: avatarWidth,
outerWidth: avatarOuterWidth,
cornerRadius: avatarWidth / 2, cornerRadius: avatarWidth / 2,
border: { outerCornerRadius: avatarOuterWidth / 2,
color: "#00000088",
width: 1,
},
grayscale: true, grayscale: true,
}, },
followerAvatar: { followerAvatar: {
width: followerAvatarWidth, width: followerAvatarWidth,
outerWidth: followerAvatarOuterWidth,
cornerRadius: followerAvatarWidth / 2, cornerRadius: followerAvatarWidth / 2,
border: { outerCornerRadius: followerAvatarOuterWidth / 2,
color: "#00000088",
width: 1,
},
}, },
followerAvatarOverlap: 6, followerAvatarOverlap: 8,
avatarRibbon: { avatarRibbon: {
height: 3, height: 3,
width: 12, width: 12,