BlueGit

ict rusty-teams

Files

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

call_view.rs

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