anathema_widgets/components/events/
mouse.rs1use anathema_geometry::Pos;
2
3#[derive(Debug, Copy, Clone, PartialEq)]
4pub struct MouseEvent {
5 pub x: u16,
6 pub y: u16,
7 pub state: MouseState,
8}
9
10impl MouseEvent {
11 pub fn pos(&self) -> Pos {
13 (self.x, self.y).into()
14 }
15
16 pub fn left_down(&self) -> bool {
18 matches!(self.state, MouseState::Down(MouseButton::Left))
19 }
20
21 pub fn right_down(&self) -> bool {
23 matches!(self.state, MouseState::Down(MouseButton::Right))
24 }
25
26 pub fn middle_down(&self) -> bool {
28 matches!(self.state, MouseState::Down(MouseButton::Middle))
29 }
30
31 pub fn is_left_down(&self) -> bool {
33 matches!(
34 self.state,
35 MouseState::Down(MouseButton::Left) | MouseState::Drag(MouseButton::Left)
36 )
37 }
38
39 pub fn is_right_down(&self) -> bool {
41 matches!(
42 self.state,
43 MouseState::Down(MouseButton::Right) | MouseState::Drag(MouseButton::Right)
44 )
45 }
46
47 pub fn is_middle_down(&self) -> bool {
49 matches!(
50 self.state,
51 MouseState::Down(MouseButton::Middle) | MouseState::Drag(MouseButton::Middle)
52 )
53 }
54
55 pub fn left_up(&self) -> bool {
57 matches!(self.state, MouseState::Up(MouseButton::Left))
58 }
59
60 pub fn right_up(&self) -> bool {
62 matches!(self.state, MouseState::Up(MouseButton::Right))
63 }
64
65 pub fn middle_up(&self) -> bool {
67 matches!(self.state, MouseState::Up(MouseButton::Middle))
68 }
69}
70
71#[derive(Debug, Copy, Clone, PartialEq)]
72pub enum MouseState {
73 Down(MouseButton),
74 Up(MouseButton),
75 Drag(MouseButton),
76 Move,
77 ScrollUp,
78 ScrollDown,
79 ScrollLeft,
80 ScrollRight,
81}
82
83#[derive(Debug, Copy, Clone, PartialEq)]
84pub enum MouseButton {
85 Left,
86 Middle,
87 Right,
88}