BlueGit

ict rusty-teams

Files

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

call_view.rs

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