| 1 | use gpui_kit::component::v_flex; |
| 2 | use gpui_kit::*; |
| 3 | |
| 4 | use super::call_stage::{StageMode, render_stage}; |
| 5 | use super::shortcuts::{ZoomShareIn, ZoomShareOut, ZoomShareReset}; |
| 6 | use crate::app_state::AppState; |
| 7 | use crate::call::ZoomStep; |
| 8 | use crate::theme; |
| 9 | |
| 10 | pub const POP_OUT_TITLE: &str = "Shared content"; |
| 11 | pub const POP_OUT_SIZE: (f32, f32) = (960., 600.); |
| 12 | const KEY_CONTEXT: &str = "SharePopOut"; |
| 13 | |
| 14 | pub struct SharePopOutView { |
| 15 | app: Entity<AppState>, |
| 16 | focus: FocusHandle, |
| 17 | _app_subscription: Subscription, |
| 18 | _media_subscription: Option<Subscription>, |
| 19 | } |
| 20 | |
| 21 | impl SharePopOutView { |
| 22 | pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self { |
| 23 | let app_subscription = cx.observe(&app, |_, _, cx| cx.notify()); |
| 24 | let media_subscription = app |
| 25 | .read(cx) |
| 26 | .call_media |
| 27 | .clone() |
| 28 | .map(|media| cx.observe(&media, |_, _, cx| cx.notify())); |
| 29 | let closing_app = app.clone(); |
| 30 | window.on_window_should_close(cx, move |_, cx| { |
| 31 | closing_app.update(cx, |state, cx| state.return_stage_from_pop_out(cx)); |
| 32 | true |
| 33 | }); |
| 34 | let focus = cx.focus_handle(); |
| 35 | window.focus(&focus, cx); |
| 36 | SharePopOutView { |
| 37 | app, |
| 38 | focus, |
| 39 | _app_subscription: app_subscription, |
| 40 | _media_subscription: media_subscription, |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | pub fn zoom_listener<A: Action>( |
| 46 | app: &Entity<AppState>, |
| 47 | step: ZoomStep, |
| 48 | ) -> impl Fn(&A, &mut Window, &mut App) + 'static { |
| 49 | let app = app.clone(); |
| 50 | move |_, _, cx| app.update(cx, |state, cx| state.zoom_share(step, cx)) |
| 51 | } |
| 52 | |
| 53 | impl Render for SharePopOutView { |
| 54 | fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 55 | let state = self.app.read(cx); |
| 56 | v_flex() |
| 57 | .id("share-pop-out") |
| 58 | .key_context(KEY_CONTEXT) |
| 59 | .track_focus(&self.focus) |
| 60 | .size_full() |
| 61 | .bg(theme::background()) |
| 62 | .on_action(zoom_listener::<ZoomShareIn>(&self.app, ZoomStep::In)) |
| 63 | .on_action(zoom_listener::<ZoomShareOut>(&self.app, ZoomStep::Out)) |
| 64 | .on_action(zoom_listener::<ZoomShareReset>(&self.app, ZoomStep::Reset)) |
| 65 | .children(render_stage(&self.app, state, StageMode::PopOut)) |
| 66 | } |
| 67 | } |