BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / call_view.rs

call_view.rs

call_view.rs 47.5 KiB Download Raw
1use std::sync::Arc;
2use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
3
4use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, VideoKey};
5use gpui_kit::assets::IconName;
6use gpui_kit::component::{
7 button::{Button, ButtonVariants as _},
8 h_flex,
9 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
10 popover::Popover,
11 switch::Switch,
12 tooltip::Tooltip,
13 v_flex,
14};
15use gpui_kit::prelude::FluentBuilder as _;
16use gpui_kit::*;
17
18use super::avatar::person_avatar;
19use super::call_control_fold::{
20 CONTROL_GAP, CONTROLS_PADDING, Foldable, FoldedControls, fixed_controls_width, folded_for_width,
21};
22use super::call_extras::{
23 CameraMenu, consent_overlay, consult_banner, hold_panel, recording_chip, return_button,
24 room_chip, whiteboard_stage,
25};
26use super::call_health::{health_banner, health_indicator};
27use super::call_layouts::stage_region;
28use crate::call::measured_stage;
29use super::call_organizer::{
30 camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
31 more_button, pin_chip, spotlight_chip, with_tile_menu,
32};
33use super::call_people::{lock_banner, lock_chip, options_dialog, people_button, people_panel};
34use super::call_stage::{StageMode, popped_placeholder, render_stage};
35use super::call_view_menu::view_button;
36use app_ui_kit::layout::ISLAND_GAP;
37use super::widgets::{Corner, corner_badge, count_badge, icon};
38use crate::app_state::AppState;
39use crate::call::REACTION_SHOWN;
40use crate::call::TileSize;
41use crate::call::{ActiveCall, CallKind, CallModel, Tile, TileState};
42use crate::rows::reaction_glyph as chat_reaction_glyph;
43use crate::theme;
44
45const HEADER_HEIGHT: f32 = 60.;
46const RING_WIDTH: f32 = 3.;
47const RING_GAP: f32 = 4.;
48pub(super) const CONTROL_SIZE: f32 = 44.;
49const CONTROL_ICON: f32 = 20.;
50pub(super) const MENU_WIDTH: f32 = 280.;
51const SHARE_MENU_WIDTH: f32 = 360.;
52const PULSE_PERIOD: Duration = Duration::from_millis(1400);
53const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
54const BLINK_DIMMED_OPACITY: f32 = 0.45;
55pub(super) const DISABLED_OPACITY: f32 = 0.4;
56const TILE_RADIUS: f32 = 12.;
57const NAME_PLATE_BACKGROUND: f32 = 0.6;
58const COMPACT_PLATE_BELOW: f32 = 200.;
59pub const CHAT_PANEL_TAG: &str = "shell/islands/main/call-chat-panel";
60pub const NO_MICROPHONE_HINT: &str = "No microphone found";
61const AUDIO_OFF_HINT: &str = "Audio is off for this meeting";
62pub const NO_CAMERA_HINT: &str = "No camera found";
63pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";
64pub const NO_WINDOWS_HINT: &str = "No windows found";
65pub(super) const BANNER_HEIGHT: f32 = 40.;
66const MAX_WINDOW_ITEMS: usize = 12;
67pub const SHARE_THUMBNAIL_TAG: &str = "call/share-menu/thumbnail";
68const SCREEN_THUMBNAIL: (f32, f32) = (128., 72.);
69const WINDOW_THUMBNAIL: (f32, f32) = (96., 54.);
70const THUMBNAIL_RADIUS: f32 = 6.;
71const THUMBNAIL_ICON: f32 = 22.;
72pub const LOBBY_TEXT: &str = "Waiting in the lobby...";
73pub(super) const CHAT_PANEL_WIDTH: f32 = 320.;
74pub(super) const OVERLAY_BELOW: f32 = 720.;
75const CONTROLS_HEIGHT: f32 = 2. * 16. + CONTROL_SIZE;
76const CHAT_HEADER_HEIGHT: f32 = 48.;
77const REACTION_RISE: f32 = 24.;
78const REACTION_FADE_FROM: f32 = 0.75;
79const REACTION_CELL: f32 = 40.;
80const SHARE_SOUND_LABEL: &str = "Include computer sound";
81const SHARE_MOTION_LABEL: &str = "Optimize for motion";
82const SHARE_STANDOUT_LABEL: &str = "Show me over my content";
83const SHARE_STANDOUT_NEEDS_CAMERA: &str = "Turn your camera on first";
84const NOISE_SUPPRESSION_LABEL: &str = "Noise suppression";
85const MUSIC_MODE_LABEL: &str = "Music mode";
86const PUSH_TO_TALK_HINT: &str = "Unmuted - release Ctrl+Space to mute";
87const PUSH_TO_TALK_TOP: f32 = 12.;
88
89pub fn reaction_glyph(reaction: &Reaction) -> String {
90 match reaction {
91 Reaction::Applause => "\u{1F44F}".to_owned(),
92 other => chat_reaction_glyph(other.name()),
93 }
94}
95
96fn is_emoji_glyph(glyph: &str) -> bool {
97 !glyph.is_ascii()
98}
99
100#[derive(Default)]
101struct TileExtras {
102 hand: Option<usize>,
103 own: bool,
104 reaction: Option<(Reaction, u64)>,
105 spotlight: bool,
106 pinned: bool,
107 fitted: bool,
108}
109
110fn hand_badge(position: usize, own: bool) -> Div {
111 h_flex()
112 .h(px(24.))
113 .px(px(8.))
114 .gap(px(4.))
115 .items_center()
116 .rounded_full()
117 .bg(theme::amber())
118 .text_color(hsla(0., 0., 0.08, 1.))
119 .text_size(px(12.))
120 .font_weight(FontWeight::SEMIBOLD)
121 .child(if own {
122 "Hand raised".to_owned()
123 } else {
124 format!("Hand {position}")
125 })
126}
127
128fn reaction_chip(reaction: Reaction, serial: u64) -> AnyElement {
129 let glyph = reaction_glyph(&reaction);
130 let emoji = is_emoji_glyph(&glyph);
131 div()
132 .absolute()
133 .right(px(12.))
134 .bottom(px(32.))
135 .h(px(36.))
136 .min_w(px(36.))
137 .when(!emoji, |chip| chip.px(px(12.)))
138 .flex()
139 .items_center()
140 .justify_center()
141 .rounded_full()
142 .bg(theme::popup())
143 .text_size(px(if emoji { 20. } else { 13. }))
144 .child(glyph)
145 .with_animation(
146 ("call-reaction", serial as usize),
147 Animation::new(REACTION_SHOWN),
148 |chip, delta| {
149 let fade = ((delta - REACTION_FADE_FROM) / (1. - REACTION_FADE_FROM)).clamp(0., 1.);
150 chip.bottom(px(32. + REACTION_RISE * delta))
151 .opacity(1. - fade)
152 },
153 )
154 .into_any_element()
155}
156
157fn tile_overlays(extras: &TileExtras) -> Vec<AnyElement> {
158 let badges = (extras.hand.is_some() || extras.spotlight || extras.pinned).then(|| {
159 h_flex()
160 .absolute()
161 .top(px(8.))
162 .left(px(8.))
163 .gap(px(6.))
164 .children(extras.hand.map(|position| hand_badge(position, extras.own)))
165 .when(extras.spotlight, |row| row.child(spotlight_chip()))
166 .when(extras.pinned, |row| row.child(pin_chip()))
167 .into_any_element()
168 });
169 let reaction = extras
170 .reaction
171 .clone()
172 .map(|(reaction, serial)| reaction_chip(reaction, serial));
173 badges.into_iter().chain(reaction).collect()
174}
175
176pub fn status_line(model: &CallModel, now: Instant) -> (String, Hsla) {
177 if model.lobby {
178 (LOBBY_TEXT.to_owned(), theme::amber())
179 } else if model.is_connecting() {
180 (model.connecting_text().to_owned(), theme::text_muted())
181 } else if model.is_reconnecting() {
182 ("Reconnecting...".to_owned(), theme::amber())
183 } else if model.view.hide_timer {
184 (String::new(), theme::text_muted())
185 } else {
186 (model.timer_text(now), theme::text_muted())
187 }
188}
189
190pub fn pulsing(element: impl IntoElement + 'static, id: &'static str) -> AnyElement {
191 div()
192 .child(element)
193 .with_animation(
194 id,
195 Animation::new(PULSE_PERIOD).repeat(),
196 |element, delta| {
197 let wave = 1. - (delta * 2. - 1.).abs();
198 element.opacity(0.45 + 0.55 * wave)
199 },
200 )
201 .into_any_element()
202}
203
204fn blinking(element: impl IntoElement + 'static) -> AnyElement {
205 let dimmed = SystemTime::now()
206 .duration_since(UNIX_EPOCH)
207 .is_ok_and(|elapsed| (elapsed.as_millis() / BLINK_HALF_PERIOD.as_millis()) % 2 == 1);
208 div()
209 .child(element)
210 .opacity(if dimmed { BLINK_DIMMED_OPACITY } else { 1. })
211 .into_any_element()
212}
213
214fn speaking_ring(avatar: AnyElement, speaking: bool) -> Div {
215 div()
216 .p(px(RING_GAP))
217 .rounded_full()
218 .border(px(RING_WIDTH))
219 .border_color(if speaking {
220 theme::green()
221 } else {
222 transparent_black()
223 })
224 .child(avatar)
225}
226
227fn mute_badge() -> Div {
228 div()
229 .absolute()
230 .top(px(8.))
231 .right(px(8.))
232 .size(px(24.))
233 .flex()
234 .items_center()
235 .justify_center()
236 .rounded_full()
237 .bg(theme::red())
238 .child(icon(IconName::MicOff, 13., theme::white()))
239}
240
241struct NamePlate {
242 inset: f32,
243 padding_x: f32,
244 padding_y: f32,
245 radius: f32,
246 text_size: f32,
247 max_width_share: f32,
248}
249
250fn name_plate_metrics(size: TileSize) -> NamePlate {
251 if size.height < COMPACT_PLATE_BELOW {
252 NamePlate { inset: 4., padding_x: 6., padding_y: 2., radius: 4., text_size: 11., max_width_share: 0.6 }
253 } else {
254 NamePlate { inset: 8., padding_x: 8., padding_y: 4., radius: 6., text_size: 12., max_width_share: 1. }
255 }
256}
257
258fn name_plate(size: TileSize, name: &str) -> Div {
259 let plate = name_plate_metrics(size);
260 div()
261 .absolute()
262 .left(px(plate.inset))
263 .bottom(px(plate.inset))
264 .max_w(px(((size.width - 3. * plate.inset) * plate.max_width_share).max(0.)))
265 .truncate()
266 .px(px(plate.padding_x))
267 .py(px(plate.padding_y))
268 .rounded(px(plate.radius))
269 .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
270 .text_size(px(plate.text_size))
271 .font_weight(FontWeight::SEMIBOLD)
272 .text_color(theme::white())
273 .child(name.to_owned())
274}
275
276fn video_tile(
277 size: TileSize,
278 image: Arc<RenderImage>,
279 name: &str,
280 speaking: bool,
281 muted: bool,
282 extras: &TileExtras,
283) -> Div {
284 div()
285 .relative()
286 .w(px(size.width))
287 .h(px(size.height))
288 .flex_none()
289 .overflow_hidden()
290 .rounded(px(TILE_RADIUS))
291 .bg(theme::row_hover())
292 .border_2()
293 .border_color(if speaking {
294 theme::green()
295 } else {
296 transparent_black()
297 })
298 .child(
299 img(ImageSource::Render(image))
300 .size_full()
301 .object_fit(if extras.fitted {
302 ObjectFit::Contain
303 } else {
304 ObjectFit::Cover
305 })
306 .rounded(px(TILE_RADIUS)),
307 )
308 .child(name_plate(size, name))
309 .when(muted, |tile| tile.child(mute_badge()))
310 .children(tile_overlays(extras))
311}
312
313fn tile(
314 size: TileSize,
315 avatar: AnyElement,
316 name: &str,
317 speaking: bool,
318 muted: bool,
319 caption: Option<AnyElement>,
320 extras: &TileExtras,
321) -> Div {
322 let badge = mute_badge();
323 v_flex()
324 .relative()
325 .w(px(size.width))
326 .h(px(size.height))
327 .items_center()
328 .justify_center()
329 .gap(px(12.))
330 .rounded(px(12.))
331 .bg(theme::row_hover())
332 .child(speaking_ring(avatar, speaking))
333 .child(
334 v_flex()
335 .items_center()
336 .gap(px(2.))
337 .max_w(px(size.width - 16.))
338 .child(
339 div()
340 .max_w_full()
341 .truncate()
342 .text_size(px(14.))
343 .font_weight(FontWeight::SEMIBOLD)
344 .child(name.to_owned()),
345 )
346 .children(caption),
347 )
348 .when(muted, |tile| tile.child(badge))
349 .children(tile_overlays(extras))
350}
351
352fn control_shell(id: &'static str, background: Hsla) -> Stateful<Div> {
353 div()
354 .id(id)
355 .size(px(CONTROL_SIZE))
356 .flex()
357 .flex_none()
358 .items_center()
359 .justify_center()
360 .rounded_full()
361 .bg(background)
362 .cursor_pointer()
363 .hover(|button| button.opacity(0.85))
364}
365
366pub(super) fn round_control(
367 id: &'static str,
368 glyph: IconName,
369 background: Hsla,
370 foreground: Hsla,
371) -> Stateful<Div> {
372 control_shell(id, background).child(icon(glyph, CONTROL_ICON, foreground))
373}
374
375pub fn mute_button(
376 app: &Entity<AppState>,
377 model: &CallModel,
378 id: &'static str,
379 size: f32,
380) -> Stateful<Div> {
381 let (glyph, background, foreground) = if model.muted {
382 (IconName::MicOff, theme::red(), theme::white())
383 } else {
384 (IconName::Mic, theme::surface_raised(), theme::text())
385 };
386 let button = round_control(id, glyph, background, foreground).size(px(size));
387 if !model.can_unmute() {
388 let hint = if model.audio_off {
389 AUDIO_OFF_HINT
390 } else {
391 NO_MICROPHONE_HINT
392 };
393 return button
394 .opacity(DISABLED_OPACITY)
395 .cursor_default()
396 .tooltip(move |window, cx| Tooltip::new(hint).build(window, cx));
397 }
398 let app = app.clone();
399 button.on_click(move |_, _, cx| {
400 cx.stop_propagation();
401 app.update(cx, |state, cx| state.toggle_call_mute(cx));
402 })
403}
404
405pub fn leave_button(
406 app: &Entity<AppState>,
407 model: &CallModel,
408 id: &'static str,
409 compact: bool,
410) -> Stateful<Div> {
411 let label = if model.is_connecting() {
412 "Cancel"
413 } else {
414 "Leave"
415 };
416 let app = app.clone();
417 h_flex()
418 .id(id)
419 .h(px(if compact { 28. } else { CONTROL_SIZE }))
420 .px(px(if compact { 10. } else { 20. }))
421 .gap(px(8.))
422 .flex_none()
423 .items_center()
424 .justify_center()
425 .rounded_full()
426 .bg(theme::red())
427 .text_color(theme::white())
428 .text_size(px(if compact { 12. } else { 14. }))
429 .font_weight(FontWeight::SEMIBOLD)
430 .cursor_pointer()
431 .hover(|button| button.opacity(0.85))
432 .child(icon(
433 IconName::PhoneOff,
434 if compact { 14. } else { 18. },
435 theme::white(),
436 ))
437 .child(label)
438 .on_click(move |_, _, cx| {
439 cx.stop_propagation();
440 app.update(cx, |state, cx| state.leave_call(cx));
441 })
442}
443
444fn share_stage_element(app: &Entity<AppState>, state: &AppState, call: &ActiveCall) -> Option<AnyElement> {
445 if call.share_stage.popped && call.model.screen_sharer.is_some() {
446 return Some(popped_placeholder(app));
447 }
448 render_stage(app, state, StageMode::Docked).or_else(|| whiteboard_stage(app, &call.model))
449}
450
451pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
452 let (glyph, background, foreground) = if model.camera_on {
453 (IconName::Video, theme::accent(), theme::on_accent())
454 } else {
455 (IconName::VideoOff, theme::surface_raised(), theme::text())
456 };
457 let button = round_control("call-camera", glyph, background, foreground);
458 if !model.can_use_camera() {
459 return button
460 .opacity(DISABLED_OPACITY)
461 .cursor_default()
462 .tooltip(|window, cx| Tooltip::new(NO_CAMERA_HINT).build(window, cx));
463 }
464 let app = app.clone();
465 button.on_click(move |_, _, cx| {
466 cx.stop_propagation();
467 app.update(cx, |state, cx| state.toggle_call_camera(cx));
468 })
469}
470
471fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
472 let app = app.clone();
473 PopupMenuItem::element(move |_, _| {
474 h_flex()
475 .id("call-share-sound-row")
476 .w_full()
477 .gap(px(16.))
478 .items_center()
479 .justify_between()
480 .child(SHARE_SOUND_LABEL)
481 .child(Switch::new("call-share-sound").checked(sound))
482 })
483 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
484}
485
486fn motion_switch_item(app: &Entity<AppState>, motion: bool) -> PopupMenuItem {
487 let app = app.clone();
488 PopupMenuItem::element(move |_, _| {
489 h_flex()
490 .id("call-share-motion-row")
491 .w_full()
492 .gap(px(16.))
493 .items_center()
494 .justify_between()
495 .child(SHARE_MOTION_LABEL)
496 .child(Switch::new("call-share-motion").checked(motion))
497 })
498 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_motion(!motion, cx)))
499}
500
501fn standout_switch_item(app: &Entity<AppState>, standout: bool, camera_on: bool) -> PopupMenuItem {
502 let app = app.clone();
503 PopupMenuItem::element(move |_, _| {
504 v_flex()
505 .id("call-share-standout-row")
506 .w_full()
507 .when(!camera_on, |row| row.opacity(DISABLED_OPACITY))
508 .child(
509 h_flex()
510 .w_full()
511 .gap(px(16.))
512 .items_center()
513 .justify_between()
514 .child(SHARE_STANDOUT_LABEL)
515 .child(Switch::new("call-share-standout").checked(standout && camera_on)),
516 )
517 .when(!camera_on, |row| {
518 row.child(
519 div()
520 .text_size(px(11.))
521 .text_color(theme::text_muted())
522 .child(SHARE_STANDOUT_NEEDS_CAMERA),
523 )
524 })
525 })
526 .disabled(!camera_on)
527 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_standout(!standout, cx)))
528}
529
530fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
531 let app = app.clone();
532 PopupMenuItem::element(move |_, _| {
533 h_flex()
534 .id("call-music-mode-row")
535 .w_full()
536 .gap(px(16.))
537 .items_center()
538 .justify_between()
539 .child(MUSIC_MODE_LABEL)
540 .child(Switch::new("call-music-mode").checked(mic.music_mode))
541 })
542 .on_click(move |_, _, cx| {
543 app.update(cx, |state, cx| {
544 let settings = MicSettings {
545 music_mode: !mic.music_mode,
546 ..state.call_mic
547 };
548 state.set_call_mic(settings, cx)
549 })
550 })
551}
552
553fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> {
554 call.push_to_talk.is_held().then(|| {
555 div()
556 .id("call-push-to-talk")
557 .absolute()
558 .top(px(HEADER_HEIGHT + PUSH_TO_TALK_TOP))
559 .left_0()
560 .right_0()
561 .flex()
562 .justify_center()
563 .child(
564 div()
565 .debug_selector(|| "call/push-to-talk".into())
566 .px(px(12.))
567 .py(px(6.))
568 .rounded_full()
569 .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
570 .text_color(theme::white())
571 .text_size(px(13.))
572 .child(PUSH_TO_TALK_HINT),
573 )
574 .into_any_element()
575 })
576}
577
578#[derive(Debug, Clone, Copy)]
579pub(super) struct ShareOptions {
580 pub sound: bool,
581 pub motion: bool,
582 pub standout: bool,
583}
584
585impl ShareOptions {
586 pub(super) fn of(state: &AppState) -> Self {
587 ShareOptions {
588 sound: state.call_share_sound,
589 motion: state.call_share_motion,
590 standout: state.call_share_standout,
591 }
592 }
593}
594
595fn share_items(
596 popup: PopupMenu,
597 app: &Entity<AppState>,
598 model: &CallModel,
599 options: ShareOptions,
600) -> PopupMenu {
601 let screens = model.screens();
602 let single_screen = screens.len() == 1;
603 let mut popup = popup
604 .min_w(px(SHARE_MENU_WIDTH))
605 .item(sound_switch_item(app, options.sound))
606 .item(motion_switch_item(app, options.motion))
607 .item(standout_switch_item(app, options.standout, model.camera_on))
608 .separator();
609 for (index, source) in screens.into_iter().enumerate() {
610 let label = if single_screen {
611 "Share entire screen".to_owned()
612 } else {
613 format!("Share screen {}", index + 1)
614 };
615 let thumbnail = model.share_thumbnail(source);
616 let source = source.clone();
617 let app = app.clone();
618 popup = popup.item(
619 share_source_item(label, thumbnail, IconName::Monitor, SCREEN_THUMBNAIL).on_click(
620 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
621 ),
622 );
623 }
624 popup = popup
625 .separator()
626 .item(PopupMenuItem::label("Share a window..."));
627 let windows = model.windows();
628 if windows.is_empty() {
629 return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true));
630 }
631 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
632 let label = source.label();
633 let thumbnail = model.share_thumbnail(source);
634 let source = source.clone();
635 let app = app.clone();
636 popup = popup.item(
637 share_source_item(label, thumbnail, IconName::AppWindow, WINDOW_THUMBNAIL).on_click(
638 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
639 ),
640 );
641 }
642 popup
643}
644
645fn share_source_item(
646 label: String,
647 thumbnail: Option<Arc<RenderImage>>,
648 fallback: IconName,
649 (width, height): (f32, f32),
650) -> PopupMenuItem {
651 PopupMenuItem::element(move |_, _| {
652 let preview = div()
653 .debug_selector(|| SHARE_THUMBNAIL_TAG.into())
654 .flex_none()
655 .w(px(width))
656 .h(px(height))
657 .rounded(px(THUMBNAIL_RADIUS))
658 .bg(theme::popup_hover())
659 .flex()
660 .items_center()
661 .justify_center();
662 let preview = match &thumbnail {
663 Some(image) => preview.child(
664 img(ImageSource::Render(image.clone()))
665 .size_full()
666 .object_fit(ObjectFit::Contain)
667 .rounded(px(THUMBNAIL_RADIUS)),
668 ),
669 None => preview.child(
670 gpui_kit::component::Icon::new(fallback.clone())
671 .size(px(THUMBNAIL_ICON))
672 .text_color(theme::text_muted()),
673 ),
674 };
675 h_flex()
676 .w_full()
677 .py(px(4.))
678 .gap(px(12.))
679 .items_center()
680 .child(preview)
681 .child(div().flex_1().min_w_0().truncate().child(label.clone()))
682 })
683}
684
685fn share_button(
686 app: &Entity<AppState>,
687 model: &CallModel,
688 options: ShareOptions,
689 menu_open: bool,
690) -> AnyElement {
691 if model.local_share.is_some() {
692 let app = app.clone();
693 return round_control(
694 "call-share-stop",
695 IconName::ScreenShareOff,
696 theme::accent(),
697 theme::on_accent(),
698 )
699 .tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))
700 .on_click(move |_, _, cx| {
701 cx.stop_propagation();
702 app.update(cx, |state, cx| state.stop_call_share(cx));
703 })
704 .into_any_element();
705 }
706 let face = round_control(
707 "call-share-face",
708 IconName::ScreenShare,
709 theme::surface_raised(),
710 theme::text(),
711 );
712 if !model.can_share() {
713 return face
714 .opacity(DISABLED_OPACITY)
715 .cursor_default()
716 .tooltip(|window, cx| Tooltip::new(NO_SHARE_HINT).build(window, cx))
717 .into_any_element();
718 }
719 let app = app.clone();
720 let open_app = app.clone();
721 let model = model.clone();
722 Button::new("call-share")
723 .ghost()
724 .p_0()
725 .size(px(CONTROL_SIZE))
726 .rounded_full()
727 .child(face)
728 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
729 share_items(popup, &app, &model, options)
730 })
731 .open(menu_open)
732 .on_open_change(move |open, _, cx| {
733 open_app.update(cx, |state, cx| state.set_call_share_menu(*open, cx))
734 })
735 .into_any_element()
736}
737
738fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Option<AnyElement> {
739 let label = model.local_share.as_ref()?;
740 let sound_app = app.clone();
741 let app = app.clone();
742 Some(
743 h_flex()
744 .id("call-sharing-banner")
745 .w_full()
746 .h(px(BANNER_HEIGHT))
747 .flex_none()
748 .px(px(20.))
749 .gap(px(12.))
750 .items_center()
751 .justify_center()
752 .bg(theme::accent())
753 .text_color(theme::on_accent())
754 .text_size(px(13.))
755 .font_weight(FontWeight::SEMIBOLD)
756 .child(icon(IconName::ScreenShare, 16., theme::on_accent()))
757 .child(format!("You are sharing: {label}"))
758 .child(
759 div()
760 .id("call-sharing-sound")
761 .h(px(26.))
762 .px(px(12.))
763 .flex()
764 .items_center()
765 .rounded_full()
766 .bg(theme::on_accent().opacity(0.2))
767 .cursor_pointer()
768 .hover(|button| button.opacity(0.9))
769 .child(if sound {
770 "Computer sound on"
771 } else {
772 "Computer sound off"
773 })
774 .on_click(move |_, _, cx| {
775 sound_app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx))
776 }),
777 )
778 .child(
779 div()
780 .id("call-sharing-stop")
781 .h(px(26.))
782 .px(px(12.))
783 .flex()
784 .items_center()
785 .rounded_full()
786 .bg(theme::on_accent())
787 .text_color(theme::accent())
788 .cursor_pointer()
789 .hover(|button| button.opacity(0.9))
790 .child("Stop sharing")
791 .on_click(move |_, _, cx| {
792 app.update(cx, |state, cx| state.stop_call_share(cx))
793 }),
794 )
795 .into_any_element(),
796 )
797}
798
799fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {
800 let app = app.clone();
801 let (background, foreground) = if open {
802 (theme::accent(), theme::on_accent())
803 } else {
804 (theme::surface_raised(), theme::text())
805 };
806 round_control("call-chat", IconName::MessageCircle, background, foreground)
807 .relative()
808 .tooltip(move |window, cx| {
809 Tooltip::new(if open {
810 "Close the chat"
811 } else {
812 "Open the chat"
813 })
814 .build(window, cx)
815 })
816 .when(unread > 0, |button| {
817 button.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
818 })
819 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))
820}
821
822fn hand_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
823 let raised = model.own_hand.is_some();
824 let background = if raised {
825 theme::accent()
826 } else {
827 theme::surface_raised()
828 };
829 let foreground = if raised {
830 theme::on_accent()
831 } else {
832 theme::text()
833 };
834 let button = control_shell("call-hand", background).child(icon(
835 IconName::Hand,
836 CONTROL_ICON,
837 foreground,
838 ));
839 let tooltip = if raised { "Lower hand" } else { "Raise hand" };
840 let button = button.tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx));
841 if !model.can_react() {
842 return button.opacity(DISABLED_OPACITY).cursor_default();
843 }
844 let app = app.clone();
845 button.on_click(move |_, _, cx| {
846 cx.stop_propagation();
847 app.update(cx, |state, cx| state.toggle_call_hand(cx));
848 })
849}
850
851fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
852 let face = control_shell("call-reactions-face", theme::surface_raised()).child(icon(
853 IconName::FaceSlightlySmiling,
854 CONTROL_ICON,
855 theme::text(),
856 ));
857 if !model.can_react() {
858 return face
859 .opacity(DISABLED_OPACITY)
860 .cursor_default()
861 .into_any_element();
862 }
863 let app = app.clone();
864 Popover::new("call-reactions-popover")
865 .anchor(Anchor::BottomLeft)
866 .offset(px(10.))
867 .trigger(
868 Button::new("call-reactions")
869 .ghost()
870 .p_0()
871 .size(px(CONTROL_SIZE))
872 .rounded_full()
873 .child(face),
874 )
875 .content(move |_, _, cx| {
876 let popover = cx.entity().downgrade();
877 h_flex()
878 .id("call-reactions-row")
879 .gap(px(4.))
880 .children(Reaction::ALL.into_iter().map(|reaction| {
881 let app = app.clone();
882 let popover = popover.clone();
883 div()
884 .id(ElementId::Name(reaction.name().to_owned().into()))
885 .size(px(REACTION_CELL))
886 .flex()
887 .items_center()
888 .justify_center()
889 .rounded(px(8.))
890 .text_size(px(24.))
891 .cursor_pointer()
892 .hover(|cell| cell.bg(theme::border_strong()))
893 .child(reaction_glyph(&reaction))
894 .on_click(move |_, window, cx| {
895 app.update(cx, |state, cx| state.send_call_reaction(reaction.clone(), cx));
896 popover
897 .update(cx, |state, cx| state.dismiss(window, cx))
898 .ok();
899 })
900 }))
901 })
902 .into_any_element()
903}
904
905fn has_leave_menu(model: &CallModel) -> bool {
906 model.kind == CallKind::Meeting
907 && (model.can_end_meeting || (model.can_lower_hands() && model.any_hand_raised()))
908}
909
910fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
911 let end_app = app.clone();
912 let can_end = model.can_end_meeting;
913 let lower_app = app.clone();
914 let can_lower_all = model.can_lower_hands() && model.any_hand_raised();
915 Button::new("call-leave-menu")
916 .ghost()
917 .p_0()
918 .size(px(CONTROL_SIZE))
919 .rounded_full()
920 .child(round_control(
921 "call-leave-menu-face",
922 IconName::ChevronUp,
923 theme::surface_raised(),
924 theme::text(),
925 ))
926 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
927 let end_app = end_app.clone();
928 let lower_app = lower_app.clone();
929 let popup = popup.min_w(px(MENU_WIDTH));
930 let popup = if can_lower_all {
931 popup.item(
932 PopupMenuItem::new("Lower all hands").on_click(move |_, _, cx| {
933 lower_app.update(cx, |state, cx| state.lower_all_call_hands(cx))
934 }),
935 )
936 } else {
937 popup
938 };
939 if can_end {
940 popup.item(
941 PopupMenuItem::new("End meeting for everyone")
942 .icon(IconName::PhoneOff)
943 .on_click(move |_, _, cx| {
944 end_app.update(cx, |state, cx| state.end_meeting_for_all(cx))
945 }),
946 )
947 } else {
948 popup
949 }
950 })
951}
952
953pub(super) fn device_items(
954 entries: Vec<DeviceEntry>,
955 selected: &calling::DeviceChoice,
956 pick: impl Fn(calling::DeviceChoice, &mut App) + Clone + 'static,
957) -> Vec<PopupMenuItem> {
958 entries
959 .into_iter()
960 .map(|entry| {
961 let pick = pick.clone();
962 let choice = entry.choice.clone();
963 PopupMenuItem::new(entry.label)
964 .checked(&entry.choice == selected)
965 .on_click(move |_, _, cx| pick(choice.clone(), cx))
966 })
967 .collect()
968}
969
970fn devices_menu(
971 popup: PopupMenu,
972 app: &Entity<AppState>,
973 model: &CallModel,
974 mic: MicSettings,
975) -> PopupMenu {
976 if model.audio_off {
977 return popup.item(PopupMenuItem::new(AUDIO_OFF_HINT).disabled(true));
978 }
979 let input_app = app.clone();
980 let output_app = app.clone();
981 let inputs = device_items(
982 model.devices.input_entries(),
983 &model.input,
984 move |choice, cx| {
985 input_app.update(cx, |state, cx| state.select_call_input(choice, cx));
986 },
987 );
988 let outputs = device_items(
989 model.devices.output_entries(),
990 &model.output,
991 move |choice, cx| {
992 output_app.update(cx, |state, cx| state.select_call_output(choice, cx));
993 },
994 );
995 let mut popup = popup
996 .min_w(px(MENU_WIDTH))
997 .item(PopupMenuItem::label("Microphone"));
998 if model.listen_only {
999 popup = popup.item(PopupMenuItem::new(NO_MICROPHONE_HINT).disabled(true));
1000 } else {
1001 for item in inputs {
1002 popup = popup.item(item);
1003 }
1004 }
1005 popup = popup
1006 .separator()
1007 .item(PopupMenuItem::label(NOISE_SUPPRESSION_LABEL));
1008 for level in NoiseSuppression::ALL {
1009 let level_app = app.clone();
1010 popup = popup.item(
1011 PopupMenuItem::new(level.label())
1012 .checked(level == mic.noise_suppression)
1013 .disabled(mic.music_mode)
1014 .on_click(move |_, _, cx| {
1015 level_app.update(cx, |state, cx| {
1016 let settings = MicSettings {
1017 noise_suppression: level,
1018 ..state.call_mic
1019 };
1020 state.set_call_mic(settings, cx)
1021 })
1022 }),
1023 );
1024 }
1025 popup = popup
1026 .item(music_mode_item(app, mic))
1027 .separator()
1028 .item(PopupMenuItem::label("Speaker"));
1029 for item in outputs {
1030 popup = popup.item(item);
1031 }
1032 popup
1033}
1034
1035fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {
1036 let app = app.clone();
1037 let model = model.clone();
1038 chevron_button("call-mic-menu", "call-mic-menu-face")
1039 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
1040 devices_menu(popup, &app, &model, mic)
1041 })
1042}
1043
1044pub(super) fn person_tile(
1045 app: &Entity<AppState>,
1046 state: &AppState,
1047 model: &CallModel,
1048 remote: &Tile,
1049 size: TileSize,
1050 now: Instant,
1051) -> AnyElement {
1052 let element = plain_person_tile(state, model, remote, size, now);
1053 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
1054}
1055
1056pub(super) fn plain_person_tile(
1057 state: &AppState,
1058 model: &CallModel,
1059 remote: &Tile,
1060 size: TileSize,
1061 now: Instant,
1062) -> AnyElement {
1063 let extras = TileExtras {
1064 hand: remote.hand.map(|rank| model.hand_position(rank)),
1065 own: false,
1066 reaction: model
1067 .chip_of(&remote.mri, now)
1068 .map(|chip| (chip.reaction.clone(), chip.serial)),
1069 spotlight: remote.spotlight.is_some(),
1070 pinned: model.is_pinned(&remote.mri),
1071 fitted: model.is_fitted(&remote.mri),
1072 };
1073 person_tile_body(state, model, remote, size, now, &extras)
1074}
1075
1076fn person_tile_body(
1077 state: &AppState,
1078 model: &CallModel,
1079 remote: &Tile,
1080 size: TileSize,
1081 now: Instant,
1082 extras: &TileExtras,
1083) -> AnyElement {
1084 let video = state
1085 .call
1086 .as_ref()
1087 .filter(|_| remote.has_video || model.is_one_to_one())
1088 .and_then(|call| {
1089 call.pictures
1090 .live(&VideoKey::Person(remote.mri.clone()), now)
1091 });
1092 if let Some(image) = video {
1093 return video_tile(
1094 size,
1095 image,
1096 &remote.name,
1097 model.tile_speaking(remote),
1098 remote.muted,
1099 extras,
1100 )
1101 .into_any_element();
1102 }
1103 let waiting = remote.state == TileState::Invited;
1104 let avatar = person_avatar(
1105 &state.directory,
1106 remote.user_id.as_deref(),
1107 &remote.name,
1108 size.avatar,
1109 );
1110 let caption = model.tile_caption(remote).map(|text| {
1111 let label = div()
1112 .text_size(px(12.))
1113 .text_color(theme::text_muted())
1114 .child(text);
1115 if waiting {
1116 blinking(label)
1117 } else {
1118 label.into_any_element()
1119 }
1120 });
1121 tile(
1122 size,
1123 avatar,
1124 &remote.name,
1125 model.tile_speaking(remote),
1126 remote.muted,
1127 caption,
1128 extras,
1129 )
1130 .into_any_element()
1131}
1132
1133pub(super) fn own_tile(
1134 app: &Entity<AppState>,
1135 state: &AppState,
1136 model: &CallModel,
1137 size: TileSize,
1138 now: Instant,
1139) -> AnyElement {
1140 let own_mri = model.own_mri.clone().unwrap_or_default();
1141 let element = plain_own_tile(state, model, size, now);
1142 if own_mri.is_empty() {
1143 return element;
1144 }
1145 with_tile_menu(app, model, &own_mri, "You", true, element)
1146}
1147
1148pub(super) fn plain_own_tile(
1149 state: &AppState,
1150 model: &CallModel,
1151 size: TileSize,
1152 now: Instant,
1153) -> AnyElement {
1154 let own_mri = model.own_mri.as_deref().unwrap_or_default();
1155 let extras = TileExtras {
1156 hand: model.own_hand.map(|rank| model.hand_position(rank)),
1157 own: true,
1158 reaction: model.own_chip(now).map(|chip| (chip.reaction.clone(), chip.serial)),
1159 spotlight: model.own_spotlight.is_some(),
1160 pinned: model.is_pinned(own_mri),
1161 fitted: false,
1162 };
1163 own_tile_body(state, model, size, now, &extras)
1164}
1165
1166fn own_tile_body(
1167 state: &AppState,
1168 model: &CallModel,
1169 size: TileSize,
1170 now: Instant,
1171 extras: &TileExtras,
1172) -> AnyElement {
1173 let me = state.directory.me.as_ref();
1174 let self_view = state
1175 .call
1176 .as_ref()
1177 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now));
1178 if let Some(image) = self_view {
1179 return video_tile(
1180 size,
1181 image,
1182 "You",
1183 model.local_speaking,
1184 model.muted,
1185 extras,
1186 )
1187 .into_any_element();
1188 }
1189 let avatar = person_avatar(
1190 &state.directory,
1191 me.map(|person| person.user_id.as_str()),
1192 me.map_or("You", |person| person.display_name.as_str()),
1193 size.avatar,
1194 );
1195 tile(
1196 size,
1197 avatar,
1198 "You",
1199 model.local_speaking,
1200 model.muted,
1201 None,
1202 extras,
1203 )
1204 .into_any_element()
1205}
1206
1207fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> FoldedControls {
1208 let model = &call.model;
1209 let has_more = model.kind != CallKind::Test;
1210 if !has_more {
1211 return FoldedControls::default();
1212 }
1213 let mut present = vec![Foldable::View];
1214 if model.has_reaction_controls() {
1215 present.extend([Foldable::Reactions, Foldable::RaiseHand]);
1216 }
1217 if model.kind != CallKind::Test {
1218 present.push(Foldable::People);
1219 }
1220 if call.chat_thread().is_some() {
1221 present.push(Foldable::Chat);
1222 }
1223 let fixed = fixed_controls_width(
1224 model.can_use_camera(),
1225 has_more,
1226 has_leave_menu(model),
1227 );
1228 FoldedControls {
1229 items: folded_for_width(measured_stage(call).0, fixed, &present),
1230 fullscreen,
1231 people_open: call.people_open,
1232 chat_open: call.chat_open,
1233 chat_unread: state.call_chat_unread(),
1234 }
1235}
1236
1237pub fn render_call_view(
1238 app: &Entity<AppState>,
1239 state: &AppState,
1240 chat: Option<AnyView>,
1241 fullscreen: bool,
1242 island_width: f32,
1243) -> Option<AnyElement> {
1244 let call = state.call.as_ref()?;
1245 let model = &call.model;
1246 let now = Instant::now();
1247 let (status, status_color) = status_line(model, now);
1248 let header = h_flex()
1249 .w_full()
1250 .h(px(HEADER_HEIGHT))
1251 .flex_none()
1252 .px(px(20.))
1253 .gap(px(12.))
1254 .items_center()
1255 .child(icon(IconName::Phone, 18., theme::accent_text()))
1256 .child(
1257 div()
1258 .min_w_0()
1259 .truncate()
1260 .text_size(px(16.))
1261 .font_weight(FontWeight::SEMIBOLD)
1262 .child(model.title.clone()),
1263 )
1264 .child(
1265 div()
1266 .flex_none()
1267 .text_size(px(13.))
1268 .text_color(status_color)
1269 .child(status),
1270 )
1271 .children(health_indicator(model))
1272 .children(recording_chip(model))
1273 .children(lock_chip(model))
1274 .children(room_chip(model))
1275 .child(div().flex_1())
1276 .children(return_button(app, model));
1277
1278 let hold = hold_panel(app, model);
1279 let share_stage = share_stage_element(app, state, call);
1280 let region = stage_region(app, state, call, now, hold, share_stage);
1281
1282 let folded = folded_controls(state, call, fullscreen);
1283 let controls = h_flex()
1284 .w_full()
1285 .flex_none()
1286 .py(px(16.))
1287 .px(px(CONTROLS_PADDING))
1288 .gap(px(CONTROL_GAP))
1289 .items_center()
1290 .justify_center()
1291 .child(
1292 h_flex()
1293 .debug_selector(|| "shell/islands/main/call-controls/mic".into())
1294 .h(px(CONTROL_SIZE))
1295 .items_center()
1296 .rounded_full()
1297 .bg(theme::surface_raised())
1298 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1299 .child(mic_menu_button(app, model, state.call_mic)),
1300 )
1301 .child(
1302 h_flex()
1303 .h(px(CONTROL_SIZE))
1304 .items_center()
1305 .rounded_full()
1306 .bg(theme::surface_raised())
1307 .child(camera_button(app, model))
1308 .children(camera_menu_button(app, model, CameraMenu::of(state))),
1309 )
1310 .child(share_button(
1311 app,
1312 model,
1313 ShareOptions::of(state),
1314 call.share_menu_open,
1315 ))
1316 .when(
1317 model.has_reaction_controls() && !folded.folds(Foldable::RaiseHand),
1318 |row| row.child(hand_button(app, model)),
1319 )
1320 .when(
1321 model.has_reaction_controls() && !folded.folds(Foldable::Reactions),
1322 |row| row.child(reactions_button(app, model)),
1323 )
1324 .when(!folded.folds(Foldable::View), |row| {
1325 row.child(view_button(app, model, fullscreen))
1326 })
1327 .children(more_button(app, model, &folded))
1328 .when(
1329 model.kind != CallKind::Test && !folded.folds(Foldable::People),
1330 |row| row.child(people_button(app, call.people_open, model.raised_hands())),
1331 )
1332 .when(
1333 call.chat_thread().is_some() && !folded.folds(Foldable::Chat),
1334 |row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())),
1335 )
1336 .child(
1337 leave_button(app, model, "call-leave", false)
1338 .debug_selector(|| "shell/islands/main/call-controls/leave".into()),
1339 )
1340 .when(has_leave_menu(model), |row| row.child(leave_menu(app, model)));
1341
1342 let top = v_flex()
1343 .w_full()
1344 .flex_none()
1345 .child(header)
1346 .children(lobby_banner(app, model, call.lobby_list_open))
1347 .children(lock_banner(app, model))
1348 .children(health_banner(app, model))
1349 .children(sharing_banner(app, model, state.call_share_sound))
1350 .children(consult_banner(app, state));
1351
1352 let chrome_visible = call
1353 .fullscreen
1354 .is_none_or(|fullscreen| fullscreen.chrome_visible(now));
1355 let move_app = app.clone();
1356 let base = v_flex()
1357 .relative()
1358 .flex_1()
1359 .min_w_0()
1360 .h_full()
1361 .overflow_hidden()
1362 .bg(theme::surface());
1363 let column = if fullscreen {
1364 base.on_mouse_move(move |_, _, cx| {
1365 move_app.update(cx, |state, cx| state.touch_call_chrome(cx))
1366 })
1367 .when(chrome_visible, |column| {
1368 column.child(fullscreen_chrome("call-chrome-top", app, top))
1369 })
1370 .child(region)
1371 .when(chrome_visible, |column| {
1372 column.child(fullscreen_chrome("call-chrome-bottom", app, controls))
1373 })
1374 } else {
1375 base.rounded(px(10.))
1376 .child(top.debug_selector(|| "shell/islands/main/call-header".into()))
1377 .child(region)
1378 .child(controls.debug_selector(|| "shell/islands/main/call-controls".into()))
1379 }
1380 .children(captions_overlay(model, now))
1381 .children(captions_hint_chip(model))
1382 .children(push_to_talk_chip(call))
1383 .children(state.transfer_picker.clone())
1384 .children(options_dialog(app, call))
1385 .children(consent_overlay(app, model));
1386 let panels: Vec<AnyElement> = chat
1387 .map(|chat| chat_panel(app, chat))
1388 .into_iter()
1389 .chain(
1390 call.transcript_open
1391 .then(|| state.transcript_panel.clone())
1392 .flatten()
1393 .map(IntoElement::into_any_element),
1394 )
1395 .chain(people_panel(app, state, call))
1396 .collect();
1397 Some(
1398 h_flex()
1399 .relative()
1400 .when(!fullscreen, |row| {
1401 row.debug_selector(|| "shell/islands/main".into())
1402 })
1403 .flex_1()
1404 .min_w_0()
1405 .h_full()
1406 .gap(px(ISLAND_GAP))
1407 .child(column)
1408 .children(side_panels(panels, island_width))
1409 .into_any_element(),
1410 )
1411}
1412
1413fn side_panels(panels: Vec<AnyElement>, island_width: f32) -> Vec<AnyElement> {
1414 if panels.is_empty() {
1415 return panels;
1416 }
1417 let panels_width = (CHAT_PANEL_WIDTH + ISLAND_GAP) * panels.len() as f32;
1418 if island_width - panels_width >= OVERLAY_BELOW {
1419 return panels;
1420 }
1421 vec![
1422 h_flex()
1423 .absolute()
1424 .top_0()
1425 .right_0()
1426 .bottom(px(CONTROLS_HEIGHT))
1427 .gap(px(ISLAND_GAP))
1428 .w(px(panels_width.min(island_width)))
1429 .children(panels)
1430 .into_any_element(),
1431 ]
1432}
1433
1434fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {
1435 let hover_app = app.clone();
1436 div()
1437 .id(id)
1438 .w_full()
1439 .flex_none()
1440 .on_hover(move |hovered, _, cx| {
1441 hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx))
1442 })
1443 .child(content)
1444}
1445
1446fn chat_panel(app: &Entity<AppState>, chat: AnyView) -> AnyElement {
1447 let app = app.clone();
1448 side_panel(
1449 "call-chat-panel",
1450 "Chat",
1451 "Close the chat",
1452 move |cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)),
1453 chat,
1454 )
1455 .debug_selector(|| CHAT_PANEL_TAG.into())
1456 .into_any_element()
1457}
1458
1459pub fn side_panel(
1460 panel_id: &'static str,
1461 title: &'static str,
1462 close_tooltip: &'static str,
1463 on_close: impl Fn(&mut App) + 'static,
1464 body: impl IntoElement,
1465) -> Stateful<Div> {
1466 v_flex()
1467 .id(panel_id)
1468 .w(px(CHAT_PANEL_WIDTH))
1469 .h_full()
1470 .flex_shrink(1.)
1471 .min_w_0()
1472 .rounded(px(10.))
1473 .overflow_hidden()
1474 .bg(theme::surface())
1475 .child(
1476 h_flex()
1477 .w_full()
1478 .h(px(CHAT_HEADER_HEIGHT))
1479 .flex_none()
1480 .pl(px(20.))
1481 .pr(px(12.))
1482 .items_center()
1483 .justify_between()
1484 .child(
1485 div()
1486 .text_size(px(15.))
1487 .font_weight(FontWeight::SEMIBOLD)
1488 .child(title),
1489 )
1490 .child(
1491 div()
1492 .id(ElementId::Name(format!("{panel_id}-close").into()))
1493 .size(px(28.))
1494 .flex()
1495 .items_center()
1496 .justify_center()
1497 .rounded(px(7.))
1498 .cursor_pointer()
1499 .hover(|button| button.bg(theme::row_hover()))
1500 .tooltip(move |window, cx| Tooltip::new(close_tooltip).build(window, cx))
1501 .child(icon(IconName::Close, 14., theme::text_muted()))
1502 .on_click(move |_, _, cx| on_close(cx)),
1503 ),
1504 )
1505 .child(body)
1506}
1507
1508#[cfg(test)]
1509mod tests {
1510 use super::{TileSize, name_plate_metrics};
1511
1512 #[test]
1513 fn small_strip_tiles_get_a_compact_name_plate() {
1514 let strip = name_plate_metrics(TileSize { width: 216., height: 121.5, avatar: 48. });
1515 assert_eq!((strip.text_size, strip.inset, strip.padding_y), (11., 4., 2.));
1516 assert!(strip.max_width_share < 1.);
1517 let stage = name_plate_metrics(TileSize { width: 640., height: 360., avatar: 96. });
1518 assert_eq!((stage.text_size, stage.inset), (12., 8.));
1519 }
1520}