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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
use crate::drag::{DragPayload, DragPayloadKind, DragSessionId, DropCancelReason, DropEffect};
use crate::WidgetId;
use crate::{MenuId, MenuItemId};
#[cfg(feature = "async")]
use crate::async_ui::TaskEvent;
#[cfg(feature = "displays")]
use crate::displays::DisplayInfo;
use crate::motion::MotionId;
use crate::pickers::{FontDescriptor, FontEffects, Rgba};
use crate::theme::ThemeMode;
use crate::timer::TimerId;
use crate::toolbar::ToolId;
use crate::windowing::PopupDismissReason;
/// Dynamic accessibility updates requested by the shared UI layer.
///
/// These are backend notifications, not events delivered to the application.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AccessibleNotification {
/// A widget's numeric value changed.
ValueChanged,
/// A widget's text changed.
TextChanged,
/// Keyboard focus moved to a widget.
FocusChanged,
/// A short message should be announced by assistive technology.
Announcement(String),
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum UiEvent {
Clicked {
widget_id: WidgetId,
},
Toggled {
widget_id: WidgetId,
checked: bool,
},
TextChanged {
widget_id: WidgetId,
text: String,
},
SelectionChanged {
widget_id: WidgetId,
selected: Option<String>,
/// Position of the selection within the widget (list/combo/tab),
/// when the backend can report it. Prefer this over matching by
/// `selected` text, which is not unique.
index: Option<usize>,
},
/// Multi-select list/tree widgets report their selection set by row index.
MultiSelectionChanged {
widget_id: WidgetId,
indices: Vec<usize>,
},
/// A grid cell was clicked (DataGrid).
GridCellClicked {
widget_id: WidgetId,
row: usize,
col: usize,
},
/// A range of cells was selected (DataGrid).
GridSelectionChanged {
widget_id: WidgetId,
/// List of (row, col) tuples representing selected cells
selected_ranges: Vec<(usize, usize)>,
},
/// In-place editing started on a cell.
GridCellEditingStarted {
widget_id: WidgetId,
row: usize,
col: usize,
},
/// In-place editing finished on a cell.
GridCellEditingFinished {
widget_id: WidgetId,
row: usize,
col: usize,
new_value: String,
},
/// A row (list/tree widgets) or line (DataGrid) was activated via
/// double-click; `index` is the row/line position when the backend can
/// report it.
Activated {
widget_id: WidgetId,
index: Option<usize>,
},
TextSubmitted {
widget_id: WidgetId,
text: String,
},
/// The user accepted a `TextInput` completion suggestion.
///
/// Emitted at most once per popup session, when the user commits a
/// suggestion with Enter or a click. The application applies `text`
/// through [`crate::Ui::set_text`] and moves focus as it sees fit; a
/// popup closed without acceptance reports
/// [`UiEvent::SuggestionDismissed`] instead.
SuggestionSelected {
widget_id: WidgetId,
text: String,
},
/// The completion popup closed without acceptance: Escape,
/// blur, or a click elsewhere. Never follows a `SuggestionSelected` for
/// the same popup session.
SuggestionDismissed {
widget_id: WidgetId,
},
ValueChanged {
widget_id: WidgetId,
value: i32,
},
DateChanged {
widget_id: WidgetId,
iso_date: String,
},
LinkActivated {
widget_id: WidgetId,
url: String,
},
ProgressChanged {
widget_id: WidgetId,
value: f64,
},
MenuItemSelected {
menu_id: MenuId,
item_id: MenuItemId,
},
/// A programmatic confirm dialog (`Ui::show_confirm_dialog`) was answered;
/// `token` matches the value returned when the dialog was shown and
/// `confirmed` is the Yes/No outcome.
DialogResponse {
token: u64,
confirmed: bool,
},
/// A function-style file dialog (`Ui::show_file_dialog`) was answered;
/// `token` matches the value returned when it was shown. `paths` holds
/// the chosen file(s) or folder, and is empty when the user cancelled.
FileDialogResponse {
token: u64,
paths: Vec<std::path::PathBuf>,
},
/// Live colour preview from an open `ColorDialog`.
///
/// Capability-gated: lanes advertise whether the native chooser emits
/// previews, and a lane without one never sends this event. Receiving it
/// means the user is hovering a candidate colour — the dialog is still
/// open, so applications that render the candidate must restore their
/// previous state when the final [`UiEvent::ColorSelected`] is a cancel.
ColorChanged {
widget_id: WidgetId,
color: Rgba,
},
/// Final answer from a `ColorDialog`: the accepted colour, or
/// `None` when the user cancelled.
///
/// Exactly one of these is delivered per activation, and an accept also
/// refreshes the widget's `color_dialog_data.initial` so reopening starts
/// where the user finished.
ColorSelected {
widget_id: WidgetId,
color: Option<Rgba>,
},
/// Live font preview from an open `FontDialog`.
///
/// Capability-gated like [`UiEvent::ColorChanged`]: it arrives while the
/// dialog is open, so applications that render the candidate must restore
/// their previous state when the final selection is a cancel. The size is
/// already clamped to the dialog's configured range.
FontChanged {
widget_id: WidgetId,
descriptor: FontDescriptor,
},
/// Final answer from a `FontDialog`: the accepted descriptor and
/// effects, or `None` when the user cancelled.
///
/// Exactly one of these is delivered per activation. An accept refreshes
/// the widget's `font_dialog_data` (initial descriptor and effects) so
/// reopening starts where the user finished, with the shared size clamp
/// applied to the stored value.
FontSelected {
widget_id: WidgetId,
selection: Option<(FontDescriptor, FontEffects)>,
},
/// The user asked for help from a picker dialog whose lane offers a help
/// affordance (capability `font_dialog_help`).
HelpRequested {
widget_id: WidgetId,
},
/// A toolbar tool was activated by the user.
///
/// A checkable tool reports [`UiEvent::ToolToggled`] instead, a dropdown
/// tool reports [`UiEvent::ToolDropdown`], and a disabled or hidden tool
/// reports nothing — so a click produces exactly one of the three.
ToolActivated {
widget_id: WidgetId,
tool_id: ToolId,
},
/// A user toggled a checkable toolbar tool; `checked` is the new state.
///
/// One event is delivered per changed tool: checking a radio member
/// unchecks the previous member, which arrives as its own event in
/// toolbar order. Programmatic [`crate::Ui::set_tool_state`] never emits
/// these — it returns the changed tools to the caller instead.
ToolToggled {
widget_id: WidgetId,
tool_id: ToolId,
checked: bool,
},
/// The user asked a dropdown tool to open its menu.
///
/// The application composes the menu with the existing menu API after
/// receiving this event; the shared model never builds popup content.
ToolDropdown {
widget_id: WidgetId,
tool_id: ToolId,
},
/// The pointer entered (`Some`) or left (`None`) a toolbar tool
/// (capability-gated: lanes that cannot report hot-item changes
/// never send it).
ToolHovered {
widget_id: WidgetId,
tool_id: Option<ToolId>,
},
/// A toolbar tool was right-clicked, asking for a context menu.
ToolContext {
widget_id: WidgetId,
tool_id: ToolId,
},
/// A row drag began on a drag-enabled widget carrying the dragged row
/// indices (usually the current selection).
DragStarted {
widget_id: WidgetId,
indices: Vec<usize>,
},
/// Rows were dropped onto `target_index` of the receiving widget; the
/// app performs the move through its core model and refreshes.
Dropped {
widget_id: WidgetId,
target_index: usize,
source_indices: Vec<usize>,
},
/// External files were dropped onto a window or widget from the OS shell (e.g. Explorer, Finder, Nautilus).
FilesDropped {
widget_id: WidgetId,
paths: Vec<String>,
},
/// URLs dropped onto a window or widget (e.g. from an external browser or link drag).
UrlsDropped {
widget_id: WidgetId,
urls: Vec<String>,
offset: Option<usize>,
},
/// Plain text dropped onto a window or widget.
TextDropped {
widget_id: WidgetId,
text: String,
offset: Option<usize>,
},
/// A text/custom-MIME drag session began on a configured source.
DragSessionStarted {
widget_id: WidgetId,
session: DragSessionId,
kinds: Vec<DragPayloadKind>,
},
/// A drag session entered a configured target with compatible MIME kinds.
DragEntered {
target: WidgetId,
session: DragSessionId,
position: (i32, i32),
offered: Vec<String>,
},
/// The pointer moved over the current drag target.
DragMoved {
target: WidgetId,
session: DragSessionId,
position: (i32, i32),
},
/// The pointer left a drag target before drop or cancellation.
DragExited {
target: WidgetId,
session: DragSessionId,
},
/// A payload was delivered to a compatible target and the session ended.
DragDropped {
target: WidgetId,
session: DragSessionId,
position: (i32, i32),
payload: DragPayload,
effect: DropEffect,
},
/// A drag session ended without a compatible drop.
DragCancelled {
session: DragSessionId,
reason: DropCancelReason,
},
WindowResized {
widget_id: WidgetId,
width: i32,
height: i32,
},
/// A split-pane backend reported a changed divider position.
/// `position` is the first pane's extent along the split axis; `extent`
/// is the total extent along that axis.
SplitPaneMoved {
widget_id: WidgetId,
position: i32,
extent: i32,
},
/// An OS close request (the window's X button, Alt+F4, the system menu)
/// for a window with close interception enabled (`Ui::set_close_guard`).
/// The window stays open until the app approves the close —
/// typically after asking through `Ui::show_confirm_dialog` (GH-056).
CloseRequested {
widget_id: WidgetId,
},
WindowClosed {
widget_id: WidgetId,
},
/// A transient popup session ended because of a user or window-system action.
PopupDismissed {
widget_id: WidgetId,
reason: PopupDismissReason,
},
/// A timer deadline was serviced on the UI event loop; `elapsed` is
/// measured from the original start and `missed` counts coalesced ticks.
TimerFired {
timer: TimerId,
elapsed: std::time::Duration,
missed: u32,
},
/// Linear progress for a UI motion, derived from a coalesced timer deadline.
MotionTicked {
motion: MotionId,
widget_id: WidgetId,
progress: f32,
},
/// A motion reached its duration and will not produce further ticks.
MotionFinished {
motion: MotionId,
widget_id: WidgetId,
},
/// Pointer input on a canvas widget.
///
/// Coordinate contract: `x` and `y` are **logical**
/// (96-DPI) coordinates matching the space the layout engine lays the widget out in.
/// A lane that receives physical pixels from the OS (Win32 under
/// Per-Monitor v2) reports its display scale through
/// [`crate::Backend::widget_scale_factor`]; [`crate::Ui`] inverts that
/// scaling before dispatch, so app code hit-tests against the same
/// coordinate space on every backend. Lanes that already receive logical
/// coordinates (GTK4 gestures, Cocoa points, the Mock backend unless a
/// display fixture installs a scale) report `1.0` and pass through
/// untouched.
PointerDown {
widget_id: WidgetId,
x: f32,
y: f32,
button: u8,
},
/// Pointer motion on a canvas widget; see [`UiEvent::PointerDown`] for the
/// coordinate contract.
PointerMove {
widget_id: WidgetId,
x: f32,
y: f32,
},
/// Pointer release on a canvas widget; see [`UiEvent::PointerDown`] for
/// the coordinate contract.
PointerUp {
widget_id: WidgetId,
x: f32,
y: f32,
button: u8,
},
/// Raw keyboard input on a focusable widget. `key` is the
/// backend's logical key name for the pressed key and is not layout-
/// committed text: use [`UiEvent::Char`] for text input.
///
/// Ordering contract: for a stroke that produces text, `KeyDown` is
/// reported before its [`UiEvent::Char`] and `KeyUp` after it. A stroke
/// claimed by a menu accelerator reports [`UiEvent::MenuItemSelected`]
/// instead and produces no `KeyDown` or `Char`; its `KeyUp` is still
/// delivered so apps can clear pressed-key state.
///
/// Text-editing strokes are the accelerator exception: while a
/// `TextInput`/`TextArea` holds focus, clipboard and undo commands
/// (Ctrl+C/X/V/Z/Y/A), Delete, and Backspace stay with the control and
/// never fire a registered accelerator — otherwise a rename field could
/// not paste text while the app's Paste command mirrors it. The
/// exception matches GTK, where the focused widget processes those keys
/// before application accelerators.
KeyDown {
widget_id: WidgetId,
key: String,
ctrl: bool,
shift: bool,
alt: bool,
},
KeyUp {
widget_id: WidgetId,
key: String,
ctrl: bool,
shift: bool,
alt: bool,
},
/// Committed text input for a widget: direct keyboard input
/// and IME commits both report through this event. `text` may contain
/// more than one scalar (IME result strings, dead-key sequences).
///
/// Exactly one `Char` is reported per committed text. The commit may
/// arrive without a preceding `KeyDown` (an IME candidate picked with
/// the pointer) and is never interleaved with an unfinished IME
/// composition — while a composition is active, text stays in
/// [`UiEvent::CompositionChanged`]. Standard text controls report their
/// value changes through [`UiEvent::TextChanged`] on top of the commit
/// `Char`; backends observe the platform IME result for those controls
/// (Win32 `GCS_RESULTSTR`, GTK's widget input context), so apps do not
/// need a separate text-input path per control.
Char {
widget_id: WidgetId,
text: String,
},
/// IME composition state changed for a widget.
///
/// `Some(preedit)` carries the live preedit string while a composition
/// is active (it may be empty for a just-started composition); `None`
/// marks the end of the composition exactly once, for both commits and
/// cancels. Repeated preedit updates that report the same string are
/// de-duplicated by the backend. A commit also reports
/// [`UiEvent::Char`] with the committed text; the relative order of
/// that `Char` and the ending `None` is platform-defined (Win32
/// commits before the end marker, GTK clears the preedit first), so
/// apps must treat both signals independently instead of relying on
/// their order.
CompositionChanged {
widget_id: WidgetId,
text: Option<String>,
},
/// Keyboard focus moved to (`focused: true`) or away from
/// (`focused: false`) a widget. Programmatic
/// `Ui::focus`/`Ui::focus_next`/`Ui::focus_previous` report through this
/// event, and native focus changes produce it; `Ui` keeps its
/// focus record in sync from it.
FocusChanged {
widget_id: WidgetId,
focused: bool,
},
/// The OS light/dark preference changed.
///
/// Reported by backends whose `Backend::theme_capabilities().change_events`
/// is true when the system setting transitions; the backend de-duplicates
/// so the event only arrives on an actual mode change. It is informational:
/// the active [`crate::Theme`] is unchanged until the app decides to follow
/// the system (for example by calling `Ui::set_theme_mode`), and the current
/// preference can always be re-read through `Ui::system_theme_mode`.
ThemeChanged {
mode: ThemeMode,
high_contrast: bool,
},
/// The window's display metrics changed: a DPI or monitor
/// transition was observed.
///
/// Reported by backends whose `Backend::display_capabilities()` has
/// `dpi_change_events` true. The payload is a fresh [`DisplayInfo`] for
/// the display the window is now on. Informational: apps decide whether
/// to re-layout or re-query `Ui::displays()`.
#[cfg(feature = "displays")]
DisplayChanged {
display: DisplayInfo,
},
/// Internal wake marker posted by a backend's event-loop wake hook when
/// background commands are queued (see `Backend::wake_handle`). `Ui`
/// consumes it while draining and never returns it to application code.
TasksPending,
/// Background-task lifecycle notification posted through a `UiProxy`.
/// See `TaskEvent` for the per-task payloads.
#[cfg(feature = "async")]
Task(TaskEvent),
/// A date was selected in a calendar widget.
CalendarDateSelected {
widget_id: WidgetId,
date: crate::widgets::CalendarDate,
selected_dates: Vec<crate::widgets::CalendarDate>,
},
/// The visible month in a calendar widget changed.
CalendarMonthChanged {
widget_id: WidgetId,
year: i32,
month: u32,
},
/// The user changed a property in a property grid and the value was
/// stored. `widget_id` is the grid host.
#[cfg(feature = "property-grid")]
PropertyChanged {
widget_id: WidgetId,
property: crate::properties::PropertyId,
previous: crate::properties::PropertyValue,
value: crate::properties::PropertyValue,
},
/// With veto mode on, a user edit is waiting for
/// [`crate::Ui::resolve_property_change`]; nothing is stored yet.
#[cfg(feature = "property-grid")]
PropertyChanging {
widget_id: WidgetId,
property: crate::properties::PropertyId,
token: crate::properties::ChangeToken,
proposed: crate::properties::PropertyValue,
},
/// A user edit did not apply: the text did not parse for the property's
/// type, the model refused it, or the application vetoed it. The editor
/// already shows the stored value again.
#[cfg(feature = "property-grid")]
PropertyEditRejected {
widget_id: WidgetId,
property: crate::properties::PropertyId,
reason: String,
},
/// Keyboard focus moved to a property's editor, selecting it.
#[cfg(feature = "property-grid")]
PropertySelected {
widget_id: WidgetId,
property: Option<crate::properties::PropertyId>,
},
/// The user changed the text of a styled text widget: at `position` (in
/// characters), `deleted` was replaced by `inserted`. The document,
/// styling, markers and indicators are already updated.
#[cfg(feature = "styled-text")]
StyledTextModified {
widget_id: WidgetId,
position: usize,
deleted: String,
inserted: String,
},
/// A user edit moved a styled text document away from its save point
/// (`dirty: true`) or back to it.
#[cfg(feature = "styled-text")]
StyledTextSavePointChanged {
widget_id: WidgetId,
dirty: bool,
},
/// A WebView started loading `url`.
#[cfg(feature = "webview")]
WebViewLoadStarted {
widget_id: WidgetId,
url: String,
},
/// A WebView finished loading `url`.
#[cfg(feature = "webview")]
WebViewLoadFinished {
widget_id: WidgetId,
url: String,
},
/// A WebView could not load `url`; `error` is the engine's description.
#[cfg(feature = "webview")]
WebViewLoadFailed {
widget_id: WidgetId,
url: String,
error: String,
},
/// A navigation or new window the page asked for was refused by the
/// WebView's navigation prefixes (new windows are always refused).
#[cfg(feature = "webview")]
WebViewNavigationBlocked {
widget_id: WidgetId,
url: String,
},
/// The page's title changed.
#[cfg(feature = "webview")]
WebViewTitleChanged {
widget_id: WidgetId,
title: String,
},
/// The page called `window.nativeGui.postMessage(body)`; `source` is the
/// URL of the page that sent it. Treat the body as untrusted input.
#[cfg(feature = "webview")]
WebViewMessage {
widget_id: WidgetId,
source: String,
body: String,
},
/// A script started by `Ui::webview_evaluate_script` finished: `Ok` holds
/// its value as JSON text, `Err` the message of the exception it threw.
#[cfg(feature = "webview")]
WebViewScriptResult {
widget_id: WidgetId,
operation: crate::advanced::OperationId,
result: Result<String, String>,
},
/// The engine failed to start or its content process ended; the WebView
/// shows nothing until it is created again.
#[cfg(feature = "webview")]
WebViewEngineFailed {
widget_id: WidgetId,
error: String,
},
}
impl UiEvent {
/// Whether this event is a deliberate user *action* on its widget.
///
/// Actions are the commit-style events an application normally answers
/// with a message: a button click, a list/grid row activation, Enter in a
/// text field, a checkbox toggle, a selection or value change, a link,
/// toolbar tool, calendar date, or picker acceptance, and a finished
/// inline grid edit. Incidental traffic — focus changes, raw key and
/// pointer strokes, hover, live text edits, live picker previews,
/// resizes, drags, and timers — is not an action.
///
/// [`Routes::on`](crate::Routes::on) uses this filter so that, for
/// example, a button that merely receives keyboard focus does not fire
/// its message.
pub fn is_action(&self) -> bool {
matches!(
self,
UiEvent::Clicked { .. }
| UiEvent::Activated { .. }
| UiEvent::TextSubmitted { .. }
| UiEvent::Toggled { .. }
| UiEvent::SelectionChanged { .. }
| UiEvent::MultiSelectionChanged { .. }
| UiEvent::SuggestionSelected { .. }
| UiEvent::ValueChanged { .. }
| UiEvent::DateChanged { .. }
| UiEvent::LinkActivated { .. }
| UiEvent::ToolActivated { .. }
| UiEvent::ToolToggled { .. }
| UiEvent::CalendarDateSelected { .. }
| UiEvent::ColorSelected { .. }
| UiEvent::FontSelected { .. }
| UiEvent::GridCellEditingFinished { .. }
| UiEvent::MenuItemSelected { .. }
) || self.is_property_action()
}
#[cfg(feature = "property-grid")]
fn is_property_action(&self) -> bool {
matches!(self, UiEvent::PropertyChanged { .. })
}
#[cfg(not(feature = "property-grid"))]
fn is_property_action(&self) -> bool {
false
}
}