An event has the id of the node it happened on, a name, and sometimes a
value. Events arrive in the order they happened, one at a time; each is
followed by a render.
By component
| Component | Event | Value | Read it with |
|---|---|---|---|
Button, Key, MenuItem, Tab, AppRow, GalleryItem, CalendarDay | click | none | |
Button with .opens_menu() | click | where to open the menu | event.point() |
Row with an id, SidebarItem | click | none | |
Row, SidebarItem with .context() | context | the pointer’s position | event.point() |
SidebarItem with .action(…) | click on <id>.action | none | |
SidebarItem with .reorder(…) | reorder | before:<id> or after:<id> | event.text() |
Switch | change | on or off | event.flag() |
Slider | input | the number, while dragging | event.number() |
TextField | input | the text, at every edit | event.text() |
submit | the text, on Enter | event.text() | |
Segmented, PictureChoice | select | the index | event.index() |
Shortcut | record | recording started or stopped | event.flag() |
change | the binding ("Super+Shift+A"), "" when cleared | event.text() | |
Sheet with an id | dismiss | none | |
Menu | dismiss | none | |
Tab | click on <id>.close | none (the close button, or a middle click) | |
PathBar | select | the crumb’s index | event.index() |
click | none (the empty part of the bar) | ||
submit, dismiss | the typed path; given up | event.text() | |
DataTable | select | the row | event.selection() |
activate | the row’s id (double click, Enter) | event.text() | |
context | the row and the point | event.target(), event.point() | |
click on <id>.sort:<column> | none | ||
Terminal | data | what was typed | event.text() |
resize | the size in cells | event.grid() | |
change | the title the program set | event.text() | |
MediaView | key | next, previous, ended | event.text() |
RegionSelect | select | the rectangle | event.rectangle() |
Wizard | click on <id>.next, <id>.back | none |
FileView
The view does not keep the selection: the applet does, and the view reports what was done.
| Event | Meaning | Read it with |
|---|---|---|
select | A click or a key changed the selection: the item and how (one, toggle, range, all, none) | event.selection() |
activate | Double click or Enter | event.text() (the item’s id) |
context | Right click, on an item or on the background | event.target(), event.point() |
drop | The selection was dropped on a folder, a sidebar item or a breadcrumb | event.target(), event.flag_named("copy") |
drop | Files came in from another program | event.paths() |
drop | Icons were moved (free placement) | event.moved() |
key | A shortcut by name: copy, cut, paste, delete, rename, new-folder, refresh, back, … | event.text() |
submit, dismiss | The inline rename field | event.text() |
The helpers
All of them return None (or an empty list) when the value is not what they
expect, so an event of another kind never panics an applet.
| Helper | Returns | For |
|---|---|---|
event.is(name) | bool | Telling submit from input, context from click |
event.text() | Option<&str> | Text fields, bindings, ids, key names |
event.flag() | Option<bool> | Switches |
event.number() | Option<f64> | Sliders |
event.index() | Option<usize> | Segmented controls |
event.point() | Option<(f64, f64)> | Where to open a menu, in window coordinates |
event.target() | Option<&str> | The item a context or drop is about |
event.selection() | Option<(Option<&str>, &str)> | The item and the mode of a select |
event.paths() | Vec<String> | Files dragged in |
event.moved() | Vec<(String, i32, i32)> | Items moved to new places |
event.flag_named(name) | bool | A named boolean, such as copy |
event.rectangle() | Option<(i64, i64, i64, i64)> | x, y, width, height |
event.grid() | Option<(u16, u16)> | Columns and rows of a terminal |
A pattern for event
Match on the id; within a family, on the name.
fn event(&mut self, event: &Event, commands: &mut Commands) {
let id = event.node_id.as_str();
// Families first: ids that carry what they are about.
if let Some(address) = id.strip_prefix("device:") {
return self.select_device(address);
}
match id {
"search" => self.query = event.text().unwrap_or_default().to_owned(),
"list" if event.is("context") => self.menu = event.target().map(str::to_owned).zip(event.point()),
"list" if event.is("activate") => self.open(event.text()),
"menu" => self.menu = None, // dismissed
"@host" if event.is("open") => self.open(event.text()),
"done" => commands.close_window(),
_ => {}
}
}