Skip to main content

Module values

Module values 

Source
Expand description

The value store: every value a widget, a setting or an agent edits lives here at a stable path (settings/theme, view/zoom), never in a widget.

  • Each path has a Descriptor: type, hard and soft range, fine and coarse steps, unit, display scale and precision, default, label, choices.
  • Every write is a Set: an absolute value, a relative step, reset, top or bottom, with its Origin. The answer says what was applied and whether it was clamped; a refusal says why and gives the current value.
  • During a gesture (a drag), the paths it touched belong to it: a write from another origin is refused. Otherwise the last writer wins; a writer may ask to write only if nothing changed since it read (if_seq).
  • Every change is told to the listeners of its path and kept in a short journal (Changed: path, old, new, origin, sequence); a write equal to the value changes nothing and tells nothing, so a change never loops back.
  • Undo: one step per gesture or group, else one per write; the newest HISTORY_CAP steps are kept unless the host sets another cap. An undo or a redo never writes into a drag still going, the dragger’s own included. Steps go to a history by scope (ADR 0014): the application’s (APP) unless the write names another (Set::history, or the one enter_history set, such as the settings window’s). Each step has an id, its time on the store’s clock (Store::set_clock) and the place it was made in (Store::set_place); writes carrying the same merge key (Set::merge) from one origin less than a second apart are one step, until Store::seal (the focus left).
  • A history also keeps its snapshots (Store::take_snapshot, restored as a new step), the redo lists new steps dropped (Store::replaced_in, reachable by Store::jump_in), and undoes one step out of order unless a later step changed the same path (Store::undo_step_in); Store::values_at says what differs at a point, for a preview.
  • A value changed outside a history since its step (an untracked write, Store::import, another history) keeps that change: undo, redo, jumps and cancels leave it and list it (Store::take_skipped). A group’s step goes before the steps made after its first write.
  • Paths are owned: a plugin’s settings and listeners go with it.
  • One writer per value: a write names the scope issuing it (Set::by, or the scope enter_scope set, such as the plugin whose command runs). A scope that is not the path’s owner, not one of its Writers and not the framework (acting for a person: the settings form, a bound widget, the user’s value.set) is refused, or only warned about under WriterCheck::Warn. An agent or a script writes as itself (Origin::writer). A write naming no scope is the application’s own and is not checked; undo, redo and restoring saved values are never refused, but for an undo or redo issued by a writer (Store::undo_by).
use egui_pop_model::commands::Origin;
use egui_pop_model::ids::OwnerId;
use egui_pop_model::values::{Change, Descriptor, Set, Store, Value};

let mut store = Store::new();
store
    .declare(&OwnerId::FRAMEWORK, "settings/volume", Descriptor::float("Volume", 0.0, 1.0, 0.5))
    .unwrap();
let applied = store
    .set(Set::new("settings/volume", Change::To(Value::Float(2.0)), Origin::User))
    .unwrap();
assert_eq!(applied.value, Value::Float(1.0)); // clamped to the range

Re-exports§

pub use crate::history::APP;
pub use crate::history::SETTINGS;

Structs§

Applied
What a write did.
Changed
A value changed.
Descriptor
What a value is and how it is shown and moved.
DroppedSteps
The undo steps one history lost when an owner went: those changing one of its paths, undo, redo and kept branches alike.
Entry
A value at its path.
GestureId
HistoryGuard
Leaves the history enter_history entered when dropped.
ListenerId
A change listener, by id.
OwnerRemoval
What Store::remove_owner_report removed with an owner.
PathHint
A text that names a path on disk: what it names and, for a file, the extensions accepted (none: any). A form shows it with a Browse button, whose chooser title, purpose and filter_name the hint may give. Built with PathHint::new or Descriptor::path: a field added later breaks nobody.
ScopeGuard
Leaves the scope enter_scope entered when dropped.
Set
A write.
SettingsDoc
The settings document: the values that differ from their default.
Skipped
A value an undo, a redo, a jump or a cancel left as it was: it was changed outside the history since the step (an untracked write, a settings file read back, another history), so the outside change is kept.
Step
One undo step.
Store
The store.
StrayWrite
A write from a scope that is not one of a path’s writers.

Enums§

Change
What a write asks for.
Clamped
Which range held a write back.
DeclareError
Why a path could not be declared.
PathKind
What a path names: a directory or a file.
Refused
Why a write was refused; each gives the current value.
Type
The type of a value.
Value
A value the store holds.
WriterCheck
What a write from a scope that is not one of a path’s writers gets.
Writers
Who may write a path, besides the framework acting for a person (see Store::set).

Constants§

HISTORY_CAP
How many undo steps a store keeps by default, the oldest dropped first (Store::set_history_cap).
JOURNAL
How many changes the journal keeps.
NOT_A_WRITER
The diagnostic code of a write from a scope that is not a writer.

Functions§

check_path
Checks a path: segments with the id syntax, separated by /.
current_history
The history enter_history set on this thread, else APP.
current_scope
The scope enter_scope set on this thread, if any.
enter_history
Steps made on this thread go to scope’s history while the guard lives, unless a write names its own (Set::history); a gesture or a group keeps the history it was opened in. The settings window enters SETTINGS while it draws its form. Histories nest.
enter_scope
Writes on this thread that name no scope are issued by scope while the guard lives (the application sets the plugin connecting, the owner of the command running, the plugin a lifecycle hook belongs to). Scopes nest.
register
Declares the value.* commands on a registry, over a shared store, owned by owner.
register_with
As register, on a registry with another handler type: wrap turns each plain handler into one.
settings_schema
The settings document’s schema. Version 2 reads a retired pointer profile id as the profile it names (adobe as lightroom); version 3 reads the file picker’s views as the file browser’s modes (list as details, grid as thumbnails).