Skip to main content

ferroui_base/input/
pull_gesture_event_args.rs

1use super::InputElement;
2use crate::interactivity::RoutedEventArgs;
3use crate::{ferro_routed_event_args, Vector};
4use std::sync::atomic::{AtomicI32, Ordering};
5
6static NEXT_ID: AtomicI32 = AtomicI32::new(1);
7
8/// Provides data for the pull gesture event.
9#[derive(Clone)]
10pub struct PullGestureEventArgs {
11    base: RoutedEventArgs,
12    id: i32,
13    delta: Vector,
14    pull_direction: PullDirection,
15}
16
17ferro_routed_event_args!(PullGestureEventArgs: RoutedEventArgs);
18
19impl PullGestureEventArgs {
20    /// Creates pull gesture event args.
21    pub fn new(id: i32, delta: Vector, pull_direction: PullDirection) -> Self {
22        Self {
23            base: RoutedEventArgs::with_event(InputElement::pull_gesture_event()),
24            id,
25            delta,
26            pull_direction,
27        }
28    }
29
30    #[doc(hidden)]
31    pub fn get_next_free_id() -> i32 {
32        NEXT_ID.fetch_add(1, Ordering::Relaxed)
33    }
34
35    /// The identifier of the gesture.
36    #[inline]
37    pub fn id(&self) -> i32 {
38        self.id
39    }
40
41    /// The distance pulled so far.
42    #[inline]
43    pub fn delta(&self) -> Vector {
44        self.delta
45    }
46
47    /// The direction of the pull.
48    #[inline]
49    pub fn pull_direction(&self) -> PullDirection {
50        self.pull_direction
51    }
52}
53
54/// Provides data for the pull gesture ended event.
55#[derive(Clone)]
56pub struct PullGestureEndedEventArgs {
57    base: RoutedEventArgs,
58    id: i32,
59    pull_direction: PullDirection,
60}
61
62ferro_routed_event_args!(PullGestureEndedEventArgs: RoutedEventArgs);
63
64impl PullGestureEndedEventArgs {
65    /// Creates pull gesture ended event args.
66    pub fn new(id: i32, pull_direction: PullDirection) -> Self {
67        Self { base: RoutedEventArgs::with_event(InputElement::pull_gesture_ended_event()), id, pull_direction }
68    }
69
70    /// The identifier of the gesture.
71    #[inline]
72    pub fn id(&self) -> i32 {
73        self.id
74    }
75
76    /// The direction of the pull.
77    #[inline]
78    pub fn pull_direction(&self) -> PullDirection {
79        self.pull_direction
80    }
81}
82
83/// The direction of a pull gesture.
84#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
85pub enum PullDirection {
86    TopToBottom,
87    BottomToTop,
88    LeftToRight,
89    RightToLeft,
90}