Skip to main content

viewport_lib/interaction/input/
event.rs

1//! Framework-agnostic viewport events for the new input pipeline.
2
3use super::binding::{KeyCode, Modifiers, MouseButton};
4
5/// Button press or release state.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum ButtonState {
8    /// Button was pressed.
9    Pressed,
10    /// Button was released.
11    Released,
12}
13
14/// Scroll delta units.
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16pub enum ScrollUnits {
17    /// Delta in logical line units (one notch ≈ 1.0).
18    Lines,
19    /// Delta in physical pixels.
20    Pixels,
21}
22
23/// A framework-agnostic event delivered to the viewport input pipeline.
24///
25/// Host applications translate their native windowing events into
26/// `ViewportEvent` values and push them to [`super::controller::OrbitCameraController`]
27/// (or [`super::viewport_input::ViewportInput`] for the lower-level path).
28#[derive(Debug, Clone)]
29pub enum ViewportEvent {
30    /// The pointer moved to the given viewport-local position.
31    PointerMoved {
32        /// Viewport-local position in logical pixels, origin at top-left.
33        position: glam::Vec2,
34    },
35    /// A mouse button was pressed or released.
36    MouseButton {
37        /// Which button changed state.
38        button: MouseButton,
39        /// New button state.
40        state: ButtonState,
41    },
42    /// The scroll wheel moved.
43    Wheel {
44        /// Scroll delta. Positive Y = scroll up / zoom in (conventional).
45        delta: glam::Vec2,
46        /// Whether the delta is in lines or pixels.
47        units: ScrollUnits,
48    },
49    /// A keyboard key changed state.
50    Key {
51        /// Which key changed state.
52        key: KeyCode,
53        /// New key state.
54        state: ButtonState,
55        /// True if the event is a key-repeat (key held down).
56        repeat: bool,
57    },
58    /// Modifier key state changed.
59    ModifiersChanged(Modifiers),
60    /// The pointer left the viewport area.
61    PointerLeft,
62    /// The viewport lost keyboard focus.
63    FocusLost,
64}