BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / call_pop_out.rs

call_pop_out.rs

call_pop_out.rs 2.2 KiB Download Raw
1use gpui_kit::component::v_flex;
2use gpui_kit::*;
3
4use super::call_stage::{StageMode, render_stage};
5use super::shortcuts::{ZoomShareIn, ZoomShareOut, ZoomShareReset};
6use crate::app_state::AppState;
7use crate::call::ZoomStep;
8use crate::theme;
9
10pub const POP_OUT_TITLE: &str = "Shared content";
11pub const POP_OUT_SIZE: (f32, f32) = (960., 600.);
12const KEY_CONTEXT: &str = "SharePopOut";
13
14pub struct SharePopOutView {
15 app: Entity<AppState>,
16 focus: FocusHandle,
17 _app_subscription: Subscription,
18 _media_subscription: Option<Subscription>,
19}
20
21impl 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
45pub 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
53impl 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}