1use crate::TitleBar;
2use call::Room;
3use client::{proto::PeerId, User};
4use gpui::{canvas, point, Hsla, IntoElement, Path, Styled};
5use rpc::proto::{self};
6use std::sync::Arc;
7use theme::ActiveTheme;
8use ui::{prelude::*, Avatar, AvatarAudioStatusIndicator, Facepile, Tooltip};
9
10pub(crate) fn render_color_ribbon(color: Hsla) -> impl Element {
11 canvas(
12 move |_, _| {},
13 move |bounds, _, cx| {
14 let height = bounds.size.height;
15 let horizontal_offset = height;
16 let vertical_offset = px(height.0 / 2.0);
17 let mut path = Path::new(bounds.lower_left());
18 path.curve_to(
19 bounds.origin + point(horizontal_offset, vertical_offset),
20 bounds.origin + point(px(0.0), vertical_offset),
21 );
22 path.line_to(bounds.upper_right() + point(-horizontal_offset, vertical_offset));
23 path.curve_to(
24 bounds.lower_right(),
25 bounds.upper_right() + point(px(0.0), vertical_offset),
26 );
27 path.line_to(bounds.lower_left());
28 cx.paint_path(path, color);
29 },
30 )
31 .h_1()
32 .w_full()
33}
34
35impl TitleBar {
36 #[allow(clippy::too_many_arguments)]
37 pub(crate) fn render_collaborator(
38 &self,
39 user: &Arc<User>,
40 peer_id: PeerId,
41 is_present: bool,
42 is_speaking: bool,
43 is_muted: bool,
44 leader_selection_color: Option<Hsla>,
45 room: &Room,
46 project_id: Option<u64>,
47 current_user: &Arc<User>,
48 cx: &ViewContext<Self>,
49 ) -> Option<Div> {
50 if room.role_for_user(user.id) == Some(proto::ChannelRole::Guest) {
51 return None;
52 }
53
54 const FACEPILE_LIMIT: usize = 3;
55 let followers = project_id.map_or(&[] as &[_], |id| room.followers_for(peer_id, id));
56 let extra_count = followers.len().saturating_sub(FACEPILE_LIMIT);
57
58 Some(
59 div()
60 .m_0p5()
61 .p_0p5()
62 // When the collaborator is not followed, still draw this wrapper div, but leave
63 // it transparent, so that it does not shift the layout when following.
64 .when_some(leader_selection_color, |div, color| {
65 div.rounded_md().bg(color)
66 })
67 .child(
68 Facepile::empty()
69 .child(
70 Avatar::new(user.avatar_uri.clone())
71 .grayscale(!is_present)
72 .border_color(if is_speaking {
73 cx.theme().status().info
74 } else {
75 // We draw the border in a transparent color rather to avoid
76 // the layout shift that would come with adding/removing the border.
77 gpui::transparent_black()
78 })
79 .when(is_muted, |avatar| {
80 avatar.indicator(
81 AvatarAudioStatusIndicator::new(ui::AudioStatus::Muted)
82 .tooltip({
83 let github_login = user.github_login.clone();
84 move |cx| {
85 Tooltip::text(
86 format!("{} is muted", github_login),
87 cx,
88 )
89 }
90 }),
91 )
92 }),
93 )
94 .children(followers.iter().take(FACEPILE_LIMIT).filter_map(
95 |follower_peer_id| {
96 let follower = room
97 .remote_participants()
98 .values()
99 .find_map(|p| {
100 (p.peer_id == *follower_peer_id).then_some(&p.user)
101 })
102 .or_else(|| {
103 (self.client.peer_id() == Some(*follower_peer_id))
104 .then_some(current_user)
105 })?
106 .clone();
107
108 Some(div().mt(-px(4.)).child(
109 Avatar::new(follower.avatar_uri.clone()).size(rems(0.75)),
110 ))
111 },
112 ))
113 .children(if extra_count > 0 {
114 Some(
115 div()
116 .ml_1()
117 .child(Label::new(format!("+{extra_count}")))
118 .into_any_element(),
119 )
120 } else {
121 None
122 }),
123 ),
124 )
125 }
126}