Skip to main content

egui/data/input/
touch.rs

1/// this is a `u64` as values of this kind can always be obtained by hashing
2#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
3#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
4pub struct TouchDeviceId(pub u64);
5
6/// Unique identification of a touch occurrence (finger or pen or …).
7/// A Touch ID is valid until the finger is lifted.
8/// A new ID is used for the next touch.
9#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
10#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
11pub struct TouchId(pub u64);
12
13/// In what phase a touch event is in.
14#[derive(Clone, Copy, Debug, Eq, PartialEq)]
15#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
16pub enum TouchPhase {
17    /// User just placed a touch point on the touch surface
18    Start,
19
20    /// User moves a touch point along the surface. This event is also sent when
21    /// any attributes (position, force, …) of the touch point change.
22    Move,
23
24    /// User lifted the finger or pen from the surface, or slid off the edge of
25    /// the surface
26    End,
27
28    /// Touch operation has been disrupted by something (various reasons are possible,
29    /// maybe a pop-up alert or any other kind of interruption which may not have
30    /// been intended by the user)
31    Cancel,
32}
33
34impl From<u64> for TouchId {
35    fn from(id: u64) -> Self {
36        Self(id)
37    }
38}
39
40impl From<i32> for TouchId {
41    fn from(id: i32) -> Self {
42        Self(id as u64)
43    }
44}
45
46impl From<u32> for TouchId {
47    fn from(id: u32) -> Self {
48        Self(id as u64)
49    }
50}