BlueGit

ict rusty-teams

Files

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

call_organizer.rs

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