Skip to main content

euv_core/event/handler/
struct.rs

1use crate::*;
2
3/// A wrapper around an event callback.
4///
5/// Stores the event name and a reference-counted mutable closure.
6#[derive(CustomDebug, Data)]
7pub struct NativeEventHandler {
8    /// The name of the event (e.g., "click", "input").
9    #[get(pub(crate))]
10    #[set(pub(crate))]
11    pub(crate) event_name: String,
12    /// The callback function to invoke when the event fires.
13    #[debug(skip)]
14    #[get(pub(crate))]
15    #[set(pub(crate))]
16    pub(crate) callback: Rc<RefCell<dyn FnMut(NativeEvent)>>,
17}
18
19/// Data associated with a mouse event.
20///
21/// Captures coordinates, buttons, and modifier key states.
22#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
23pub struct NativeMouseEvent {
24    /// The X coordinate relative to the viewport.
25    #[get(pub, type(copy))]
26    #[set(pub)]
27    pub(crate) client_x: i32,
28    /// The Y coordinate relative to the viewport.
29    #[get(pub, type(copy))]
30    #[set(pub)]
31    pub(crate) client_y: i32,
32    /// The X coordinate relative to the screen.
33    #[get(pub, type(copy))]
34    #[set(pub)]
35    pub(crate) screen_x: i32,
36    /// The Y coordinate relative to the screen.
37    #[get(pub, type(copy))]
38    #[set(pub)]
39    pub(crate) screen_y: i32,
40    /// Which mouse button was pressed.
41    #[get(pub, type(copy))]
42    #[set(pub)]
43    pub(crate) button: i16,
44    /// Bitmask of pressed buttons.
45    #[get(pub, type(copy))]
46    #[set(pub)]
47    pub(crate) buttons: u16,
48    /// Whether the ctrl key was pressed.
49    #[get(pub, type(copy))]
50    #[set(pub)]
51    pub(crate) ctrl_key: bool,
52    /// Whether the shift key was pressed.
53    #[get(pub, type(copy))]
54    #[set(pub)]
55    pub(crate) shift_key: bool,
56    /// Whether the alt key was pressed.
57    #[get(pub, type(copy))]
58    #[set(pub)]
59    pub(crate) alt_key: bool,
60    /// Whether the meta key was pressed.
61    #[get(pub, type(copy))]
62    #[set(pub)]
63    pub(crate) meta_key: bool,
64}
65
66/// Data associated with an input event.
67///
68/// Contains the current value and the type of input change.
69#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
70pub struct NativeInputEvent {
71    /// The current value of the input element.
72    #[get(pub)]
73    #[set(pub)]
74    value: String,
75    /// The type of input (e.g., "insertText", "deleteContentBackward").
76    #[get(pub)]
77    #[set(pub)]
78    input_type: String,
79}
80
81/// Data associated with a keyboard event.
82///
83/// Captures the pressed key, physical code, location, and modifier states.
84#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
85pub struct NativeKeyboardEvent {
86    /// The key that was pressed.
87    #[get(pub)]
88    #[set(pub)]
89    pub(crate) key: String,
90    /// The numeric code of the key.
91    #[get(pub)]
92    #[set(pub)]
93    pub(crate) code: String,
94    /// The physical key location.
95    #[get(pub, type(copy))]
96    #[set(pub)]
97    pub(crate) location: u32,
98    /// Whether the ctrl key was pressed.
99    #[get(pub, type(copy))]
100    #[set(pub)]
101    pub(crate) ctrl_key: bool,
102    /// Whether the shift key was pressed.
103    #[get(pub, type(copy))]
104    #[set(pub)]
105    pub(crate) shift_key: bool,
106    /// Whether the alt key was pressed.
107    #[get(pub, type(copy))]
108    #[set(pub)]
109    pub(crate) alt_key: bool,
110    /// Whether the meta key was pressed.
111    #[get(pub, type(copy))]
112    #[set(pub)]
113    pub(crate) meta_key: bool,
114    /// Whether the key is being held down.
115    #[get(pub, type(copy))]
116    #[set(pub)]
117    pub(crate) repeat: bool,
118}
119
120/// Data associated with a focus event.
121///
122/// Indicates whether the element is gaining or losing focus.
123#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
124pub struct NativeFocusEvent {
125    /// Whether the element is receiving focus.
126    #[get(pub, type(copy))]
127    #[set(pub)]
128    is_focus: bool,
129    /// Whether the element is losing focus.
130    #[get(pub, type(copy))]
131    #[set(pub)]
132    is_blur: bool,
133}
134
135/// Data associated with a form submit event.
136///
137/// Identifies the element that triggered the submission.
138#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
139pub struct NativeSubmitEvent {
140    /// The submitter element identifier.
141    #[get(pub)]
142    #[set(pub)]
143    submitter: Option<String>,
144}
145
146/// Data associated with a change event.
147///
148/// Contains the new value and checked state for form controls.
149#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
150pub struct NativeChangeEvent {
151    /// The new value after the change.
152    #[get(pub)]
153    #[set(pub)]
154    value: String,
155    /// Whether the element is checked (for checkboxes/radios).
156    #[get(pub, type(copy))]
157    #[set(pub)]
158    checked: bool,
159}
160
161/// Data associated with a drag event.
162///
163/// Captures the drag position and available data transfer types.
164#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
165pub struct NativeDragEvent {
166    /// The X coordinate of the drag.
167    #[get(pub, type(copy))]
168    #[set(pub)]
169    client_x: i32,
170    /// The Y coordinate of the drag.
171    #[get(pub, type(copy))]
172    #[set(pub)]
173    client_y: i32,
174    /// The data transfer types available.
175    #[get(pub)]
176    #[set(pub)]
177    types: Vec<String>,
178}
179
180/// Data associated with a touch event.
181///
182/// Captures the number of touch points and the first touch coordinates.
183#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
184pub struct NativeTouchEvent {
185    /// The number of touch points.
186    #[get(pub, type(copy))]
187    #[set(pub)]
188    touches_count: u32,
189    /// The X coordinate of the first touch.
190    #[get(pub, type(copy))]
191    #[set(pub)]
192    client_x: i32,
193    /// The Y coordinate of the first touch.
194    #[get(pub, type(copy))]
195    #[set(pub)]
196    client_y: i32,
197}
198
199/// Data associated with a wheel event.
200///
201/// Captures scroll deltas and the delta mode.
202#[derive(Clone, Data, Debug, Default, New, PartialEq)]
203pub struct NativeWheelEvent {
204    /// Horizontal scroll delta.
205    #[get(pub, type(copy))]
206    #[set(pub)]
207    delta_x: f64,
208    /// Vertical scroll delta.
209    #[get(pub, type(copy))]
210    #[set(pub)]
211    delta_y: f64,
212    /// Scroll delta mode.
213    #[get(pub, type(copy))]
214    #[set(pub)]
215    delta_mode: u32,
216}
217
218/// Data associated with a clipboard event.
219///
220/// Contains the clipboard text data if available.
221#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
222pub struct NativeClipboardEvent {
223    /// The clipboard data if available.
224    #[get(pub)]
225    #[set(pub)]
226    data: Option<String>,
227}
228
229/// Data associated with a media event.
230///
231/// Identifies the type of media event that occurred.
232#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
233pub struct NativeMediaEvent {
234    /// The type of media event (e.g., "play", "pause", "ended").
235    #[get(pub)]
236    #[set(pub)]
237    event_type: String,
238}