Skip to main content

runmat_plot/core/
interaction.rs

1//! Event handling and user interaction for interactive plots
2//!
3//! Manages mouse, keyboard, and touch input for plot navigation
4//! and data interaction.
5
6use glam::Vec2;
7
8/// Keyboard modifier keys captured alongside pointer events.
9#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
10pub struct Modifiers {
11    pub shift: bool,
12    pub ctrl: bool,
13    pub alt: bool,
14    pub meta: bool,
15}
16
17/// Event types for plot interaction
18#[derive(Debug, Clone)]
19pub enum PlotEvent {
20    MousePress {
21        position: Vec2,
22        button: MouseButton,
23        modifiers: Modifiers,
24    },
25    MouseRelease {
26        position: Vec2,
27        button: MouseButton,
28        modifiers: Modifiers,
29    },
30    MouseMove {
31        position: Vec2,
32        delta: Vec2,
33        modifiers: Modifiers,
34    },
35    /// Mouse wheel / trackpad scroll.
36    ///
37    /// `position` is the pointer location in the same coordinate space as other mouse events.
38    MouseWheel {
39        position: Vec2,
40        delta: Vec2,
41        modifiers: Modifiers,
42    },
43    KeyPress {
44        key: KeyCode,
45    },
46    KeyRelease {
47        key: KeyCode,
48    },
49    Resize {
50        width: u32,
51        height: u32,
52    },
53}
54
55/// Mouse button enumeration
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub enum MouseButton {
58    Left,
59    Right,
60    Middle,
61}
62
63/// Key code enumeration (subset for now)
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum KeyCode {
66    Escape,
67    Space,
68    Enter,
69    Tab,
70    Backspace,
71    Delete,
72    Home,
73    End,
74    PageUp,
75    PageDown,
76    ArrowUp,
77    ArrowDown,
78    ArrowLeft,
79    ArrowRight,
80    // Add more as needed
81}
82
83/// Event handler trait for plot interaction
84pub trait EventHandler {
85    fn handle_event(&mut self, event: PlotEvent) -> bool;
86}