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