BlueGit

ict rusty-teams

Files

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

call_view.rs

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