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