| 1 | use std::time::Instant; |
| 2 | |
| 3 | use gpui_kit::assets::IconName; |
| 4 | use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex}; |
| 5 | use gpui_kit::prelude::FluentBuilder as _; |
| 6 | use gpui_kit::*; |
| 7 | |
| 8 | use super::call_mini_window::{CONTROL_SIZE, WINDOW_RADIUS}; |
| 9 | use super::call_view::{ |
| 10 | camera_button, leave_button, mute_button, plain_own_tile, plain_person_tile, round_control, |
| 11 | }; |
| 12 | use crate::app_state::AppState; |
| 13 | use crate::call::share_overlay::{ |
| 14 | GALLERY_CONTROLS_HEIGHT, GALLERY_DIVIDER_HEIGHT, GALLERY_INSET, GALLERY_TILE_WIDTH, |
| 15 | GALLERY_TITLE_HEIGHT, gallery_candidates, |
| 16 | }; |
| 17 | use crate::call::{CallWindows, TileSize}; |
| 18 | use crate::theme; |
| 19 | |
| 20 | pub const SHOW_SPEAKER_ONLY: &str = "Show only active speaker"; |
| 21 | pub const SHOW_MORE_PEOPLE: &str = "Show more people"; |
| 22 | const MAXIMIZE_MEETING_WINDOW: &str = "Maximize meeting window"; |
| 23 | const TITLE_BUTTON_SIZE: f32 = 24.; |
| 24 | const TITLE_PADDING: f32 = (GALLERY_TITLE_HEIGHT - TITLE_BUTTON_SIZE) / 2.; |
| 25 | const CONTROLS_GAP: f32 = 8.; |
| 26 | |
| 27 | pub struct ShareGalleryView { |
| 28 | windows: Entity<CallWindows>, |
| 29 | app: Entity<AppState>, |
| 30 | _windows_subscription: Subscription, |
| 31 | _app_subscription: Subscription, |
| 32 | _media_subscription: Option<Subscription>, |
| 33 | } |
| 34 | |
| 35 | impl ShareGalleryView { |
| 36 | pub fn new(windows: Entity<CallWindows>, cx: &mut Context<Self>) -> Self { |
| 37 | let app = windows.read(cx).app().clone(); |
| 38 | let windows_subscription = cx.observe(&windows, |_, _, cx| cx.notify()); |
| 39 | let app_subscription = cx.observe(&app, |_, _, cx| cx.notify()); |
| 40 | let media_subscription = app |
| 41 | .read(cx) |
| 42 | .call_media |
| 43 | .clone() |
| 44 | .map(|media| cx.observe(&media, |_, _, cx| cx.notify())); |
| 45 | ShareGalleryView { |
| 46 | windows, |
| 47 | app, |
| 48 | _windows_subscription: windows_subscription, |
| 49 | _app_subscription: app_subscription, |
| 50 | _media_subscription: media_subscription, |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | pub(super) fn view_switch_button( |
| 56 | windows: &Entity<CallWindows>, |
| 57 | id: &'static str, |
| 58 | glyph: IconName, |
| 59 | tooltip: &'static str, |
| 60 | ) -> Stateful<Div> { |
| 61 | let windows = windows.clone(); |
| 62 | round_control(id, glyph, theme::surface_raised(), theme::text()) |
| 63 | .size(px(TITLE_BUTTON_SIZE)) |
| 64 | .tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx)) |
| 65 | .on_click(move |_, _, cx| { |
| 66 | cx.stop_propagation(); |
| 67 | windows.update(cx, |windows, cx| windows.toggle_speaker_only(cx)); |
| 68 | }) |
| 69 | } |
| 70 | |
| 71 | fn maximize_button(windows: &Entity<CallWindows>) -> Stateful<Div> { |
| 72 | let windows = windows.clone(); |
| 73 | round_control( |
| 74 | "call-gallery-maximize", |
| 75 | IconName::Maximize2, |
| 76 | theme::surface_raised(), |
| 77 | theme::text(), |
| 78 | ) |
| 79 | .size(px(TITLE_BUTTON_SIZE)) |
| 80 | .tooltip(|window, cx| Tooltip::new(MAXIMIZE_MEETING_WINDOW).build(window, cx)) |
| 81 | .on_click(move |_, _, cx| { |
| 82 | cx.stop_propagation(); |
| 83 | windows.update(cx, |windows, cx| windows.return_to_call(cx)); |
| 84 | }) |
| 85 | } |
| 86 | |
| 87 | fn title_bar(windows: &Entity<CallWindows>) -> Div { |
| 88 | h_flex() |
| 89 | .w_full() |
| 90 | .h(px(GALLERY_TITLE_HEIGHT)) |
| 91 | .flex_none() |
| 92 | .items_center() |
| 93 | .gap(px(TITLE_PADDING)) |
| 94 | .pr(px(TITLE_PADDING)) |
| 95 | .child( |
| 96 | div() |
| 97 | .id("call-gallery-drag") |
| 98 | .flex_1() |
| 99 | .h_full() |
| 100 | .window_control_area(WindowControlArea::Drag) |
| 101 | .on_mouse_down(MouseButton::Left, |_, window, _| window.start_window_move()), |
| 102 | ) |
| 103 | .child(view_switch_button( |
| 104 | windows, |
| 105 | "call-gallery-speaker-only", |
| 106 | IconName::User, |
| 107 | SHOW_SPEAKER_ONLY, |
| 108 | )) |
| 109 | .child(maximize_button(windows)) |
| 110 | } |
| 111 | |
| 112 | fn divider(overflow: usize) -> Div { |
| 113 | div() |
| 114 | .relative() |
| 115 | .w_full() |
| 116 | .h(px(GALLERY_DIVIDER_HEIGHT)) |
| 117 | .flex_none() |
| 118 | .flex() |
| 119 | .items_center() |
| 120 | .justify_center() |
| 121 | .child( |
| 122 | div() |
| 123 | .absolute() |
| 124 | .left_0() |
| 125 | .right_0() |
| 126 | .top(px(GALLERY_DIVIDER_HEIGHT / 2.)) |
| 127 | .h(px(1.)) |
| 128 | .bg(theme::border()), |
| 129 | ) |
| 130 | .when(overflow > 0, |row| { |
| 131 | row.child( |
| 132 | div() |
| 133 | .px(px(8.)) |
| 134 | .rounded_full() |
| 135 | .bg(theme::surface_raised()) |
| 136 | .text_size(px(11.)) |
| 137 | .font_weight(FontWeight::SEMIBOLD) |
| 138 | .text_color(theme::text_muted()) |
| 139 | .child(format!("+{overflow}")), |
| 140 | ) |
| 141 | }) |
| 142 | } |
| 143 | |
| 144 | impl Render for ShareGalleryView { |
| 145 | fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 146 | let layout = self.windows.read(cx).gallery_layout(); |
| 147 | let state = self.app.read(cx); |
| 148 | let Some(call) = state.call.as_ref() else { |
| 149 | return div().into_any_element(); |
| 150 | }; |
| 151 | let model = &call.model; |
| 152 | let now = Instant::now(); |
| 153 | let size = TileSize::sixteen_by_nine(GALLERY_TILE_WIDTH); |
| 154 | let tiles: Vec<AnyElement> = gallery_candidates(model) |
| 155 | .into_iter() |
| 156 | .take(layout.tiles) |
| 157 | .map(|tile| plain_person_tile(state, model, tile, size, now)) |
| 158 | .collect(); |
| 159 | v_flex() |
| 160 | .id("call-gallery") |
| 161 | .size_full() |
| 162 | .overflow_hidden() |
| 163 | .items_center() |
| 164 | .gap(px(GALLERY_INSET)) |
| 165 | .rounded(px(WINDOW_RADIUS)) |
| 166 | .bg(theme::surface()) |
| 167 | .text_color(theme::text()) |
| 168 | .child(title_bar(&self.windows)) |
| 169 | .children(tiles) |
| 170 | .when(layout.divider, |column| { |
| 171 | column.child(divider(layout.overflow)) |
| 172 | }) |
| 173 | .when(layout.self_tile, |column| { |
| 174 | column.child(plain_own_tile(state, model, size, now)) |
| 175 | }) |
| 176 | .child( |
| 177 | h_flex() |
| 178 | .w_full() |
| 179 | .h(px(GALLERY_CONTROLS_HEIGHT)) |
| 180 | .flex_none() |
| 181 | .mt_auto() |
| 182 | .items_center() |
| 183 | .justify_center() |
| 184 | .gap(px(CONTROLS_GAP)) |
| 185 | .child(mute_button( |
| 186 | &self.app, |
| 187 | model, |
| 188 | "call-gallery-mute", |
| 189 | CONTROL_SIZE, |
| 190 | )) |
| 191 | .child(camera_button(&self.app, model).size(px(CONTROL_SIZE))) |
| 192 | .child(leave_button(&self.app, model, "call-gallery-leave", true)), |
| 193 | ) |
| 194 | .into_any_element() |
| 195 | } |
| 196 | } |