1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! Event types for the widget system.
//!
//! All coordinates in events are **first-quadrant (Y-up)** by the time any
//! widget code sees them. The single Y-down → Y-up conversion happens at the
//! platform boundary inside [`crate::widget::App`].
use crate::geometry::Point;
/// Which mouse button triggered a `MouseDown` or `MouseUp` event.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MouseButton {
Left,
Middle,
Right,
Other(u8),
}
/// Modifier keys held at the time of an event.
///
/// `meta` is the platform-specific "super" key: **Cmd** on macOS, **Super /
/// Windows key** on Linux, **Windows key** on Windows. Widgets that want
/// portable command shortcuts should use the runtime platform helpers rather
/// than treating `ctrl || meta` as universally equivalent.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Modifiers {
pub shift: bool,
pub ctrl: bool,
pub alt: bool,
pub meta: bool,
}
/// A logical keyboard key.
#[derive(Clone, Debug, PartialEq)]
pub enum Key {
/// A printable character, already translated through the keyboard layout.
Char(char),
Backspace,
Delete,
/// The `Insert` key. Paired with `Shift`/`Ctrl` for classic Windows
/// clipboard shortcuts (`Shift+Ins` paste, `Ctrl+Ins` copy).
Insert,
ArrowLeft,
ArrowRight,
ArrowUp,
ArrowDown,
Home,
End,
Tab,
Enter,
Escape,
/// Any key not in the above set — not usually handled, included for
/// completeness.
Other(String),
}
/// A GUI event delivered to a widget.
///
/// Coordinate positions are in the **local** coordinate space of the widget
/// receiving the event (bottom-left origin, Y-up). The framework translates
/// positions as it descends the widget tree.
#[derive(Clone, Debug)]
pub enum Event {
/// The cursor moved to `pos` (may be outside widget bounds — used to
/// clear hover state).
MouseMove { pos: Point },
/// A mouse button was pressed at `pos`.
MouseDown {
pos: Point,
button: MouseButton,
modifiers: Modifiers,
},
/// A mouse button was released at `pos`.
MouseUp {
pos: Point,
button: MouseButton,
modifiers: Modifiers,
},
/// A key was pressed while this widget (or a descendant) had focus.
KeyDown { key: Key, modifiers: Modifiers },
/// A key was released.
KeyUp { key: Key, modifiers: Modifiers },
/// Sent by the framework when this widget gains keyboard focus.
FocusGained,
/// Sent by the framework when this widget loses keyboard focus.
FocusLost,
/// Mouse wheel scrolled. Convention matches `winit` /
/// `WheelEvent` after the OS applies its natural-scroll
/// preference: **positive `delta_y` means the user wants to see
/// content ABOVE the current view** (wheel rotated forward on
/// Windows / wheel forward + natural-scroll on macOS). Scroll
/// containers should DECREASE their scroll offset when `delta_y`
/// is positive. `delta_x` follows the same sign rule for
/// horizontal scroll (positive = see content to the LEFT).
/// Magnitude is in logical pixels; line deltas should be
/// pre-scaled by the platform shell (~40 px per line).
MouseWheel {
pos: Point,
delta_y: f64,
delta_x: f64,
modifiers: Modifiers,
},
/// One or more files were dropped onto the window at `pos`.
///
/// `paths` is non-empty. Native windowing layers (winit) typically
/// emit one path per `WindowEvent::DroppedFile` — the framework
/// either forwards each as its own `FileDropped` event, or batches
/// drops within a single gesture into one event. Receivers should
/// not rely on batching behaviour: handle each path in the vec.
///
/// Coordinates follow the same convention as `MouseMove`/`MouseDown`:
/// widget-local Y-up. The cursor lives at `pos` at the moment of
/// drop, so widgets can spawn objects under the user's intent.
FileDropped {
pos: Point,
paths: Vec<std::path::PathBuf>,
},
}
/// What a widget returns from [`crate::widget::Widget::on_event`].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EventResult {
/// The widget handled the event; stop propagation.
Consumed,
/// The widget did not handle the event; continue bubbling up.
Ignored,
}