Skip to main content

Module steps

Module steps 

Source
Expand description

Steps: the moments of a feature’s life an application can reach (ADR 0011). egui-pop does the plumbing (closing a window, detaching a panel, switching an arrangement, rebinding a key); at each step a plugin may:

  • observe: every step publishes a signal on the host’s journal, named after the step (frame.close), with its arguments and result, or <step>.vetoed;
  • veto or redirect with a before-hook (Before): stop the step with a reason, or change its arguments;
  • replace with a run-hook: do the step its own way instead of egui-pop’s default (the last plugin to replace a step wins; two are reported);
  • extend with an after-hook: act on the result.

Each is optional; without hooks a step runs its default. Every run is traced (who redirected, vetoed, ran, followed) and shown by the debug bridge’s steps collector.

use egui_pop_api::steps::{Before, StepSpec};
use egui_pop_api::{App, Ctx, Plugin, PluginError};
use egui_pop_model::ids::{PluginId, StepId};

const SAVE: StepId = StepId::from_static("demo.save");

struct Guard;
impl Plugin for Guard {
    fn id(&self) -> PluginId { PluginId::from_static("guard") }
    fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
        ctx.step(StepSpec::new(SAVE, "Saves the demo."))?;
        ctx.before(SAVE, |_, args| {
            if args["name"] == "" { Before::Veto("no name".into()) } else { Before::Go }
        });
        Ok(())
    }
}

let app = App::builder().plugin(Guard).build(&egui::Context::default()).unwrap();
let h = app.handle();
let out = h.step(&SAVE, serde_json::json!({ "name": "" }), |_, _| Ok(serde_json::json!("saved")));
assert_eq!(out.vetoed(), Some("no name"));
let out = h.step(&SAVE, serde_json::json!({ "name": "a" }), |_, _| Ok(serde_json::json!("saved")));
assert_eq!(out.result(), Some(&Ok(serde_json::json!("saved"))));

Structs§

HookInfo
A hook on a step: its owner and kind (before, replace, after).
StepInfo
A declared step with its hooks, as the debug bridge shows it.
StepSpec
A step as declared: its id, what it does, an example of its arguments.
StepTrace
One run of a step, as the steps collector shows it.

Enums§

Before
What a before-hook decides.
Outcome
How a step ended.

Constants§

PRIVATE
The key a step’s arguments carry, true, when they hold private data (a private command’s arguments, say): the step’s events and trace are then marked private, and readers that do not read private data get their arguments, result and error redacted (host::redact_private). A redirection cannot take the mark off.
TRACES
How many runs the trace keeps.

Functions§

is_private
Whether a step’s arguments carry the PRIVATE mark.

Type Aliases§

AfterFn
An after-hook: sees the arguments and the result.
BeforeFn
A before-hook.
RunFn
A run-hook: does the step instead of the default.