Skip to main content

pointer_types/
pointer.rs

1pub mod button;
2pub use button::*;
3use {
4  crate::{
5    ButtonState,
6    PointerType,
7    mouse::MouseEvent,
8  },
9  dpi::PhysicalPosition,
10  keyboard_types::Modifiers,
11};
12
13#[derive(Clone, Debug, PartialEq)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub enum PointerEvent {
16  Button {
17    /// The type of pointer that fired this event.
18    pointer: PointerType,
19    /// The position relative to the top-left of the client area.
20    position: PhysicalPosition<f64>,
21    /// Whether the button is pressed or released.
22    state: ButtonState,
23    /// Logical button value.
24    button: PointerButton,
25    /// Flags for pressed modifier keys.
26    modifiers: Modifiers,
27    /// Whether this event is a double click/tap.
28    is_double: bool,
29  },
30  Move {
31    /// The type of pointer that fired this event.
32    pointer: PointerType,
33    /// The position relative to the top-left of the client area.
34    position: PhysicalPosition<f64>,
35  },
36  Enter {
37    /// The type of pointer that fired this event.
38    pointer: PointerType,
39    /// The position relative to the top-left of the client area.
40    position: PhysicalPosition<f64>,
41  },
42  Leave {
43    /// The type of pointer that fired this event.
44    pointer: PointerType,
45    /// The position relative to the top-left of the client area.
46    position: PhysicalPosition<f64>,
47  },
48}
49
50impl PointerEvent {
51  pub fn mouse_event(self) -> Option<MouseEvent> {
52    self.try_into().ok()
53  }
54}