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