Skip to main content

ferroui_base/input/
pinch_event_args.rs

1use super::InputElement;
2use crate::interactivity::RoutedEventArgs;
3use crate::{ferro_routed_event_args, Point};
4
5/// Provides data for the pinch gesture event.
6#[derive(Clone)]
7pub struct PinchEventArgs {
8    base: RoutedEventArgs,
9    scale: f64,
10    scale_origin: Point,
11    angle: f64,
12    angle_delta: f64,
13}
14
15ferro_routed_event_args!(PinchEventArgs: RoutedEventArgs);
16
17impl PinchEventArgs {
18    /// Creates pinch event args with a scale and its origin.
19    pub fn new(scale: f64, scale_origin: Point) -> Self {
20        Self::with_angle(scale, scale_origin, 0.0, 0.0)
21    }
22
23    /// Creates pinch event args with a scale, its origin and the angle of
24    /// the gesture.
25    pub fn with_angle(scale: f64, scale_origin: Point, angle: f64, angle_delta: f64) -> Self {
26        Self {
27            base: RoutedEventArgs::with_event(InputElement::pinch_event()),
28            scale,
29            scale_origin,
30            angle,
31            angle_delta,
32        }
33    }
34
35    /// The scale of the pinch relative to its start.
36    #[inline]
37    pub fn scale(&self) -> f64 {
38        self.scale
39    }
40
41    /// The origin of the scale.
42    #[inline]
43    pub fn scale_origin(&self) -> Point {
44        self.scale_origin
45    }
46
47    /// The angle of the pinch gesture, in degrees.
48    ///
49    /// A pinch gesture is the movement of two pressed points closer
50    /// together. This property is the measured angle of the line between
51    /// those two points. Remember zero degrees is a line pointing up.
52    #[inline]
53    pub fn angle(&self) -> f64 {
54        self.angle
55    }
56
57    /// The difference from the previous and current pinch angle.
58    ///
59    /// The value includes the sign of rotation: positive for clockwise,
60    /// negative counterclockwise.
61    #[inline]
62    pub fn angle_delta(&self) -> f64 {
63        self.angle_delta
64    }
65}
66
67/// Provides data for the pinch ended event.
68#[derive(Clone)]
69pub struct PinchEndedEventArgs {
70    base: RoutedEventArgs,
71}
72
73ferro_routed_event_args!(PinchEndedEventArgs: RoutedEventArgs);
74
75impl Default for PinchEndedEventArgs {
76    fn default() -> Self {
77        Self::new()
78    }
79}
80
81impl PinchEndedEventArgs {
82    /// Creates pinch ended event args.
83    pub fn new() -> Self {
84        Self { base: RoutedEventArgs::with_event(InputElement::pinch_ended_event()) }
85    }
86}