plushie_core/pointer.rs
1//! Typed pointer event data for the wire protocol.
2//!
3//! These structs represent the data payload of pointer and viewport
4//! events. They are shared between the SDK (which parses them from
5//! wire JSON) and could be used by the renderer to construct events
6//! with typed fields.
7
8use crate::key::{Key, MouseButton, PointerKind};
9use crate::protocol::KeyModifiers;
10
11/// Data from a pointer press event (mouse button down, touch start).
12#[derive(Debug, Clone)]
13pub struct PointerPress {
14 /// X coordinate.
15 pub x: f32,
16 /// Y coordinate.
17 pub y: f32,
18 /// Pointer button.
19 pub button: MouseButton,
20 /// Pointer kind (Mouse, Touch, Pen).
21 pub pointer: PointerKind,
22 /// Finger index for multi-touch events.
23 pub finger: Option<u64>,
24 /// Active modifier keys.
25 pub modifiers: KeyModifiers,
26 /// Whether the event was consumed by a widget before reaching the
27 /// global subscription layer.
28 pub captured: bool,
29}
30
31/// Data from a pointer release event (mouse button up, touch end).
32#[derive(Debug, Clone)]
33pub struct PointerRelease {
34 /// X coordinate.
35 pub x: f32,
36 /// Y coordinate.
37 pub y: f32,
38 /// Pointer button.
39 pub button: MouseButton,
40 /// Pointer kind (Mouse, Touch, Pen).
41 pub pointer: PointerKind,
42 /// Finger index for multi-touch events.
43 pub finger: Option<u64>,
44 /// Active modifier keys.
45 pub modifiers: KeyModifiers,
46 /// Whether the event was consumed by a widget before reaching the
47 /// global subscription layer.
48 pub captured: bool,
49 /// Whether a touch release happened outside the widget's bounds
50 /// (touch `lost` event). Absent for mouse / pen releases.
51 pub lost: Option<bool>,
52}
53
54/// Data from a pointer move event.
55#[derive(Debug, Clone)]
56pub struct PointerMove {
57 /// X coordinate.
58 pub x: f32,
59 /// Y coordinate.
60 pub y: f32,
61 /// Pointer kind (Mouse, Touch, Pen).
62 pub pointer: PointerKind,
63 /// Finger index for multi-touch events.
64 pub finger: Option<u64>,
65 /// Active modifier keys.
66 pub modifiers: KeyModifiers,
67 /// Whether the event was consumed by a widget before reaching the
68 /// global subscription layer.
69 pub captured: bool,
70}
71
72/// Data from a raw scroll input event (mouse wheel, trackpad).
73///
74/// Distinct from [`ScrollPosition`] which reports where a scrollable
75/// widget's viewport ended up. This reports the raw pointer input.
76#[derive(Debug, Clone)]
77pub struct PointerScroll {
78 /// X coordinate.
79 pub x: f32,
80 /// Y coordinate.
81 pub y: f32,
82 /// Scroll delta on the X axis.
83 pub delta_x: f32,
84 /// Scroll delta on the Y axis.
85 pub delta_y: f32,
86 /// Pointer kind (Mouse, Touch, Pen).
87 pub pointer: PointerKind,
88 /// Active modifier keys.
89 pub modifiers: KeyModifiers,
90 /// Whether the event was consumed by a widget before reaching the
91 /// global subscription layer.
92 pub captured: bool,
93}
94
95/// Data from a pointer enter / exit event.
96///
97/// Coordinates are populated when the event originates from a canvas
98/// element (where they carry meaning) and `None` for widget-level
99/// enter / exit (where they don't).
100#[derive(Debug, Clone, Default)]
101pub struct PointerBoundary {
102 /// X coordinate (canvas sources only).
103 pub x: Option<f32>,
104 /// Y coordinate (canvas sources only).
105 pub y: Option<f32>,
106 /// Whether the event was consumed by a widget before reaching the
107 /// global subscription layer.
108 pub captured: bool,
109}
110
111/// Data from a drag event.
112#[derive(Debug, Clone)]
113pub struct PointerDrag {
114 /// X coordinate.
115 pub x: f32,
116 /// Y coordinate.
117 pub y: f32,
118 /// Pointer kind (Mouse, Touch, Pen).
119 pub pointer: PointerKind,
120 /// Active modifier keys.
121 pub modifiers: KeyModifiers,
122 /// Whether the event was consumed by a widget before reaching the
123 /// global subscription layer.
124 pub captured: bool,
125}
126
127/// Viewport state from a scrollable widget's "scrolled" event.
128///
129/// Reports where the scrollable viewport ended up after scrolling.
130/// Distinct from [`PointerScroll`] which reports raw wheel input.
131#[derive(Debug, Clone)]
132pub struct ScrollPosition {
133 /// Absolute x.
134 pub absolute_x: f32,
135 /// Absolute y.
136 pub absolute_y: f32,
137 /// Relative x.
138 pub relative_x: f32,
139 /// Relative y.
140 pub relative_y: f32,
141 /// Bounds width.
142 pub bounds_width: f32,
143 /// Bounds height.
144 pub bounds_height: f32,
145 /// Content width.
146 pub content_width: f32,
147 /// Content height.
148 pub content_height: f32,
149}
150
151/// Data from a widget-level key press or release event.
152#[derive(Debug, Clone)]
153pub struct KeyData {
154 /// The logical key (typed enum with aliases).
155 pub key: Key,
156 /// Key after modifier application (e.g., Shift+a produces 'A').
157 pub modified_key: Option<Key>,
158 /// Physical key code (layout-independent).
159 pub physical_key: Option<Key>,
160 /// Active modifier keys.
161 pub modifiers: KeyModifiers,
162 /// Text generated by the key press, if any.
163 pub text: Option<String>,
164 /// Whether this is an auto-repeat event.
165 pub repeat: bool,
166}
167
168/// Data from a window or widget resize event.
169#[derive(Debug, Clone, Copy)]
170pub struct ResizeDimensions {
171 /// Width in pixels.
172 pub width: f32,
173 /// Height in pixels.
174 pub height: f32,
175}