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    #[set(pub(crate))]
10    pub(crate) event_name: String,
11    /// The callback function to invoke when the event fires.
12    #[get(pub(crate))]
13    #[set(pub(crate))]
14    pub(crate) callback: Rc<RefCell<dyn FnMut(NativeEvent)>>,
15}
16
17/// Data associated with a mouse event.
18///
19/// Captures coordinates, buttons, and modifier key states.
20#[derive(Data, Default)]
21pub struct NativeMouseEvent {
22    /// The X coordinate relative to the viewport.
23    pub(crate) client_x: i32,
24    /// The Y coordinate relative to the viewport.
25    pub(crate) client_y: i32,
26    /// The X coordinate relative to the screen.
27    pub(crate) screen_x: i32,
28    /// The Y coordinate relative to the screen.
29    pub(crate) screen_y: i32,
30    /// Which mouse button was pressed.
31    pub(crate) button: i16,
32    /// Bitmask of pressed buttons.
33    pub(crate) buttons: u16,
34    /// Whether the ctrl key was pressed.
35    pub(crate) ctrl_key: bool,
36    /// Whether the shift key was pressed.
37    pub(crate) shift_key: bool,
38    /// Whether the alt key was pressed.
39    pub(crate) alt_key: bool,
40    /// Whether the meta key was pressed.
41    pub(crate) meta_key: bool,
42}
43
44/// Data associated with an input event.
45///
46/// Contains the current value and the type of input change.
47#[derive(Data, Default)]
48pub struct NativeInputEvent {
49    /// The current value of the input element.
50    value: String,
51    /// The type of input (e.g., "insertText", "deleteContentBackward").
52    input_type: String,
53}
54
55/// Data associated with a keyboard event.
56///
57/// Captures the pressed key, physical code, location, and modifier states.
58#[derive(Data, Default)]
59pub struct NativeKeyboardEvent {
60    /// The key that was pressed.
61    pub(crate) key: String,
62    /// The numeric code of the key.
63    pub(crate) code: String,
64    /// The physical key location.
65    pub(crate) location: u32,
66    /// Whether the ctrl key was pressed.
67    pub(crate) ctrl_key: bool,
68    /// Whether the shift key was pressed.
69    pub(crate) shift_key: bool,
70    /// Whether the alt key was pressed.
71    pub(crate) alt_key: bool,
72    /// Whether the meta key was pressed.
73    pub(crate) meta_key: bool,
74    /// Whether the key is being held down.
75    pub(crate) repeat: bool,
76}
77
78/// Data associated with a focus event.
79///
80/// Indicates whether the element is gaining or losing focus.
81#[derive(Data, Default)]
82pub struct NativeFocusEvent {
83    /// Whether the element is receiving focus.
84    is_focus: bool,
85    /// Whether the element is losing focus.
86    is_blur: bool,
87}
88
89/// Data associated with a form submit event.
90///
91/// Identifies the element that triggered the submission.
92#[derive(Data, Default)]
93pub struct NativeSubmitEvent {
94    /// The submitter element identifier.
95    submitter: Option<String>,
96}
97
98/// Data associated with a change event.
99///
100/// Contains the new value and checked state for form controls.
101#[derive(Data, Default)]
102pub struct NativeChangeEvent {
103    /// The new value after the change.
104    value: String,
105    /// Whether the element is checked (for checkboxes/radios).
106    checked: bool,
107}
108
109/// Data associated with a drag event.
110///
111/// Captures the drag position and available data transfer types.
112#[derive(Data, Default)]
113pub struct NativeDragEvent {
114    /// The X coordinate of the drag.
115    client_x: i32,
116    /// The Y coordinate of the drag.
117    client_y: i32,
118    /// The data transfer types available.
119    types: Vec<String>,
120}
121
122/// Data associated with a touch event.
123///
124/// Captures the number of touch points and the first touch coordinates.
125#[derive(Data, Default)]
126pub struct NativeTouchEvent {
127    /// The number of touch points.
128    touches_count: u32,
129    /// The X coordinate of the first touch.
130    client_x: i32,
131    /// The Y coordinate of the first touch.
132    client_y: i32,
133}
134
135/// Data associated with a wheel event.
136///
137/// Captures scroll deltas and the delta mode.
138#[derive(Data, Default)]
139pub struct NativeWheelEvent {
140    /// Horizontal scroll delta.
141    delta_x: f64,
142    /// Vertical scroll delta.
143    delta_y: f64,
144    /// Scroll delta mode.
145    delta_mode: u32,
146}
147
148/// Data associated with a clipboard event.
149///
150/// Contains the clipboard text data if available.
151#[derive(Data, Default)]
152pub struct NativeClipboardEvent {
153    /// The clipboard data if available.
154    data: Option<String>,
155}
156
157/// Data associated with a media event.
158///
159/// Identifies the type of media event that occurred.
160#[derive(Data, Default)]
161pub struct NativeMediaEvent {
162    /// The type of media event (e.g., "play", "pause", "ended").
163    event_type: String,
164}