mouse_codes/types/
event.rs

1use std::fmt;
2
3use super::Button;
4
5/// Mouse event type
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub enum MouseEvent {
9    /// Button press event
10    Press(Button),
11    /// Button release event
12    Release(Button),
13    /// Scroll event with direction and amount
14    Scroll(ScrollDirection, i32),
15    /// Mouse movement event (x, y coordinates)
16    Move(i32, i32),
17    /// Mouse movement relative to previous position (dx, dy)
18    RelativeMove(i32, i32),
19}
20
21/// Scroll direction enumeration
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
24pub enum ScrollDirection {
25    /// Vertical scroll up
26    VerticalUp,
27    /// Vertical scroll down
28    VerticalDown,
29    /// Horizontal scroll left
30    HorizontalLeft,
31    /// Horizontal scroll right
32    HorizontalRight,
33}
34
35impl fmt::Display for ScrollDirection {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        match self {
38            ScrollDirection::VerticalUp => write!(f, "VerticalUp"),
39            ScrollDirection::VerticalDown => write!(f, "VerticalDown"),
40            ScrollDirection::HorizontalLeft => write!(f, "HorizontalLeft"),
41            ScrollDirection::HorizontalRight => write!(f, "HorizontalRight"),
42        }
43    }
44}
45
46impl fmt::Display for MouseEvent {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        match self {
49            MouseEvent::Press(button) => write!(f, "Press({})", button),
50            MouseEvent::Release(button) => write!(f, "Release({})", button),
51            MouseEvent::Scroll(dir, amount) => write!(f, "Scroll({}, {})", dir, amount),
52            MouseEvent::Move(x, y) => write!(f, "Move({}, {})", x, y),
53            MouseEvent::RelativeMove(dx, dy) => write!(f, "RelativeMove({}, {})", dx, dy),
54        }
55    }
56}