Expand description
The context stack (ADR 0012): places (drill-downs, shown as a breadcrumb) and modes (global states, shown as chips), owned by the application’s kernel and projected by the interface.
Experimental: may change in any release
(docs/stability.md).
- The owner implements
Contexts: the frames, the state, the transitions (through the pureegui_pop_model::context::apply), the holds. The host gives it (Host::contexts); without one,ContextsPluginkeeps aLocalContexts, which writes the stack to thecontextdocument inside each transition. The owner publishescontext.changed(with the whole new state and its revision), thencontext.leftandcontext.enteredper frame, orcontext.refused;context.restoredat start,context.heldandcontext.released. - The interface asks, never writes. Every transition is the step
context.request(ADR 0011): a before-hook vetoes it (unsaved typed input) or redirects it, its default asks the owner. Nothing is shown until the owner’s state has a new revision, so a refusal leaves the display as it was. - The projection follows the owner’s state: per projection key
(the place path and the active modes), the main window’s workbench
layout (a place’s arrangement the first time, a mode’s panels shown
or hidden; a change made in a mode belongs to it and goes when it is
left; panels docked in other application windows stay there), the
focused panel and the values components keep (
view_value,scroll_area); the context keysplace,placeDepth,modePushed,mode.<group>and the frames’ own keys, read bywhenclauses (a frame’s own key bindings useFrameSpec::clause:Ctx::frame_keybinding). It is written to theviewdocument about a second after it changes. - Widgets:
breadcrumb,mode_chips,mode_switch,mode_toggle. Commands:nav.back(Alt+Left; Escape while a mode is pushed),nav.up(Alt+Shift+Up),nav.enter, and for agentscontext.read,context.request(withif_revanddry_run),context.go,context.set_mode,context.holdandcontext.release. Thecontextscollector shows it all. - Undo out of sight: the value store’s new steps carry the place
shown (
Store::set_place); an undo, a redo or a jump that walks a step made in another place (itsStepInfo::place) says so in a toast, with “Go there”.
use egui_pop_api::contexts::{self, ContextsPlugin, FrameSpec};
use egui_pop_api::{App, Ctx, Plugin, PluginError};
use egui_pop_model::ids::{FrameId, GroupId, PluginId};
const ALBUM: FrameId = FrameId::from_static("demo.album");
const CULLING: FrameId = FrameId::from_static("demo.culling");
struct Demo;
impl Plugin for Demo {
fn id(&self) -> PluginId { PluginId::from_static("demo") }
fn requires(&self) -> Vec<PluginId> { vec![contexts::PLUGIN] }
fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
ctx.frame(FrameSpec::place(ALBUM, "Album"))?
.frame(FrameSpec::mode(CULLING, GroupId::from_static("orientation"), "Culling"))?;
Ok(())
}
}
let app = App::builder().plugin(ContextsPlugin::default()).plugin(Demo)
.build(&egui::Context::default()).unwrap();
let h = app.handle();
assert!(contexts::enter(h, ALBUM, serde_json::Value::Null).ok());
assert!(contexts::set_mode(h, CULLING).ok());
assert_eq!(h.context().get("place"), "demo.album");
assert_eq!(h.context().get("mode.orientation"), "demo.culling");
assert!(contexts::back(h).vetoed().is_none());
assert_eq!(h.context().get("place"), "root");Structs§
- Chip
- An active mode, as a chip shows it.
- Context
Service - The context stack in the application: the default owner, the projection, the requests waiting for a remote owner.
- Contexts
Plugin - The context stack as a plugin: the default owner (a
LocalContexts, unless the host owns the stack), the projection, thecontext.requeststep, the commands and keys, thecontextscollector, the undo toasts. - Dropped
- A frame dropped on restore, and why.
- Entry
- A place on the path, with its payload (the application’s own: a sub-workspace’s id).
- Envelope
- A request with its conditions.
- Frame
Clash - Two frames that can be on together (a place and a mode, two modes of
different groups) binding the same keys to different commands
(
Ctx::frame_keybinding): while both are on, one wins (the later declared, between equals) and the other never fires. - FrameId
- A frame of the context stack (ADR 0012): a place (
demo.album) or a mode (demo.orientation.culling). - Frame
Registry - The frames that exist.
- Frame
Spec - A frame as declared.
- GroupId
- A group of modes, one active at a time (
orientation): the context keymode.<group>, so letters, digits,_and.. - Hand
Write - One of the stack’s own context keys, set by hand (
AppHandle::set_context) instead of by the projection: two truths, and the projection’s overwrites the plugin’s at the next transition. - Hold
- A short lock on groups of the stack: a drag in progress, a batch writing, an agent holding the image. Requests touching a held group are refused with its reason.
- Label
Call - What a place’s crumb label is asked about.
- Local
Contexts - The default owner, in process: frames declared by plugins, the stack written to a document inside each transition when given one.
- Mode
Entry - An active mode.
- Refusal
- A refusal, with its reason and who refused.
- Root
Label Call - What the root crumb’s label is asked about
(
ContextsPlugin::root_label). - State
- The stack: the place path, the active modes, a revision.
- Transition
- A transition applied (or, for a dry run, that would be).
Enums§
- Answer
- What the owner answers a request.
- Kind
- What a frame is.
- Life
- How a mode is on.
- Refusal
Kind - Why a transition did not happen.
- Request
- A transition asked of the owner.
- Verdict
- What a guard decides.
Constants§
- CMD_
BACK - Back: pops the last pushed mode, else leaves the top place.
- CMD_
ENTER - Enters a place (
frame,payload). - CMD_GO
- Goes to a place path (
places:[{ "frame", "payload" }]). - CMD_
HOLD - Holds groups of the stack (
groups,reason): requests touching them are refused until released. - CMD_
READ - The stack, its holds and its frames.
- CMD_
RELEASE - Releases a hold (
token). - CMD_
REQUEST - Any transition, as an envelope (
request,if_rev,dry_run). - CMD_
SET_ MODE - Sets a mode (
mode), pushes it (push: true), or turns a group off (group, nomode). - CMD_UP
- Up: leaves the top place.
- CONTEXTS
- The context stack’s service.
- CONTEXT_
DOCUMENT - The document
LocalContextswrites the stack to, beside the layout’s (workspaces/photos/contextwhen the host keeps the layout inworkspaces/photos/layout; seedocuments). - PLACES
- The group a hold names to stop place transitions (enter, leave, jump, go).
- PLUGIN
- The plugin’s id: plugins declaring frames require it.
- ROOT
- The place at the bottom of every path, as the
placecontext key says it. - STEP_
REQUEST - A transition asked of the owner (
{ "request": envelope, "origin" }): a before-hook vetoes it (the interface’s own guards) or redirects it; the default asks the owner. Its result: the new revision, the frames entered and left; a refusal is its error. - VIEW_
DOCUMENT - The document the projection writes its layouts and view states to, beside the layout’s too.
Traits§
- Contexts
- The owner of the context stack, as the interface reaches it.
Functions§
- back
- Back, as the user: pops the last pushed mode, else leaves the top place.
- breadcrumb
- The breadcrumb: the root, then each place; a crumb jumps back to its level (the last one is where the user is).
- chips
- The active modes, in the order they came. Empty without the context plugin.
- clear_
mode - Turns a group’s mode off, as the user.
- crumb_
icons - The icon each crumb’s place declares (
FrameSpec::icon), by name, incrumbs’ order:Nonefor the root and for a place without one. - crumbs
- The breadcrumb’s crumbs as the interface says them: the root’s title,
then each place’s (its title, and its payload when it is a text or a
number). Crumb
iis reached withjump(app, i). Empty without the context plugin. - documents
- The documents the stack (
LocalContexts) and its view are kept in:CONTEXT_DOCUMENTandVIEW_DOCUMENTbeside the layout’s document as the host names it (Host::layout_document), so a host keeping a layout per workspace keeps a stack per workspace too; at the top when it names none. - enter
- Enters a place, as the user.
- frame_
clashes - The keymap’s frame clashes (see
FrameClash): the key conflicts (AppHandle::key_conflicts) between two frames’ own bindings. - go
- Goes to a place path, as the user.
- hold
- Holds groups of the stack (empty: all of it) for
by: requests touching them are refused withreasonuntilrelease. - is_
stack_ key - Whether a context key is the stack’s own:
place,placeDepth,modePushed,mode.<group>, the top place’spayloadandpayload.<field>. Only the projection sets them; a plugin declares frames and reads them. - jump
- Leaves places until
depthare left (0: the root), as the user. - leave
- Leaves the top place, as the user.
- mode_
chips - The active modes as chips, each with a way out (a pushed mode pops, a set one is turned off).
- mode_
switch - The modes of a group as a row of choices, the one on selected;
noneadds a choice turning the group off. - mode_
toggle - A pushed mode as a toggle: pushes it, or pops it (turns it off when it is not the last pushed).
- place_
value - A value kept for the place shown (
place_value_of). - place_
value_ of - A value kept for a place (its frame id,
ROOTat the root) rather than for a projection key: the same in every album, whatever the modes. Saved with the view state. - pop_
mode - Pops the last pushed mode, as the user.
- push_
mode - Pushes a mode, as the user.
- release
- Releases a hold; whether it was held.
- reload
- Reads the stack and its view again from
documents, as at start: after the host changed where they are (another workspace opened in the same window). What was shown is forgotten (its view was written already); what the documents hold, checked against today’s frames, is projected. - request
- Asks the owner for a transition, through the
context.requeststep; the projection follows (at once, or at the next pass while the areas are drawn). A refusal or a veto asked by the user shows in a toast, unless there was nothing to do. - scroll_
area - A scroll area whose offset is kept per projection key: entering a place and coming back finds it where it was.
- set_
mode - Sets a mode, as the user.
- set_
place_ value - Keeps a value for the place shown (
Json::Nullforgets it); written to theviewdocument a second later. - set_
view_ value - Keeps a value for the projection key shown; written to the
viewdocument a second later. - state
- The state the interface shows, as projected last (
Nonewithout the plugin). - sync
- Projects the owner’s state when its revision moved (each pass does).
- view_
value - A value a component keeps for the projection key shown (a list’s scroll offset, a selection), saved with the view state.
- why_not
- Why the owner would refuse a request now (its guards, a hold), asked
as a dry run of the stack’s own owner;
Nonewhen it would go, when there is nothing to do, or when the host owns the stack (its answer may come later). - with_
owner - Runs
fon the owner: the host’s, else the plugin’sLocalContexts.Nonewithout the plugin, or while the host (owning the stack) runs a command.