pointer_types/lib.rs
1#![no_std]
2
3#[cfg(feature = "std")]
4extern crate std;
5
6pub mod mouse;
7pub mod pointer;
8pub mod wheel;
9
10pub use pointer::*;
11
12#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
13#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14pub enum PointerType {
15 #[default]
16 Mouse,
17 Stylus,
18 Touch,
19}
20
21/// Describes the state a button is in.
22#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
23#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24pub enum ButtonState {
25 /// The button is pressed down.
26 ///
27 /// Often emitted in a [mousedown] event, see also [the MDN documentation][mdn] on that.
28 ///
29 /// [mousedown]: https://w3c.github.io/pointerevents/#mousedown
30 /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Element/mousedown_event
31 #[default]
32 Down,
33 /// The button is not pressed / was just released.
34 ///
35 /// Often emitted in a [mouseup] event, see also [the MDN documentation][mdn] on that.
36 ///
37 /// [mouseup]: https://w3c.github.io/pointerevents/#mouseup
38 /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseup_event
39 Up,
40}
41
42impl ButtonState {
43 /// True if the button is pressed down.
44 pub const fn is_down(self) -> bool {
45 matches!(self, Self::Down)
46 }
47
48 /// True if the button is released.
49 pub const fn is_up(self) -> bool {
50 matches!(self, Self::Up)
51 }
52}