use calling::CallCommand; use gpui_kit::*; use super::share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY}; use crate::app_state::{AppEvent, AppState}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ZoomStep { In, Out, Reset, } fn flag_text(on: bool) -> &'static str { if on { "1" } else { "0" } } impl AppState { fn change_share_stage( &mut self, cx: &mut Context, change: impl FnOnce(&mut super::share_view::ShareStage), ) { let Some(call) = self .call .as_mut() .filter(|call| call.model.screen_sharer.is_some()) else { return; }; change(&mut call.share_stage); cx.emit(AppEvent::Call); cx.notify(); } pub fn zoom_share_wheel( &mut self, scroll_pixels: f32, position: (f32, f32), cx: &mut Context, ) { self.change_share_stage(cx, |stage| { let (pointer, size) = (stage.pointer(position), stage.size()); stage.view.zoom_wheel(scroll_pixels, pointer, size); }); } pub fn zoom_share(&mut self, step: ZoomStep, cx: &mut Context) { self.change_share_stage(cx, |stage| { let size = stage.size(); match step { ZoomStep::In => stage.view.step_in(size), ZoomStep::Out => stage.view.step_out(size), ZoomStep::Reset => stage.view.reset(), } }); } pub fn begin_share_pan(&mut self, position: (f32, f32), cx: &mut Context) { self.change_share_stage(cx, |stage| stage.pan_from = Some(position)); } pub fn pan_share_to(&mut self, position: (f32, f32), cx: &mut Context) { self.change_share_stage(cx, |stage| { let Some(from) = stage.pan_from.replace(position) else { return; }; let size = stage.size(); stage .view .pan_by((position.0 - from.0, position.1 - from.1), size); }); } pub fn end_share_pan(&mut self, cx: &mut Context) { self.change_share_stage(cx, |stage| stage.pan_from = None); } pub fn pop_out_stage(&mut self, cx: &mut Context) { self.change_share_stage(cx, |stage| stage.popped = true); } pub fn return_stage_from_pop_out(&mut self, cx: &mut Context) { self.change_share_stage(cx, |stage| stage.popped = false); } pub fn set_call_share_motion(&mut self, on: bool, cx: &mut Context) { self.call_share_motion = on; let _ = self.store.set_meta(SHARE_MOTION_META_KEY, flag_text(on)); self.send_call_command(CallCommand::SetShareMotion(on)); cx.notify(); } pub fn set_call_share_standout(&mut self, on: bool, cx: &mut Context) { self.call_share_standout = on; let _ = self.store.set_meta(SHARE_STANDOUT_META_KEY, flag_text(on)); self.send_call_command(CallCommand::SetShareStandout(on)); cx.notify(); } }