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