Skip to main content

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