Expand description
The context stack (ADR 0012): where the user is and how the application behaves right now, without egui.
Experimental: may change in any release
(docs/stability.md).
- Places are drill-downs (an album, a group, a sub-workspace): a path from the root, shown as a breadcrumb.
- Modes are global states (an orientation, compare, read-only): at most one per group, modes of different groups combine. A mode is set (sticky until changed) or pushed (temporary: popping it puts back what it replaced in its group).
- A frame may be transient: on the live stack, never restored.
Frames are declared in a FrameRegistry; the State is the place
path, the active modes and a revision. apply is the pure
transition function (guards, holds, if_rev, redirections) and
restore brings a saved state back against today’s frames. The
owner of the stack (the application’s kernel, or egui-pop’s
LocalContexts) calls them; nothing here does I/O.
use egui_pop_model::context::{self, Envelope, FrameRegistry, FrameSpec, Request, State};
use egui_pop_model::ids::{FrameId, GroupId};
const ALBUM: FrameId = FrameId::from_static("demo.album");
const CULLING: FrameId = FrameId::from_static("demo.culling");
let mut frames = FrameRegistry::new();
frames.insert(FrameSpec::place(ALBUM, "Album")).unwrap();
frames
.insert(FrameSpec::mode(CULLING, GroupId::from_static("orientation"), "Culling"))
.unwrap();
let s = State::default();
let t = context::apply(&s, &frames, &[], &Envelope::new(Request::enter(ALBUM))).unwrap();
assert_eq!(t.state.place(), "demo.album");
let t = context::apply(&t.state, &frames, &[], &Envelope::new(Request::set(CULLING))).unwrap();
assert_eq!(t.state.mode_of("orientation"), Some(&CULLING));
assert_eq!(t.state.rev, 2);Structs§
- Context
Doc - The
contextdocument: the stack as its owner writes it at each transition. - 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
Registry - The frames that exist.
- Frame
Spec - A frame as declared.
- Guard
Call - What a guard is asked about.
- 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.
- Mode
Entry - An active mode.
- Refusal
- A refusal, with its reason and who refused.
- State
- The stack: the place path, the active modes, a revision.
- Transition
- A transition applied (or, for a dry run, that would be).
- ViewDoc
- The
viewdocument: the projection’s layouts and view states, by projection key (State::projection_key), and values kept per place (the top place’s frame id,rootat the root: the status bar’s choices). - View
State - What the projection keeps for one projection key: the focused panel and the values components remember there (a list’s scroll offset).
Enums§
- 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§
- PLACES
- The group a hold names to stop place transitions (enter, leave, jump, go).
- ROOT
- The place at the bottom of every path, as the
placecontext key says it.
Functions§
- apply
- Applies a request to a state: the new state and what was entered and left, or why not. Pure: the owner writes and publishes.
- payload_
keys - The context keys a top place’s payload sets, for
whenclauses: a text, a number or a boolean aspayload; an object’s fields that are one of those aspayload.<field>(payload.id == 'darkroom'). Nested values set nothing. - restore
- Brings a saved state back against today’s frames: a place that is
unknown, transient or refused by
valid(its payload no longer exists) cuts the path there (its children go with it); a mode is dropped alone (a pushed one gives its place back to what it replaced). Restoring never fails; the revision is kept. - schema
- The
contextdocument’s schema. - view_
schema - The
viewdocument’s schema.
Type Aliases§
- Arrangement
For - The arrangement a place starts from, chosen from its payload
(
FrameSpec::arrangement_for):Nonefalls back to its arrangement. - Guard
- A guard on a frame:
can_enterorcan_leave, evaluated by the owner of the stack. - Label
- A place’s crumb label from its payload (
FrameSpec::label):Nonekeeps the default (the title, and the payload when it is a text or a number).