Skip to main content

ferroui_base/input/
holding_routed_event_args.rs

1use super::{InputElement, PointerEventArgs, PointerType};
2use crate::interactivity::RoutedEventArgs;
3use crate::{ferro_routed_event_args, Point};
4
5/// Provides data for the holding event.
6#[derive(Clone)]
7pub struct HoldingRoutedEventArgs {
8    base: RoutedEventArgs,
9    holding_state: HoldingState,
10    position: Point,
11    pointer_type: PointerType,
12    pointer_event_args: PointerEventArgs,
13}
14
15ferro_routed_event_args!(HoldingRoutedEventArgs: RoutedEventArgs);
16
17impl HoldingRoutedEventArgs {
18    pub(crate) fn new(
19        holding_state: HoldingState,
20        position: Point,
21        pointer_type: PointerType,
22        pointer_event_args: &PointerEventArgs,
23    ) -> Self {
24        Self {
25            base: RoutedEventArgs::with_event(InputElement::holding_event()),
26            holding_state,
27            position,
28            pointer_type,
29            pointer_event_args: pointer_event_args.clone(),
30        }
31    }
32
33    /// The state of the holding gesture.
34    #[inline]
35    pub fn holding_state(&self) -> HoldingState {
36        self.holding_state
37    }
38
39    /// The location of the touch, mouse, or pen/stylus contact.
40    #[inline]
41    pub fn position(&self) -> Point {
42        self.position
43    }
44
45    /// The pointer type of the input source.
46    #[inline]
47    pub fn pointer_type(&self) -> PointerType {
48        self.pointer_type
49    }
50
51    pub fn pointer_event_args(&self) -> &PointerEventArgs {
52        &self.pointer_event_args
53    }
54}
55
56/// The state of a holding gesture.
57#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
58pub enum HoldingState {
59    /// A single contact has been detected and a time threshold is crossed
60    /// without the contact being lifted, another contact detected, or
61    /// another gesture started.
62    Started,
63    /// The single contact is lifted.
64    Completed,
65    /// An additional contact is detected or a subsequent gesture (such as a
66    /// slide) is detected.
67    Canceled,
68}