BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / call / share_actions.rs

share_actions.rs

9ee83b18 History
share_actions.rs 2.9 KiB Download Raw
1use calling::CallCommand;
2use gpui_kit::*;
3
4use super::share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY};
5use crate::app_state::{AppEvent, AppState};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ZoomStep {
9 In,
10 Out,
11 Reset,
12}
13
14fn flag_text(on: bool) -> &'static str {
15 if on { "1" } else { "0" }
16}
17
18impl AppState {
19 fn change_share_stage(&mut self, cx: &mut Context<Self>, change: impl FnOnce(&mut super::share_view::ShareStage)) {
20 let Some(call) = self.call.as_mut().filter(|call| call.model.screen_sharer.is_some()) else {
21 return;
22 };
23 change(&mut call.share_stage);
24 cx.emit(AppEvent::Call);
25 cx.notify();
26 }
27
28 pub fn zoom_share_wheel(&mut self, scroll_pixels: f32, position: (f32, f32), cx: &mut Context<Self>) {
29 self.change_share_stage(cx, |stage| {
30 let (pointer, size) = (stage.pointer(position), stage.size());
31 stage.view.zoom_wheel(scroll_pixels, pointer, size);
32 });
33 }
34
35 pub fn zoom_share(&mut self, step: ZoomStep, cx: &mut Context<Self>) {
36 self.change_share_stage(cx, |stage| {
37 let size = stage.size();
38 match step {
39 ZoomStep::In => stage.view.step_in(size),
40 ZoomStep::Out => stage.view.step_out(size),
41 ZoomStep::Reset => stage.view.reset(),
42 }
43 });
44 }
45
46 pub fn begin_share_pan(&mut self, position: (f32, f32), cx: &mut Context<Self>) {
47 self.change_share_stage(cx, |stage| stage.pan_from = Some(position));
48 }
49
50 pub fn pan_share_to(&mut self, position: (f32, f32), cx: &mut Context<Self>) {
51 self.change_share_stage(cx, |stage| {
52 let Some(from) = stage.pan_from.replace(position) else {
53 return;
54 };
55 let size = stage.size();
56 stage.view.pan_by((position.0 - from.0, position.1 - from.1), size);
57 });
58 }
59
60 pub fn end_share_pan(&mut self, cx: &mut Context<Self>) {
61 self.change_share_stage(cx, |stage| stage.pan_from = None);
62 }
63
64 pub fn pop_out_stage(&mut self, cx: &mut Context<Self>) {
65 self.change_share_stage(cx, |stage| stage.popped = true);
66 }
67
68 pub fn return_stage_from_pop_out(&mut self, cx: &mut Context<Self>) {
69 self.change_share_stage(cx, |stage| stage.popped = false);
70 }
71
72 pub fn set_call_share_motion(&mut self, on: bool, cx: &mut Context<Self>) {
73 self.call_share_motion = on;
74 let _ = self.store.set_meta(SHARE_MOTION_META_KEY, flag_text(on));
75 self.send_call_command(CallCommand::SetShareMotion(on));
76 cx.notify();
77 }
78
79 pub fn set_call_share_standout(&mut self, on: bool, cx: &mut Context<Self>) {
80 self.call_share_standout = on;
81 let _ = self.store.set_meta(SHARE_STANDOUT_META_KEY, flag_text(on));
82 self.send_call_command(CallCommand::SetShareStandout(on));
83 cx.notify();
84 }
85}