BlueGit

ict rusty-teams

Files

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

call_organizer.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
call_organizer.rs 27.5 KiB Download Raw
1use std::sync::Arc;
2use std::time::Instant;
3
4use calling::{CaptionState, HoldState, MeetingRole, Modality, VideoKey};
5use gpui_kit::assets::IconName;
6use gpui_kit::component::button::{Button, ButtonVariants as _};
7use gpui_kit::component::dialog::DialogFooter;
8use gpui_kit::component::menu::{ContextMenuExt as _, DropdownMenu as _, PopupMenu, PopupMenuItem};
9use gpui_kit::component::popover::Popover;
10use gpui_kit::component::{Sizable as _, WindowExt as _, h_flex, v_flex};
11use gpui_kit::prelude::FluentBuilder as _;
12use gpui_kit::*;
13
14use super::avatar::person_avatar;
15use super::call_control_fold::{Foldable, FoldedControls, folded_items};
16use super::call_extras::{CameraMenu, background_items, effect_items, open_transfer_picker};
17use super::call_record::{record_items, transcript_and_settings_items};
18use super::call_toolbar::{split_chevron, tool_face, tool_trigger};
19use super::call_view::{BANNER_HEIGHT, MENU_WIDTH};
20use super::widgets::{Corner, corner_badge, count_badge, icon};
21use crate::app_state::AppState;
22use crate::call::{CAPTION_SHOWN, CallModel, CaptionPosition, Focus, contain_size};
23use crate::notice::truncated;
24use crate::theme;
25
26const BANNER_TEXT: f32 = 13.;
27const PILL_HEIGHT: f32 = 26.;
28const LOBBY_LIST_WIDTH: f32 = 340.;
29const LOBBY_NAME_LIMIT: usize = 28;
30const CAPTION_WIDTH: f32 = 720.;
31const CAPTION_BOTTOM: f32 = 16.;
32const CAPTION_TOP: f32 = 72.;
33const CAPTION_FADE_SECONDS: f32 = 1.;
34const CAPTION_BACKGROUND: f32 = 0.72;
35const FOCUS_RADIUS: f32 = 12.;
36const FOCUS_BORDER: f32 = 2.;
37const FOCUS_AVATAR: f32 = 140.;
38const CHIP_HEIGHT: f32 = 24.;
39const MORE_SIZE: f32 = 28.;
40const NAME_LIMIT: usize = 32;
41
42fn dark_text() -> Hsla {
43 hsla(0., 0., 0.08, 1.)
44}
45
46pub(super) fn pill(
47 id: impl Into<ElementId>,
48 label: impl Into<SharedString>,
49 filled: bool,
50) -> Stateful<Div> {
51 let (background, foreground) = if filled {
52 (dark_text(), theme::white())
53 } else {
54 (dark_text().opacity(0.12), dark_text())
55 };
56 div()
57 .id(id)
58 .h(px(PILL_HEIGHT))
59 .px(px(12.))
60 .flex()
61 .flex_none()
62 .items_center()
63 .rounded_full()
64 .bg(background)
65 .text_color(foreground)
66 .text_size(px(BANNER_TEXT))
67 .font_weight(FontWeight::SEMIBOLD)
68 .cursor_pointer()
69 .hover(|button| button.opacity(0.85))
70 .child(label.into())
71}
72
73pub fn lobby_text(waiting: usize) -> String {
74 match waiting {
75 1 => "1 person is waiting in the lobby".to_owned(),
76 count => format!("{count} people are waiting in the lobby"),
77 }
78}
79
80fn lobby_list(app: &Entity<AppState>, guests: &[(String, String)]) -> Div {
81 v_flex()
82 .w(px(LOBBY_LIST_WIDTH))
83 .gap(px(6.))
84 .children(guests.iter().map(|(mri, name)| {
85 let (admit_app, deny_app) = (app.clone(), app.clone());
86 let (admit_mri, deny_mri) = (mri.clone(), mri.clone());
87 h_flex()
88 .w_full()
89 .gap(px(8.))
90 .items_center()
91 .child(
92 div()
93 .flex_1()
94 .min_w_0()
95 .truncate()
96 .text_size(px(14.))
97 .child(truncated(name, LOBBY_NAME_LIMIT)),
98 )
99 .child(
100 Button::new(SharedString::from(format!("lobby-admit-{mri}")))
101 .label("Admit")
102 .on_click(move |_, _, cx| {
103 admit_app.update(cx, |state, cx| {
104 state.admit_call_guest(admit_mri.clone(), cx)
105 })
106 }),
107 )
108 .child(
109 Button::new(SharedString::from(format!("lobby-deny-{mri}")))
110 .label("Deny")
111 .ghost()
112 .on_click(move |_, _, cx| {
113 deny_app
114 .update(cx, |state, cx| state.deny_call_guest(deny_mri.clone(), cx))
115 }),
116 )
117 }))
118}
119
120pub fn lobby_banner(
121 app: &Entity<AppState>,
122 model: &CallModel,
123 list_open: bool,
124) -> Option<AnyElement> {
125 if !model.can_admit() {
126 return None;
127 }
128 let guests: Vec<(String, String)> = model
129 .lobby_guests()
130 .into_iter()
131 .map(|tile| (tile.mri.clone(), tile.name.clone()))
132 .collect();
133 if guests.is_empty() {
134 return None;
135 }
136 let list_app = app.clone();
137 let open_app = app.clone();
138 let admit_app = app.clone();
139 Some(
140 h_flex()
141 .id("call-lobby-banner")
142 .w_full()
143 .h(px(BANNER_HEIGHT))
144 .flex_none()
145 .px(px(20.))
146 .gap(px(12.))
147 .items_center()
148 .justify_center()
149 .bg(theme::amber())
150 .text_color(dark_text())
151 .text_size(px(BANNER_TEXT))
152 .font_weight(FontWeight::SEMIBOLD)
153 .child(lobby_text(guests.len()))
154 .child(
155 Popover::new("call-lobby-popover")
156 .anchor(Anchor::TopLeft)
157 .offset(px(8.))
158 .open(list_open)
159 .on_open_change(move |open, _, cx| {
160 open_app.update(cx, |state, cx| state.set_call_lobby_list(*open, cx))
161 })
162 .trigger(
163 Button::new("call-lobby-view")
164 .ghost()
165 .p_0()
166 .h(px(PILL_HEIGHT))
167 .rounded_full()
168 .child(pill("call-lobby-view-face", "View", false)),
169 )
170 .content(move |_, _, _| lobby_list(&list_app, &guests)),
171 )
172 .child(
173 pill("call-lobby-admit-all", "Admit all", true).on_click(move |_, _, cx| {
174 admit_app.update(cx, |state, cx| state.admit_all_call_guests(cx))
175 }),
176 )
177 .into_any_element(),
178 )
179}
180
181fn confirm_remove(
182 app: &Entity<AppState>,
183 mri: &str,
184 name: &str,
185 window: &mut Window,
186 cx: &mut App,
187) {
188 let app = app.clone();
189 let mri = mri.to_owned();
190 let heading = format!("Remove {} from the meeting?", truncated(name, NAME_LIMIT));
191 window.open_alert_dialog(cx, move |alert, _, _| {
192 let app = app.clone();
193 let mri = mri.clone();
194 let cancel = Button::new("remove-cancel")
195 .label("Cancel")
196 .on_click(|_, window, cx| window.close_dialog(cx));
197 let remove = Button::new("remove-confirm")
198 .label("Remove")
199 .danger()
200 .on_click(move |_, window, cx| {
201 app.update(cx, |state, cx| {
202 state.remove_call_participant(mri.clone(), cx)
203 });
204 window.close_dialog(cx);
205 });
206 alert
207 .title(heading.clone())
208 .description("They leave the call and can only come back if they join again.")
209 .footer(DialogFooter::new().child(cancel).child(remove))
210 .on_ok(|_, _, _| false)
211 });
212}
213
214fn own_tile_items(popup: PopupMenu, app: &Entity<AppState>) -> PopupMenu {
215 let hide_app = app.clone();
216 popup.min_w(px(MENU_WIDTH)).item(
217 PopupMenuItem::new("Hide for me")
218 .icon(IconName::EyeOff)
219 .on_click(move |_, _, cx| {
220 hide_app.update(cx, |state, cx| state.set_call_hide_me(true, cx))
221 }),
222 )
223}
224
225pub fn tile_menu(
226 popup: PopupMenu,
227 app: &Entity<AppState>,
228 model: &CallModel,
229 mri: &str,
230 name: &str,
231 own: bool,
232) -> PopupMenu {
233 if own {
234 return own_tile_items(popup, app);
235 }
236 let pinned = model.is_pinned(mri);
237 let spotlighted = model.is_spotlighted(mri);
238 let organizes = model.organizes_meeting();
239 let raised = model
240 .tiles
241 .iter()
242 .any(|tile| tile.mri == mri && tile.hand.is_some());
243 let muted = model.tiles.iter().any(|tile| tile.mri == mri && tile.muted);
244 let mut popup = popup.min_w(px(MENU_WIDTH));
245 let pin_app = app.clone();
246 let pin_mri = mri.to_owned();
247 popup = popup.item(
248 PopupMenuItem::new(if pinned { "Unpin" } else { "Pin for me" })
249 .icon(IconName::Frame)
250 .on_click(move |_, _, cx| {
251 pin_app.update(cx, |state, cx| state.toggle_call_pin(&pin_mri, cx))
252 }),
253 );
254 if model.is_one_to_one()
255 || model
256 .tiles
257 .iter()
258 .any(|tile| tile.mri == mri && tile.has_video)
259 {
260 let (fit_app, fit_mri) = (app.clone(), mri.to_owned());
261 let fitted = model.is_fitted(mri);
262 popup = popup.item(
263 PopupMenuItem::new(if fitted { "Fill frame" } else { "Fit to frame" })
264 .icon(if fitted {
265 IconName::Expand
266 } else {
267 IconName::Shrink
268 })
269 .on_click(move |_, _, cx| {
270 fit_app.update(cx, |state, cx| state.toggle_call_fit(&fit_mri, cx))
271 }),
272 );
273 }
274 if organizes {
275 let (spotlight_app, spotlight_mri) = (app.clone(), mri.to_owned());
276 popup = popup.item(
277 PopupMenuItem::new(if spotlighted {
278 "Stop spotlight"
279 } else {
280 "Spotlight for everyone"
281 })
282 .icon(IconName::Star)
283 .on_click(move |_, _, cx| {
284 spotlight_app.update(cx, |state, cx| {
285 state.toggle_call_spotlight(spotlight_mri.clone(), cx)
286 })
287 }),
288 );
289 }
290 if organizes {
291 let (mute_app, mute_mri) = (app.clone(), mri.to_owned());
292 popup = popup.item(
293 PopupMenuItem::new("Mute")
294 .icon(IconName::MicOff)
295 .disabled(muted)
296 .on_click(move |_, _, cx| {
297 mute_app.update(cx, |state, cx| {
298 state.mute_call_participant(mute_mri.clone(), cx)
299 })
300 }),
301 );
302 }
303 if model.can_change_roles(mri) {
304 popup = restriction_items(popup, app, model, mri);
305 }
306 if organizes && raised {
307 let (hand_app, hand_mri) = (app.clone(), mri.to_owned());
308 popup = popup.item(PopupMenuItem::new("Lower hand").on_click(move |_, _, cx| {
309 hand_app.update(cx, |state, cx| state.lower_call_hand(hand_mri.clone(), cx))
310 }));
311 }
312 if organizes {
313 let (remove_app, remove_mri, remove_name) = (app.clone(), mri.to_owned(), name.to_owned());
314 popup = popup.separator().item(
315 PopupMenuItem::new("Remove from meeting...")
316 .icon(IconName::Close)
317 .on_click(move |_, window, cx| {
318 confirm_remove(&remove_app, &remove_mri, &remove_name, window, cx)
319 }),
320 );
321 }
322 popup
323}
324
325fn modality_item(
326 app: &Entity<AppState>,
327 mri: &str,
328 modality: Modality,
329 allowed: bool,
330) -> PopupMenuItem {
331 let (app, mri) = (app.clone(), mri.to_owned());
332 let (label, glyph) = match (modality, allowed) {
333 (Modality::Mic, true) => ("Disable mic", IconName::MicOff),
334 (Modality::Mic, false) => ("Allow mic", IconName::Mic),
335 (Modality::Camera, true) => ("Disable camera", IconName::VideoOff),
336 (Modality::Camera, false) => ("Allow camera", IconName::Video),
337 };
338 PopupMenuItem::new(label)
339 .icon(glyph)
340 .on_click(move |_, _, cx| {
341 app.update(cx, |state, cx| {
342 state.set_call_attendee_modality(mri.clone(), modality, !allowed, cx)
343 })
344 })
345}
346
347fn restriction_items(
348 popup: PopupMenu,
349 app: &Entity<AppState>,
350 model: &CallModel,
351 mri: &str,
352) -> PopupMenu {
353 let presenter = model.tile_role(mri) == Some(MeetingRole::Presenter);
354 let (role_app, role_mri) = (app.clone(), mri.to_owned());
355 popup
356 .item(modality_item(
357 app,
358 mri,
359 Modality::Mic,
360 model.attendee_allowed(mri, Modality::Mic),
361 ))
362 .item(modality_item(
363 app,
364 mri,
365 Modality::Camera,
366 model.attendee_allowed(mri, Modality::Camera),
367 ))
368 .item(
369 PopupMenuItem::new(if presenter {
370 "Make attendee"
371 } else {
372 "Make presenter"
373 })
374 .icon(IconName::Users)
375 .on_click(move |_, _, cx| {
376 let role = if presenter {
377 MeetingRole::Attendee
378 } else {
379 MeetingRole::Presenter
380 };
381 role_app.update(cx, |state, cx| {
382 state.set_call_role(role_mri.clone(), role, cx)
383 })
384 }),
385 )
386}
387
388fn more_overlay(
389 app: &Entity<AppState>,
390 model: &CallModel,
391 mri: &str,
392 name: &str,
393 own: bool,
394 group: SharedString,
395) -> Div {
396 let (app, model, mri_owned, name) =
397 (app.clone(), model.clone(), mri.to_owned(), name.to_owned());
398 div()
399 .absolute()
400 .top(px(8.))
401 .right(px(8.))
402 .opacity(0.)
403 .group_hover(group, |more| more.opacity(1.))
404 .child(
405 Button::new(SharedString::from(format!("call-tile-more-{mri}")))
406 .icon(IconName::Ellipsis)
407 .ghost()
408 .xsmall()
409 .size(px(MORE_SIZE))
410 .rounded_full()
411 .bg(black().opacity(0.55))
412 .text_color(theme::white())
413 .tooltip("More")
414 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
415 tile_menu(popup, &app, &model, &mri_owned, &name, own)
416 }),
417 )
418}
419
420/// Adds the right-click menu and a "..." button that shows while the pointer is over the tile.
421pub fn attach_tile_menu(
422 tile: Stateful<Div>,
423 app: &Entity<AppState>,
424 model: &CallModel,
425 mri: &str,
426 name: &str,
427 own: bool,
428) -> AnyElement {
429 let group = SharedString::from(format!("call-tile-group-{mri}"));
430 let (context_app, context_model, context_mri, context_name) =
431 (app.clone(), model.clone(), mri.to_owned(), name.to_owned());
432 tile.group(group.clone())
433 .relative()
434 .child(more_overlay(app, model, mri, name, own, group))
435 .context_menu(move |popup, _, _| {
436 tile_menu(
437 popup,
438 &context_app,
439 &context_model,
440 &context_mri,
441 &context_name,
442 own,
443 )
444 })
445 .into_any_element()
446}
447
448pub fn with_tile_menu(
449 app: &Entity<AppState>,
450 model: &CallModel,
451 mri: &str,
452 name: &str,
453 own: bool,
454 tile: AnyElement,
455) -> AnyElement {
456 let wrapper = div()
457 .id(SharedString::from(format!("call-tile-{mri}")))
458 .flex_none()
459 .child(tile);
460 attach_tile_menu(wrapper, app, model, mri, name, own)
461}
462
463pub fn more_button(
464 app: &Entity<AppState>,
465 model: &CallModel,
466 folded: &FoldedControls,
467) -> Option<AnyElement> {
468 if !matches!(
469 model.kind,
470 crate::call::CallKind::Meeting
471 | crate::call::CallKind::Direct
472 | crate::call::CallKind::Group
473 ) {
474 return None;
475 }
476 let app = app.clone();
477 let model = model.clone();
478 let folded = folded.clone();
479 let unread = folded.chat_unread;
480 let chat_folded = folded.folds(Foldable::Chat);
481 Some(
482 tool_trigger(
483 "call-more",
484 tool_face("call-more-face", IconName::Ellipsis, "More", false)
485 .relative()
486 .when(chat_folded && unread > 0, |face| {
487 face.child(corner_badge(Corner::TopRight, 4.).child(count_badge(unread, false)))
488 }),
489 )
490 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, window, cx| {
491 more_menu(popup, window, cx, &app, &model, &folded)
492 })
493 .into_any_element(),
494 )
495}
496
497fn more_menu(
498 popup: PopupMenu,
499 window: &mut Window,
500 cx: &mut Context<PopupMenu>,
501 app: &Entity<AppState>,
502 model: &CallModel,
503 folded: &FoldedControls,
504) -> PopupMenu {
505 let popup = folded_items(popup.min_w(px(MENU_WIDTH)), window, cx, app, model, folded);
506 let popup = match model.kind {
507 crate::call::CallKind::Meeting => meeting_items(popup, window, cx, app, model),
508 crate::call::CallKind::Direct => one_to_one_items(popup, window, cx, app, model),
509 _ => record_items(popup, window, cx, app, model),
510 };
511 incoming_video_item(popup, app, model)
512}
513
514fn incoming_video_item(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
515 if model.health.incoming_video {
516 return popup;
517 }
518 let app = app.clone();
519 popup.item(
520 PopupMenuItem::new("Turn on incoming video")
521 .icon(IconName::Video)
522 .on_click(move |_, _, cx| {
523 app.update(cx, |state, cx| state.set_call_incoming_video(true, cx))
524 }),
525 )
526}
527
528fn one_to_one_items(
529 mut popup: PopupMenu,
530 window: &mut Window,
531 cx: &mut Context<PopupMenu>,
532 app: &Entity<AppState>,
533 model: &CallModel,
534) -> PopupMenu {
535 let (hold_app, transfer_app) = (app.clone(), app.clone());
536 let held = model.hold == HoldState::Local;
537 popup = popup.item(
538 PopupMenuItem::new(if held { "Resume" } else { "Hold" })
539 .icon(IconName::Timer)
540 .disabled(!held && !model.can_hold())
541 .on_click(move |_, _, cx| hold_app.update(cx, |state, cx| state.toggle_call_hold(cx))),
542 );
543 popup = record_items(popup, window, cx, app, model);
544 let can_transfer = model.can_transfer();
545 popup.item(
546 PopupMenuItem::new("Transfer...")
547 .icon(IconName::Forward)
548 .disabled(!can_transfer)
549 .on_click(move |_, window, cx| open_transfer_picker(&transfer_app, window, cx)),
550 )
551}
552
553fn meeting_items(
554 mut popup: PopupMenu,
555 window: &mut Window,
556 cx: &mut Context<PopupMenu>,
557 app: &Entity<AppState>,
558 model: &CallModel,
559) -> PopupMenu {
560 let (mute_app, captions_app, board_app) = (app.clone(), app.clone(), app.clone());
561 let captions_on = model.captions_on();
562 if model.organizes_meeting() {
563 popup = popup.item(
564 PopupMenuItem::new("Mute all")
565 .icon(IconName::MicOff)
566 .on_click(move |_, _, cx| mute_app.update(cx, |state, cx| state.mute_all_call(cx))),
567 );
568 }
569 popup = record_items(popup, window, cx, app, model);
570 if model.can_open_whiteboard() {
571 popup = popup.item(
572 PopupMenuItem::new("Whiteboard")
573 .icon(IconName::Frame)
574 .on_click(move |_, _, cx| {
575 board_app.update(cx, |state, cx| state.open_call_whiteboard(cx))
576 }),
577 );
578 }
579 let popup = popup.item(
580 PopupMenuItem::new(if captions_on {
581 "Turn off live captions"
582 } else {
583 "Turn on live captions"
584 })
585 .icon(if captions_on {
586 IconName::CaptionsOff
587 } else {
588 IconName::Captions
589 })
590 .on_click(move |_, _, cx| {
591 captions_app.update(cx, |state, cx| state.toggle_call_captions(cx))
592 }),
593 );
594 transcript_and_settings_items(popup, app)
595}
596
597pub fn camera_menu_button(
598 app: &Entity<AppState>,
599 model: &CallModel,
600 backgrounds: CameraMenu,
601) -> Option<AnyElement> {
602 if !model.can_use_camera() {
603 return None;
604 }
605 let app = app.clone();
606 let model = model.clone();
607 Some(
608 split_chevron("call-camera-menu", "call-camera-menu-face")
609 .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| {
610 camera_menu(popup, &app, &model, &backgrounds)
611 })
612 .into_any_element(),
613 )
614}
615
616fn camera_menu(
617 popup: PopupMenu,
618 app: &Entity<AppState>,
619 model: &CallModel,
620 backgrounds: &CameraMenu,
621) -> PopupMenu {
622 let camera_app = app.clone();
623 let cameras = super::call_view::device_items(
624 calling::camera_entries(&model.cameras),
625 &model.camera,
626 move |choice, cx| {
627 camera_app.update(cx, |state, cx| state.select_call_camera(choice, cx));
628 },
629 );
630 let mut popup = popup
631 .min_w(px(MENU_WIDTH))
632 .item(PopupMenuItem::label("Camera"));
633 for item in cameras {
634 popup = popup.item(item);
635 }
636 background_items(
637 effect_items(popup, app, backgrounds.effects),
638 app,
639 backgrounds,
640 )
641}
642
643pub fn captions_overlay(model: &CallModel, now: Instant) -> Option<AnyElement> {
644 let lines = model.visible_captions(now);
645 if lines.is_empty() {
646 return None;
647 }
648 let shown = CAPTION_SHOWN.as_secs_f32();
649 Some(
650 div()
651 .id("call-captions")
652 .absolute()
653 .left_0()
654 .right_0()
655 .map(|overlay| match model.view.caption_position {
656 CaptionPosition::Bottom => overlay.bottom(px(CAPTION_BOTTOM)),
657 CaptionPosition::Top => overlay.top(px(CAPTION_TOP)),
658 })
659 .flex()
660 .justify_center()
661 .px(px(24.))
662 .child(
663 v_flex()
664 .w(px(CAPTION_WIDTH))
665 .max_w_full()
666 .gap(px(4.))
667 .px(px(16.))
668 .py(px(8.))
669 .rounded(px(10.))
670 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
671 .text_color(theme::white())
672 .text_size(px(model.view.caption_size.text_size()))
673 .children(lines.into_iter().map(|line| {
674 let age = now.saturating_duration_since(line.at).as_secs_f32();
675 let fade = ((shown - age) / CAPTION_FADE_SECONDS).clamp(0., 1.);
676 h_flex()
677 .opacity(fade)
678 .gap(px(8.))
679 .items_start()
680 .child(
681 div()
682 .flex_none()
683 .font_weight(FontWeight::BOLD)
684 .child(format!("{}:", line.speaker)),
685 )
686 .child(div().flex_1().min_w_0().child(line.text.clone()))
687 })),
688 )
689 .into_any_element(),
690 )
691}
692
693fn focus_chip(label: &'static str, glyph: IconName, background: Hsla, foreground: Hsla) -> Div {
694 h_flex()
695 .h(px(CHIP_HEIGHT))
696 .px(px(8.))
697 .gap(px(4.))
698 .items_center()
699 .rounded_full()
700 .bg(background)
701 .text_color(foreground)
702 .text_size(px(12.))
703 .font_weight(FontWeight::SEMIBOLD)
704 .child(icon(glyph, 13., foreground))
705 .child(label)
706}
707
708pub fn spotlight_chip() -> Div {
709 focus_chip("Spotlight", IconName::Star, theme::amber(), dark_text())
710}
711
712pub fn pin_chip() -> Div {
713 focus_chip(
714 "Pinned",
715 IconName::Frame,
716 hsla(0., 0., 0., 0.6),
717 theme::white(),
718 )
719}
720
721pub fn render_focus_stage(
722 app: &Entity<AppState>,
723 state: &AppState,
724 focus: &Focus,
725 size: (f32, f32),
726 now: Instant,
727) -> Option<AnyElement> {
728 let call = state.call.as_ref()?;
729 let model = &call.model;
730 let me = state.directory.me.as_ref();
731 let (name, user_id, speaking, muted, key) = if focus.own {
732 (
733 "You".to_owned(),
734 me.map(|person| person.user_id.clone()),
735 model.local_speaking,
736 model.muted,
737 VideoKey::LocalCamera,
738 )
739 } else {
740 let tile = model.tiles.iter().find(|tile| tile.mri == focus.mri)?;
741 (
742 tile.name.clone(),
743 tile.user_id.clone(),
744 model.tile_speaking(tile),
745 tile.muted,
746 VideoKey::Person(tile.mri.clone()),
747 )
748 };
749 let image: Option<Arc<RenderImage>> = call.pictures.live(&key, now);
750 let avatar_only = image.is_none();
751 let (picture_size, picture) = match image {
752 Some(image) => {
753 let pixels = image.size(0);
754 let (width, height) =
755 contain_size(size, (pixels.width.0 as f32, pixels.height.0 as f32));
756 let picture = img(ImageSource::Render(image))
757 .size_full()
758 .object_fit(ObjectFit::Fill)
759 .rounded(px(FOCUS_RADIUS))
760 .into_any_element();
761 ((width, height), picture)
762 }
763 None => (
764 contain_size(size, (16., 9.)),
765 div()
766 .size_full()
767 .flex()
768 .items_center()
769 .justify_center()
770 .child(person_avatar(
771 &state.directory,
772 user_id.as_deref(),
773 &name,
774 FOCUS_AVATAR,
775 ))
776 .into_any_element(),
777 ),
778 };
779 let stage = div()
780 .id("call-focus-stage")
781 .relative()
782 .w(px(picture_size.0))
783 .h(px(picture_size.1))
784 .flex_none()
785 .overflow_hidden()
786 .rounded(px(FOCUS_RADIUS))
787 .when(avatar_only, |stage| stage.bg(hsla(0., 0., 0.04, 1.)))
788 .border(px(FOCUS_BORDER))
789 .border_color(if speaking {
790 theme::green()
791 } else {
792 transparent_black()
793 })
794 .child(picture)
795 .child(
796 h_flex()
797 .absolute()
798 .top(px(12.))
799 .left(px(12.))
800 .gap(px(6.))
801 .when(focus.spotlight, |chips| chips.child(spotlight_chip()))
802 .when(focus.pinned, |chips| chips.child(pin_chip())),
803 )
804 .child(
805 h_flex()
806 .absolute()
807 .left(px(8.))
808 .bottom(px(8.))
809 .gap(px(8.))
810 .px(px(8.))
811 .py(px(4.))
812 .rounded(px(6.))
813 .bg(hsla(0., 0., 0., 0.6))
814 .text_color(theme::white())
815 .text_size(px(13.))
816 .font_weight(FontWeight::SEMIBOLD)
817 .child(name.clone())
818 .when(muted, |plate| {
819 plate.child(icon(IconName::MicOff, 14., theme::red()))
820 }),
821 );
822 let stage = attach_tile_menu(stage, app, model, &focus.mri, &name, focus.own);
823 Some(
824 div()
825 .w(px(size.0))
826 .h(px(size.1))
827 .flex_none()
828 .flex()
829 .items_center()
830 .justify_center()
831 .child(stage)
832 .into_any_element(),
833 )
834}
835
836pub fn captions_state_hint(model: &CallModel) -> Option<&'static str> {
837 match model.captions {
838 CaptionState::Starting => Some("Starting live captions..."),
839 CaptionState::Failed(_) => Some("Live captions could not start"),
840 CaptionState::On | CaptionState::Off => None,
841 }
842}
843
844pub fn captions_hint_chip(model: &CallModel) -> Option<AnyElement> {
845 let text = captions_state_hint(model)?;
846 Some(
847 div()
848 .id("call-captions-hint")
849 .absolute()
850 .left_0()
851 .right_0()
852 .bottom(px(CAPTION_BOTTOM))
853 .flex()
854 .justify_center()
855 .child(
856 div()
857 .px(px(12.))
858 .py(px(6.))
859 .rounded_full()
860 .bg(hsla(0., 0., 0., CAPTION_BACKGROUND))
861 .text_color(theme::white())
862 .text_size(px(13.))
863 .child(text),
864 )
865 .into_any_element(),
866 )
867}