ferroui_base/input/
swipe_gesture_event_args.rs1use super::{InputElement, SwipeDirection};
2use crate::interactivity::RoutedEventArgs;
3use crate::{ferro_routed_event_args, Vector};
4use std::sync::atomic::{AtomicI32, Ordering};
5
6static NEXT_ID: AtomicI32 = AtomicI32::new(0);
7
8#[derive(Clone)]
10pub struct SwipeGestureEventArgs {
11 base: RoutedEventArgs,
12 id: i32,
13 delta: Vector,
14 velocity: Vector,
15 swipe_direction: SwipeDirection,
16}
17
18ferro_routed_event_args!(SwipeGestureEventArgs: RoutedEventArgs);
19
20impl SwipeGestureEventArgs {
21 pub fn new(id: i32, delta: Vector, velocity: Vector) -> Self {
27 let swipe_direction = if delta.x.abs() >= delta.y.abs() {
28 if delta.x <= 0.0 {
29 SwipeDirection::Right
30 } else {
31 SwipeDirection::Left
32 }
33 } else if delta.y <= 0.0 {
34 SwipeDirection::Down
35 } else {
36 SwipeDirection::Up
37 };
38
39 Self {
40 base: RoutedEventArgs::with_event(InputElement::swipe_gesture_event()),
41 id,
42 delta,
43 velocity,
44 swipe_direction,
45 }
46 }
47
48 #[inline]
50 pub fn id(&self) -> i32 {
51 self.id
52 }
53
54 #[inline]
56 pub fn delta(&self) -> Vector {
57 self.delta
58 }
59
60 #[inline]
62 pub fn velocity(&self) -> Vector {
63 self.velocity
64 }
65
66 #[inline]
68 pub fn swipe_direction(&self) -> SwipeDirection {
69 self.swipe_direction
70 }
71
72 #[allow(dead_code)]
73 pub(crate) fn get_next_free_id() -> i32 {
74 NEXT_ID.fetch_add(1, Ordering::Relaxed) + 1
75 }
76}
77
78#[derive(Clone)]
80pub struct SwipeGestureEndedEventArgs {
81 base: RoutedEventArgs,
82 id: i32,
83 velocity: Vector,
84}
85
86ferro_routed_event_args!(SwipeGestureEndedEventArgs: RoutedEventArgs);
87
88impl SwipeGestureEndedEventArgs {
89 pub fn new(id: i32, velocity: Vector) -> Self {
94 Self { base: RoutedEventArgs::with_event(InputElement::swipe_gesture_ended_event()), id, velocity }
95 }
96
97 #[inline]
99 pub fn id(&self) -> i32 {
100 self.id
101 }
102
103 #[inline]
105 pub fn velocity(&self) -> Vector {
106 self.velocity
107 }
108}