BlueGit

ict rusty-teams

Files

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

share_actions.rs

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