Skip to main content

Module selection

Module selection 

Source
Expand description

The application-wide selection: what the user selected and what the pointer is over, shared by every panel.

Experimental: may change in any release (docs/stability.md).

A tree, a list and a canvas showing the same things select and hover them together: a click in one highlights the item in the others, and hovering a row lights up the same item everywhere. The selection is one SelectionService (the SELECTION token), provided by SelectionPlugin; widgets opt in (TreeView::shared, ListView::shared in egui_pop_views, or a canvas of the application’s calling SelectionService::click and SelectionService::hover).

  • Items are SelectionItems: a string id each, a path such as photos/2024/0012.raw or entity:/world/points. Widgets with different keys meet on it.
  • Gestures (Gesture): a click replaces, Ctrl (Cmd on macOS) toggles, Shift selects a range in the order the widget clicked gives, Ctrl+Shift adds that range.
  • Hover: one item at most, said by the widget under the pointer each pass; it goes when that widget says it hovers nothing, or stops saying anything.
  • Changes: each bumps a revision; subscribers are called (SelectionService::subscribe), the journal says selection.changed, and the context keys follow: hasSelection, selectionCount, selectionCanBack and selectionCanForward.
  • History: the past selections, walked by selection.back and selection.forward (Alt+Left and Alt+Right while the focus is in a widget bound to the selection, its SURFACE). A selection is not an edit: undo does not see it.
  • Agents: the selection collector, and the selection.set, selection.add, selection.clear and selection.hover commands.
use egui_pop_api::selection::{Gesture, SelectionItem, SelectionService};

let s = SelectionService::new();
let order: Vec<SelectionItem> = ["a", "b", "c", "d"].map(SelectionItem::from).to_vec();
s.click(&order[1], Gesture::Replace, &order, "list");
s.click(&order[3], Gesture::Range, &order, "list");
assert_eq!(s.items(), order[1..].to_vec());
s.click(&order[2], Gesture::Toggle, &order, "list");
assert_eq!(s.items(), vec![order[1].clone(), order[3].clone()]);
assert!(s.back("test"));
assert_eq!(s.len(), 3);

Structs§

Change
What changed, as subscribers get it.
SelectionItem
An item of the selection: a string id the application chooses, the same in every widget showing the item (a path, kind:id, a number).
SelectionPlugin
The application-wide selection: its service, commands, keys, context keys and collector.
SelectionService
The application-wide selection; see the module.
Subscription
A subscription, to give back to SelectionService::unsubscribe.

Enums§

Gesture
What a click does to the selection.

Constants§

CMD_ADD
Adds items to the selection.
CMD_BACK
Back to the selection before (Alt+Left in a bound widget).
CMD_CLEAR
Selects nothing.
CMD_FORWARD
Forward to the selection gone back from (Alt+Right in a bound widget).
CMD_HOVER
Hovers an item, or none.
CMD_SET
Selects these items, and only them.
CONTEXT_CAN_BACK
The context key: selection.back has a selection to go back to.
CONTEXT_CAN_FORWARD
The context key: selection.forward has a selection to go to.
CONTEXT_COUNT
The context key: how many items are selected.
CONTEXT_HAS
The context key: something is selected (true or false).
EVENT_CHANGED
The journal’s event after a change of the selection or of the hovered item.
HISTORY_CAP
How many past selections the history keeps.
SELECTION
The selection service.
SELECTION_PLUGIN
The plugin’s id.
SOURCE_COMMAND
The source a change made by an agent’s command names.
SURFACE
The focus surface of the widgets bound to the selection: Alt+Left and Alt+Right go back and forward through the selections there, and the context stack’s nav.back keeps them elsewhere.

Functions§

surface
Draws add in the selection’s focus surface (SURFACE): a widget of the application’s bound to the selection (a canvas) opens it so Alt+Left and Alt+Right walk the selection’s history while it has the focus.
sync
Sets the context keys and publishes what changed since the last call.