BlueGit

ict rusty-teams

Files

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

call_view.rs

9ee83b18 History
call_view.rs 49.3 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::{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 screens = model.screens();
628 let single_screen = screens.len() == 1;
629 let mut popup = popup
630 .min_w(px(SHARE_MENU_WIDTH))
631 .item(sound_switch_item(app, options.sound))
632 .item(motion_switch_item(app, options.motion))
633 .item(standout_switch_item(app, options.standout, model.camera_on))
634 .separator();
635 for (index, source) in screens.into_iter().enumerate() {
636 let label = if single_screen {
637 "Share entire screen".to_owned()
638 } else {
639 format!("Share screen {}", index + 1)
640 };
641 let thumbnail = model.share_thumbnail(source);
642 let source = source.clone();
643 let app = app.clone();
644 popup = popup.item(
645 share_source_item(label, thumbnail, IconName::Monitor, SCREEN_THUMBNAIL).on_click(
646 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
647 ),
648 );
649 }
650 popup = popup
651 .separator()
652 .item(PopupMenuItem::label("Share a window..."));
653 let windows = model.windows();
654 if windows.is_empty() {
655 return popup.item(PopupMenuItem::new(NO_WINDOWS_HINT).disabled(true));
656 }
657 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
658 let label = source.label();
659 let thumbnail = model.share_thumbnail(source);
660 let source = source.clone();
661 let app = app.clone();
662 popup = popup.item(
663 share_source_item(label, thumbnail, IconName::AppWindow, WINDOW_THUMBNAIL).on_click(
664 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
665 ),
666 );
667 }
668 popup
669}
670
671fn share_source_item(
672 label: String,
673 thumbnail: Option<Arc<RenderImage>>,
674 fallback: IconName,
675 (width, height): (f32, f32),
676) -> PopupMenuItem {
677 PopupMenuItem::element(move |_, _| {
678 let preview = div()
679 .debug_selector(|| SHARE_THUMBNAIL_TAG.into())
680 .flex_none()
681 .w(px(width))
682 .h(px(height))
683 .rounded(px(THUMBNAIL_RADIUS))
684 .bg(theme::popup_hover())
685 .flex()
686 .items_center()
687 .justify_center();
688 let preview = match &thumbnail {
689 Some(image) => preview.child(
690 img(ImageSource::Render(image.clone()))
691 .size_full()
692 .object_fit(ObjectFit::Contain)
693 .rounded(px(THUMBNAIL_RADIUS)),
694 ),
695 None => preview.child(
696 gpui_kit::component::Icon::new(fallback.clone())
697 .size(px(THUMBNAIL_ICON))
698 .text_color(theme::text_muted()),
699 ),
700 };
701 h_flex()
702 .w_full()
703 .py(px(4.))
704 .gap(px(12.))
705 .items_center()
706 .child(preview)
707 .child(div().flex_1().min_w_0().truncate().child(label.clone()))
708 })
709}
710
711fn share_button(
712 app: &Entity<AppState>,
713 model: &CallModel,
714 options: ShareOptions,
715 menu_open: bool,
716) -> AnyElement {
717 if model.local_share.is_some() {
718 let app = app.clone();
719 return tool_face("call-share-stop", IconName::ScreenShareOff, "Stop", true)
720 .tooltip(|window, cx| Tooltip::new("Stop sharing").build(window, cx))
721 .on_click(move |_, _, cx| {
722 cx.stop_propagation();
723 app.update(cx, |state, cx| state.stop_call_share(cx));
724 })
725 .into_any_element();
726 }
727 let face = tool_face("call-share-face", IconName::ScreenShare, "Share", false);
728 if !model.can_share() {
729 return face
730 .opacity(DISABLED_OPACITY)
731 .cursor_default()
732 .tooltip(|window, cx| Tooltip::new(NO_SHARE_HINT).build(window, cx))
733 .into_any_element();
734 }
735 let app = app.clone();
736 let open_app = app.clone();
737 let model = model.clone();
738 tool_trigger("call-share", face)
739 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
740 share_items(popup, &app, &model, options)
741 })
742 .open(menu_open)
743 .on_open_change(move |open, _, cx| {
744 open_app.update(cx, |state, cx| state.set_call_share_menu(*open, cx))
745 })
746 .into_any_element()
747}
748
749fn sharing_banner(app: &Entity<AppState>, model: &CallModel, sound: bool) -> Option<AnyElement> {
750 let label = model.local_share.as_ref()?;
751 let sound_app = app.clone();
752 let app = app.clone();
753 Some(
754 h_flex()
755 .id("call-sharing-banner")
756 .w_full()
757 .h(px(BANNER_HEIGHT))
758 .flex_none()
759 .px(px(20.))
760 .gap(px(12.))
761 .items_center()
762 .justify_center()
763 .bg(theme::accent())
764 .text_color(theme::on_accent())
765 .text_size(px(13.))
766 .font_weight(FontWeight::SEMIBOLD)
767 .child(icon(IconName::ScreenShare, 16., theme::on_accent()))
768 .child(format!("You are sharing: {label}"))
769 .child(
770 div()
771 .id("call-sharing-sound")
772 .h(px(26.))
773 .px(px(12.))
774 .flex()
775 .items_center()
776 .rounded_full()
777 .bg(theme::on_accent().opacity(0.2))
778 .cursor_pointer()
779 .hover(|button| button.opacity(0.9))
780 .child(if sound {
781 "Computer sound on"
782 } else {
783 "Computer sound off"
784 })
785 .on_click(move |_, _, cx| {
786 sound_app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx))
787 }),
788 )
789 .child(
790 div()
791 .id("call-sharing-stop")
792 .h(px(26.))
793 .px(px(12.))
794 .flex()
795 .items_center()
796 .rounded_full()
797 .bg(theme::on_accent())
798 .text_color(theme::accent())
799 .cursor_pointer()
800 .hover(|button| button.opacity(0.9))
801 .child("Stop sharing")
802 .on_click(move |_, _, cx| {
803 app.update(cx, |state, cx| state.stop_call_share(cx))
804 }),
805 )
806 .into_any_element(),
807 )
808}
809
810fn chat_button(app: &Entity<AppState>, open: bool, unread: u32) -> Stateful<Div> {
811 let app = app.clone();
812 tool_face("call-chat", IconName::MessageCircle, "Chat", open)
813 .relative()
814 .tooltip(move |window, cx| {
815 Tooltip::new(if open {
816 "Close the chat"
817 } else {
818 "Open the chat"
819 })
820 .build(window, cx)
821 })
822 .when(unread > 0, |button| {
823 button.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
824 })
825 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)))
826}
827
828fn reactions_button(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
829 let raised = model.own_hand.is_some();
830 let face = tool_face("call-reactions-face", IconName::FaceSlightlySmiling, "React", raised);
831 if !model.can_react() {
832 return face
833 .opacity(DISABLED_OPACITY)
834 .cursor_default()
835 .into_any_element();
836 }
837 let app = app.clone();
838 Popover::new("call-reactions-popover")
839 .anchor(Anchor::TopRight)
840 .offset(px(6.))
841 .trigger(tool_trigger("call-reactions", face))
842 .content(move |_, _, cx| {
843 let popover = cx.entity().downgrade();
844 let hand_app = app.clone();
845 let hand_popover = popover.clone();
846 let reactions = h_flex()
847 .id("call-reactions-row")
848 .gap(px(4.))
849 .children(Reaction::ALL.into_iter().map(|reaction| {
850 let app = app.clone();
851 let popover = popover.clone();
852 div()
853 .id(ElementId::Name(reaction.name().to_owned().into()))
854 .size(px(REACTION_CELL))
855 .flex()
856 .items_center()
857 .justify_center()
858 .rounded(px(8.))
859 .text_size(px(24.))
860 .cursor_pointer()
861 .hover(|cell| cell.bg(theme::border_strong()))
862 .child(reaction_glyph(&reaction))
863 .on_click(move |_, window, cx| {
864 app.update(cx, |state, cx| state.send_call_reaction(reaction.clone(), cx));
865 popover
866 .update(cx, |state, cx| state.dismiss(window, cx))
867 .ok();
868 })
869 }));
870 v_flex()
871 .gap(px(6.))
872 .child(reactions)
873 .child(
874 h_flex()
875 .id("call-hand")
876 .h(px(36.))
877 .px(px(10.))
878 .gap(px(8.))
879 .items_center()
880 .rounded(px(8.))
881 .cursor_pointer()
882 .when(raised, |row| row.bg(theme::accent_soft()))
883 .hover(|row| row.bg(theme::border_strong()))
884 .child(icon(IconName::Hand, 18., if raised { theme::accent_text() } else { theme::text() }))
885 .child(div().text_size(px(13.)).child(if raised { "Lower hand" } else { "Raise hand" }))
886 .on_click(move |_, window, cx| {
887 hand_app.update(cx, |state, cx| state.toggle_call_hand(cx));
888 hand_popover
889 .update(cx, |state, cx| state.dismiss(window, cx))
890 .ok();
891 }),
892 )
893 })
894 .into_any_element()
895}
896
897fn pop_out_tool(app: &Entity<AppState>) -> Stateful<Div> {
898 let app = app.clone();
899 tool_face("call-pop-out", IconName::ExternalLink, POP_OUT_TOOLTIP, false)
900 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.pop_out_stage(cx)))
901}
902
903fn shows_pop_out(call: &ActiveCall) -> bool {
904 call.model.screen_sharer.is_some() && !call.share_stage.popped
905}
906
907fn leave_group(app: &Entity<AppState>, model: &CallModel) -> AnyElement {
908 let leave = leave_button(app, model, "call-leave", false)
909 .rounded(px(LEAVE_RADIUS))
910 .debug_selector(|| "shell/islands/main/call-header/leave".into());
911 if !has_leave_menu(model) {
912 return leave.into_any_element();
913 }
914 h_flex()
915 .flex_none()
916 .gap(px(1.))
917 .child(leave.rounded_r(px(0.)))
918 .child(leave_menu(app, model))
919 .into_any_element()
920}
921
922fn has_leave_menu(model: &CallModel) -> bool {
923 model.kind == CallKind::Meeting
924 && (model.can_end_meeting || (model.can_lower_hands() && model.any_hand_raised()))
925}
926
927fn leave_menu(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
928 let end_app = app.clone();
929 let can_end = model.can_end_meeting;
930 let lower_app = app.clone();
931 let can_lower_all = model.can_lower_hands() && model.any_hand_raised();
932 Button::new("call-leave-menu")
933 .ghost()
934 .p_0()
935 .w(px(SPLIT_CHEVRON_WIDTH + 4.))
936 .h(px(LEAVE_HEIGHT))
937 .rounded_r(px(LEAVE_RADIUS))
938 .child(
939 div()
940 .id("call-leave-menu-face")
941 .size_full()
942 .flex()
943 .items_center()
944 .justify_center()
945 .rounded_r(px(LEAVE_RADIUS))
946 .bg(theme::red())
947 .cursor_pointer()
948 .hover(|face| face.opacity(0.85))
949 .child(icon(IconName::ChevronDown, 12., theme::white())),
950 )
951 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
952 let end_app = end_app.clone();
953 let lower_app = lower_app.clone();
954 let popup = popup.min_w(px(MENU_WIDTH));
955 let popup = if can_lower_all {
956 popup.item(
957 PopupMenuItem::new("Lower all hands").on_click(move |_, _, cx| {
958 lower_app.update(cx, |state, cx| state.lower_all_call_hands(cx))
959 }),
960 )
961 } else {
962 popup
963 };
964 if can_end {
965 popup.item(
966 PopupMenuItem::new("End meeting for everyone")
967 .icon(IconName::PhoneOff)
968 .on_click(move |_, _, cx| {
969 end_app.update(cx, |state, cx| state.end_meeting_for_all(cx))
970 }),
971 )
972 } else {
973 popup
974 }
975 })
976}
977
978pub(super) fn device_items(
979 entries: Vec<DeviceEntry>,
980 selected: &calling::DeviceChoice,
981 pick: impl Fn(calling::DeviceChoice, &mut App) + Clone + 'static,
982) -> Vec<PopupMenuItem> {
983 entries
984 .into_iter()
985 .map(|entry| {
986 let pick = pick.clone();
987 let choice = entry.choice.clone();
988 PopupMenuItem::new(entry.label)
989 .checked(&entry.choice == selected)
990 .on_click(move |_, _, cx| pick(choice.clone(), cx))
991 })
992 .collect()
993}
994
995fn devices_menu(
996 popup: PopupMenu,
997 app: &Entity<AppState>,
998 model: &CallModel,
999 mic: MicSettings,
1000) -> PopupMenu {
1001 if model.audio_off {
1002 return popup.item(PopupMenuItem::new(AUDIO_OFF_HINT).disabled(true));
1003 }
1004 let input_app = app.clone();
1005 let output_app = app.clone();
1006 let inputs = device_items(
1007 model.devices.input_entries(),
1008 &model.input,
1009 move |choice, cx| {
1010 input_app.update(cx, |state, cx| state.select_call_input(choice, cx));
1011 },
1012 );
1013 let outputs = device_items(
1014 model.devices.output_entries(),
1015 &model.output,
1016 move |choice, cx| {
1017 output_app.update(cx, |state, cx| state.select_call_output(choice, cx));
1018 },
1019 );
1020 let mut popup = popup
1021 .min_w(px(MENU_WIDTH))
1022 .item(PopupMenuItem::label("Microphone"));
1023 if model.listen_only {
1024 popup = popup.item(PopupMenuItem::new(NO_MICROPHONE_HINT).disabled(true));
1025 } else {
1026 for item in inputs {
1027 popup = popup.item(item);
1028 }
1029 }
1030 popup = popup
1031 .separator()
1032 .item(PopupMenuItem::label(NOISE_SUPPRESSION_LABEL));
1033 for level in NoiseSuppression::ALL {
1034 let level_app = app.clone();
1035 popup = popup.item(
1036 PopupMenuItem::new(level.label())
1037 .checked(level == mic.noise_suppression)
1038 .disabled(mic.music_mode)
1039 .on_click(move |_, _, cx| {
1040 level_app.update(cx, |state, cx| {
1041 let settings = MicSettings {
1042 noise_suppression: level,
1043 ..state.call_mic
1044 };
1045 state.set_call_mic(settings, cx)
1046 })
1047 }),
1048 );
1049 }
1050 popup = popup
1051 .item(music_mode_item(app, mic))
1052 .separator()
1053 .item(PopupMenuItem::label("Speaker"));
1054 for item in outputs {
1055 popup = popup.item(item);
1056 }
1057 popup
1058}
1059
1060fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {
1061 let app = app.clone();
1062 let model = model.clone();
1063 split_chevron("call-mic-menu", "call-mic-menu-face")
1064 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
1065 devices_menu(popup, &app, &model, mic)
1066 })
1067}
1068
1069pub(super) fn person_tile(
1070 app: &Entity<AppState>,
1071 state: &AppState,
1072 model: &CallModel,
1073 remote: &Tile,
1074 size: TileSize,
1075 now: Instant,
1076) -> AnyElement {
1077 let element = plain_person_tile(state, model, remote, size, now);
1078 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
1079}
1080
1081pub(super) fn plain_person_tile(
1082 state: &AppState,
1083 model: &CallModel,
1084 remote: &Tile,
1085 size: TileSize,
1086 now: Instant,
1087) -> AnyElement {
1088 let extras = TileExtras {
1089 hand: remote.hand.map(|rank| model.hand_position(rank)),
1090 own: false,
1091 reaction: model
1092 .chip_of(&remote.mri, now)
1093 .map(|chip| (chip.reaction.clone(), chip.serial)),
1094 spotlight: remote.spotlight.is_some(),
1095 pinned: model.is_pinned(&remote.mri),
1096 fitted: model.is_fitted(&remote.mri),
1097 };
1098 person_tile_body(state, model, remote, size, now, &extras)
1099}
1100
1101fn person_tile_body(
1102 state: &AppState,
1103 model: &CallModel,
1104 remote: &Tile,
1105 size: TileSize,
1106 now: Instant,
1107 extras: &TileExtras,
1108) -> AnyElement {
1109 let video = state
1110 .call
1111 .as_ref()
1112 .filter(|_| remote.has_video || model.is_one_to_one())
1113 .and_then(|call| {
1114 call.pictures
1115 .live(&VideoKey::Person(remote.mri.clone()), now)
1116 });
1117 if let Some(image) = video {
1118 return video_tile(
1119 size,
1120 image,
1121 &remote.name,
1122 model.tile_speaking(remote),
1123 remote.muted,
1124 extras,
1125 )
1126 .into_any_element();
1127 }
1128 let waiting = remote.state == TileState::Invited;
1129 let avatar = person_avatar(
1130 &state.directory,
1131 remote.user_id.as_deref(),
1132 &remote.name,
1133 size.avatar,
1134 );
1135 let caption = model.tile_caption(remote).map(|text| {
1136 let label = div()
1137 .text_size(px(12.))
1138 .text_color(theme::text_muted())
1139 .child(text);
1140 if waiting {
1141 blinking(label)
1142 } else {
1143 label.into_any_element()
1144 }
1145 });
1146 tile(
1147 size,
1148 avatar,
1149 &remote.name,
1150 model.tile_speaking(remote),
1151 remote.muted,
1152 caption,
1153 extras,
1154 )
1155 .into_any_element()
1156}
1157
1158pub(super) fn own_tile(
1159 app: &Entity<AppState>,
1160 state: &AppState,
1161 model: &CallModel,
1162 size: TileSize,
1163 now: Instant,
1164) -> AnyElement {
1165 let own_mri = model.own_mri.clone().unwrap_or_default();
1166 let element = plain_own_tile(state, model, size, now);
1167 if own_mri.is_empty() {
1168 return element;
1169 }
1170 with_tile_menu(app, model, &own_mri, "You", true, element)
1171}
1172
1173pub(super) fn plain_own_tile(
1174 state: &AppState,
1175 model: &CallModel,
1176 size: TileSize,
1177 now: Instant,
1178) -> AnyElement {
1179 let own_mri = model.own_mri.as_deref().unwrap_or_default();
1180 let extras = TileExtras {
1181 hand: model.own_hand.map(|rank| model.hand_position(rank)),
1182 own: true,
1183 reaction: model.own_chip(now).map(|chip| (chip.reaction.clone(), chip.serial)),
1184 spotlight: model.own_spotlight.is_some(),
1185 pinned: model.is_pinned(own_mri),
1186 fitted: false,
1187 };
1188 own_tile_body(state, model, size, now, &extras)
1189}
1190
1191fn own_tile_body(
1192 state: &AppState,
1193 model: &CallModel,
1194 size: TileSize,
1195 now: Instant,
1196 extras: &TileExtras,
1197) -> AnyElement {
1198 let me = state.directory.me.as_ref();
1199 let self_view = state
1200 .call
1201 .as_ref()
1202 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now));
1203 if let Some(image) = self_view {
1204 return video_tile(
1205 size,
1206 image,
1207 "You",
1208 model.local_speaking,
1209 model.muted,
1210 extras,
1211 )
1212 .into_any_element();
1213 }
1214 let avatar = person_avatar(
1215 &state.directory,
1216 me.map(|person| person.user_id.as_str()),
1217 me.map_or("You", |person| person.display_name.as_str()),
1218 size.avatar,
1219 );
1220 tile(
1221 size,
1222 avatar,
1223 "You",
1224 model.local_speaking,
1225 model.muted,
1226 None,
1227 extras,
1228 )
1229 .into_any_element()
1230}
1231
1232fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> FoldedControls {
1233 let model = &call.model;
1234 let has_more = model.kind != CallKind::Test;
1235 if !has_more {
1236 return FoldedControls::default();
1237 }
1238 let mut present = Vec::new();
1239 if model.has_reaction_controls() {
1240 present.push(Foldable::Reactions);
1241 }
1242 if model.kind != CallKind::Test {
1243 present.push(Foldable::People);
1244 }
1245 if call.chat_thread().is_some() {
1246 present.push(Foldable::Chat);
1247 }
1248 let fixed = fixed_controls_width(
1249 model.can_use_camera(),
1250 has_more,
1251 has_leave_menu(model),
1252 shows_pop_out(call),
1253 );
1254 FoldedControls {
1255 items: in_more_menu(folded_for_width(measured_stage(call).0, fixed, &present)),
1256 fullscreen,
1257 people_open: call.people_open,
1258 chat_open: call.chat_open,
1259 chat_unread: state.call_chat_unread(),
1260 }
1261}
1262
1263pub fn render_call_view(
1264 app: &Entity<AppState>,
1265 state: &AppState,
1266 chat: Option<AnyView>,
1267 fullscreen: bool,
1268 island_width: f32,
1269) -> Option<AnyElement> {
1270 let call = state.call.as_ref()?;
1271 let model = &call.model;
1272 let now = Instant::now();
1273 let (status, status_color) = status_line(model, now);
1274 let header = h_flex()
1275 .w_full()
1276 .h(px(HEADER_HEIGHT))
1277 .flex_none()
1278 .pl(px(20.))
1279 .pr(px(HEADER_END_PADDING))
1280 .gap(px(12.))
1281 .items_center();
1282 let title_group = h_flex()
1283 .flex_1()
1284 .flex_basis(px(0.))
1285 .min_w_0()
1286 .gap(px(12.))
1287 .items_center()
1288 .child(icon(IconName::Phone, 18., theme::accent_text()))
1289 .child(
1290 div()
1291 .min_w_0()
1292 .truncate()
1293 .text_size(px(16.))
1294 .font_weight(FontWeight::SEMIBOLD)
1295 .child(model.title.clone()),
1296 )
1297 .child(
1298 div()
1299 .flex_none()
1300 .text_size(px(13.))
1301 .text_color(status_color)
1302 .child(status),
1303 )
1304 .children(health_indicator(model))
1305 .children(recording_chip(model))
1306 .children(lock_chip(model))
1307 .children(room_chip(model));
1308 let end_group = h_flex()
1309 .flex_1()
1310 .flex_basis(px(0.))
1311 .min_w_0()
1312 .justify_end()
1313 .gap(px(GROUP_GAP))
1314 .items_center()
1315 .children(return_button(app, model))
1316 .child(leave_group(app, model));
1317
1318 let hold = hold_panel(app, model);
1319 let share_stage = share_stage_element(app, state, call);
1320 let region = stage_region(app, state, call, now, hold, share_stage);
1321
1322 let folded = folded_controls(state, call, fullscreen);
1323 let panels_and_reactions = h_flex()
1324 .gap(px(TOOL_GAP))
1325 .items_center()
1326 .when(
1327 model.has_reaction_controls() && !folded.folds(Foldable::Reactions),
1328 |row| row.child(reactions_button(app, model)),
1329 )
1330 .when(
1331 call.chat_thread().is_some() && !folded.folds(Foldable::Chat),
1332 |row| row.child(chat_button(app, call.chat_open, state.call_chat_unread())),
1333 )
1334 .when(
1335 model.kind != CallKind::Test && !folded.folds(Foldable::People),
1336 |row| row.child(people_button(app, call.people_open, model.raised_hands())),
1337 );
1338 let stage_and_more = h_flex()
1339 .gap(px(TOOL_GAP))
1340 .items_center()
1341 .when(shows_pop_out(call), |row| row.child(pop_out_tool(app)))
1342 .when(!folded.folds(Foldable::View), |row| {
1343 row.child(view_button(app, model, fullscreen))
1344 })
1345 .children(more_button(app, model, &folded));
1346 let devices = h_flex()
1347 .gap(px(TOOL_GAP))
1348 .items_center()
1349 .child(
1350 h_flex()
1351 .debug_selector(|| "shell/islands/main/call-header/controls/mic".into())
1352 .items_center()
1353 .child(toolbar_mic(app, model))
1354 .child(mic_menu_button(app, model, state.call_mic)),
1355 )
1356 .child(
1357 h_flex()
1358 .items_center()
1359 .child(toolbar_camera(app, model))
1360 .children(camera_menu_button(app, model, CameraMenu::of(state))),
1361 )
1362 .child(share_button(
1363 app,
1364 model,
1365 ShareOptions::of(state),
1366 call.share_menu_open,
1367 ));
1368 let controls = h_flex()
1369 .debug_selector(|| "shell/islands/main/call-header/controls".into())
1370 .flex_none()
1371 .gap(px(GROUP_GAP))
1372 .items_center()
1373 .child(devices)
1374 .child(group_divider())
1375 .child(panels_and_reactions)
1376 .child(group_divider())
1377 .child(stage_and_more);
1378 let header = header.child(title_group).child(controls).child(end_group);
1379
1380 let top = v_flex()
1381 .w_full()
1382 .flex_none()
1383 .child(header)
1384 .children(lobby_banner(app, model, call.lobby_list_open))
1385 .children(lock_banner(app, model))
1386 .children(health_banner(app, model))
1387 .children(sharing_banner(app, model, state.call_share_sound))
1388 .children(consult_banner(app, state));
1389
1390 let chrome_visible = call
1391 .fullscreen
1392 .is_none_or(|fullscreen| fullscreen.chrome_visible(now));
1393 let move_app = app.clone();
1394 let base = v_flex()
1395 .relative()
1396 .flex_1()
1397 .min_w_0()
1398 .h_full()
1399 .overflow_hidden()
1400 .bg(theme::surface());
1401 let column = if fullscreen {
1402 base.on_mouse_move(move |_, _, cx| {
1403 move_app.update(cx, |state, cx| state.touch_call_chrome(cx))
1404 })
1405 .when(chrome_visible, |column| {
1406 column.child(fullscreen_chrome("call-chrome-top", app, top))
1407 })
1408 .child(region)
1409 } else {
1410 base.rounded(px(10.))
1411 .child(top.debug_selector(|| "shell/islands/main/call-header".into()))
1412 .child(region)
1413 }
1414 .children(captions_overlay(model, now))
1415 .children(captions_hint_chip(model))
1416 .children(push_to_talk_chip(call))
1417 .children(state.transfer_picker.clone())
1418 .children(options_dialog(app, call))
1419 .children(consent_overlay(app, model));
1420 let panels: Vec<AnyElement> = chat
1421 .map(|chat| chat_panel(app, chat))
1422 .into_iter()
1423 .chain(
1424 call.transcript_open
1425 .then(|| state.transcript_panel.clone())
1426 .flatten()
1427 .map(IntoElement::into_any_element),
1428 )
1429 .chain(people_panel(app, state, call))
1430 .collect();
1431 Some(
1432 h_flex()
1433 .relative()
1434 .when(!fullscreen, |row| {
1435 row.debug_selector(|| "shell/islands/main".into())
1436 })
1437 .flex_1()
1438 .min_w_0()
1439 .h_full()
1440 .gap(px(ISLAND_GAP))
1441 .child(column)
1442 .children(side_panels(panels, island_width))
1443 .into_any_element(),
1444 )
1445}
1446
1447fn side_panels(panels: Vec<AnyElement>, island_width: f32) -> Vec<AnyElement> {
1448 if panels.is_empty() {
1449 return panels;
1450 }
1451 let panels_width = (CHAT_PANEL_WIDTH + ISLAND_GAP) * panels.len() as f32;
1452 if island_width - panels_width >= OVERLAY_BELOW {
1453 return panels;
1454 }
1455 vec![
1456 h_flex()
1457 .absolute()
1458 .top(px(HEADER_HEIGHT))
1459 .right_0()
1460 .bottom_0()
1461 .gap(px(ISLAND_GAP))
1462 .w(px(panels_width.min(island_width)))
1463 .children(panels)
1464 .into_any_element(),
1465 ]
1466}
1467
1468fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) -> Stateful<Div> {
1469 let hover_app = app.clone();
1470 div()
1471 .id(id)
1472 .w_full()
1473 .flex_none()
1474 .on_hover(move |hovered, _, cx| {
1475 hover_app.update(cx, |state, cx| state.set_call_chrome_hovered(*hovered, cx))
1476 })
1477 .child(content)
1478}
1479
1480fn chat_panel(app: &Entity<AppState>, chat: AnyView) -> AnyElement {
1481 let app = app.clone();
1482 side_panel(
1483 "call-chat-panel",
1484 "Chat",
1485 "Close the chat",
1486 move |cx| app.update(cx, |state, cx| state.toggle_call_chat(cx)),
1487 chat,
1488 )
1489 .debug_selector(|| CHAT_PANEL_TAG.into())
1490 .into_any_element()
1491}
1492
1493pub fn side_panel(
1494 panel_id: &'static str,
1495 title: &'static str,
1496 close_tooltip: &'static str,
1497 on_close: impl Fn(&mut App) + 'static,
1498 body: impl IntoElement,
1499) -> Stateful<Div> {
1500 v_flex()
1501 .id(panel_id)
1502 .w(px(CHAT_PANEL_WIDTH))
1503 .h_full()
1504 .flex_shrink(1.)
1505 .min_w_0()
1506 .rounded(px(10.))
1507 .overflow_hidden()
1508 .bg(theme::surface())
1509 .child(
1510 h_flex()
1511 .w_full()
1512 .h(px(CHAT_HEADER_HEIGHT))
1513 .flex_none()
1514 .pl(px(20.))
1515 .pr(px(12.))
1516 .items_center()
1517 .justify_between()
1518 .child(
1519 div()
1520 .text_size(px(15.))
1521 .font_weight(FontWeight::SEMIBOLD)
1522 .child(title),
1523 )
1524 .child(
1525 div()
1526 .id(ElementId::Name(format!("{panel_id}-close").into()))
1527 .size(px(28.))
1528 .flex()
1529 .items_center()
1530 .justify_center()
1531 .rounded(px(7.))
1532 .cursor_pointer()
1533 .hover(|button| button.bg(theme::row_hover()))
1534 .tooltip(move |window, cx| Tooltip::new(close_tooltip).build(window, cx))
1535 .child(icon(IconName::Close, 14., theme::text_muted()))
1536 .on_click(move |_, _, cx| on_close(cx)),
1537 ),
1538 )
1539 .child(body)
1540}
1541
1542#[cfg(test)]
1543mod tests {
1544 use super::{TileSize, name_plate_metrics};
1545
1546 #[test]
1547 fn small_strip_tiles_get_a_compact_name_plate() {
1548 let strip = name_plate_metrics(TileSize { width: 216., height: 121.5, avatar: 48. });
1549 assert_eq!((strip.text_size, strip.inset, strip.padding_y), (11., 4., 2.));
1550 assert!(strip.max_width_share < 1.);
1551 let stage = name_plate_metrics(TileSize { width: 640., height: 360., avatar: 96. });
1552 assert_eq!((stage.text_size, stage.inset), (12., 8.));
1553 }
1554}