BlueGit

ict rusty-teams

Files

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

call_view.rs

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