Skip to main content

viewport_lib/interaction/input/
event.rs

1//! 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    /// Delta in viewport pages (one unit = viewport height).
22    Pages,
23}
24
25/// An event delivered to the viewport input pipeline.
26///
27/// Host applications translate their native windowing events into
28/// `ViewportEvent` values and push them to [`crate::camera::controllers::orbit::OrbitCameraController`]
29/// (or [`super::viewport_input::ViewportInput`] for direct input handling).
30#[non_exhaustive]
31#[derive(Debug, Clone)]
32pub enum ViewportEvent {
33    /// The pointer moved to the given viewport-local position.
34    PointerMoved {
35        /// Viewport-local position in logical pixels, origin at top-left.
36        position: glam::Vec2,
37    },
38    /// A mouse button was pressed or released.
39    MouseButton {
40        /// Which button changed state.
41        button: MouseButton,
42        /// New button state.
43        state: ButtonState,
44    },
45    /// The scroll wheel moved.
46    Wheel {
47        /// Scroll delta. Positive Y = scroll up / zoom in (conventional).
48        delta: glam::Vec2,
49        /// Whether the delta is in lines or pixels.
50        units: ScrollUnits,
51    },
52    /// A keyboard key changed state.
53    Key {
54        /// Which key changed state.
55        key: KeyCode,
56        /// New key state.
57        state: ButtonState,
58        /// True if the event is a key-repeat (key held down).
59        repeat: bool,
60    },
61    /// Modifier key state changed.
62    ModifiersChanged(Modifiers),
63    /// The pointer left the viewport area.
64    PointerLeft,
65    /// The viewport lost keyboard focus.
66    FocusLost,
67    /// A character was typed (Unicode).
68    ///
69    /// Only push this event when the manipulation controller is active
70    /// (`ManipulationController::is_active()`) to avoid swallowing other keypresses.
71    /// The library filters the character stream to digits, `.`, and `-` before
72    /// passing it to the numeric input buffer.
73    Character(char),
74
75    /// Two-finger trackpad rotation gesture.
76    ///
77    /// `delta` is the change in angle this event, in radians.
78    /// Positive = counter-clockwise (matches winit's `RotationGesture` convention,
79    /// converted from degrees to radians by the host).
80    ///
81    /// ## Platform-specific
82    /// Only emitted on macOS (and iOS). Silently unused on Windows and Linux.
83    TrackpadRotate(f32),
84}