Skip to main content

Module context

Module context 

Source
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§

ContextDoc
The context document: 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.
FrameRegistry
The frames that exist.
FrameSpec
A frame as declared.
GuardCall
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.
LabelCall
What a place’s crumb label is asked about.
ModeEntry
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 view document: the projection’s layouts and view states, by projection key (State::projection_key), and values kept per place (the top place’s frame id, root at the root: the status bar’s choices).
ViewState
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.
RefusalKind
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 place context 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 when clauses: a text, a number or a boolean as payload; an object’s fields that are one of those as payload.<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 context document’s schema.
view_schema
The view document’s schema.

Type Aliases§

ArrangementFor
The arrangement a place starts from, chosen from its payload (FrameSpec::arrangement_for): None falls back to its arrangement.
Guard
A guard on a frame: can_enter or can_leave, evaluated by the owner of the stack.
Label
A place’s crumb label from its payload (FrameSpec::label): None keeps the default (the title, and the payload when it is a text or a number).