pub struct Ctx<'a> { /* private fields */ }Expand description
What a plugin registers through.
Implementations§
Source§impl Ctx<'_>
impl Ctx<'_>
Sourcepub fn clip_type(&mut self, t: ClipType) -> Result<&mut Self, CtxError>
pub fn clip_type(&mut self, t: ClipType) -> Result<&mut Self, CtxError>
Declares a type of clipboard item, owned by this plugin (gone with it). Its format must not be declared already.
Sourcepub fn clip_transform(&mut self, t: Transform) -> Result<&mut Self, CtxError>
pub fn clip_transform(&mut self, t: Transform) -> Result<&mut Self, CtxError>
Declares a clipboard transform, owned by this plugin.
Sourcepub fn clip_sanitiser(&mut self, s: Sanitiser) -> Result<&mut Self, CtxError>
pub fn clip_sanitiser(&mut self, s: Sanitiser) -> Result<&mut Self, CtxError>
Declares a clipboard sanitiser, owned by this plugin.
Sourcepub fn clip_endpoint(
&mut self,
name: &str,
source: Option<Rc<dyn ClipSource>>,
target: Option<Rc<dyn ClipTarget>>,
) -> &mut Self
pub fn clip_endpoint( &mut self, name: &str, source: Option<Rc<dyn ClipSource>>, target: Option<Rc<dyn ClipTarget>>, ) -> &mut Self
Registers a component’s endpoint, owned by this plugin (gone with
it); see register.
Source§impl Ctx<'_>
impl Ctx<'_>
Sourcepub fn frame(&mut self, spec: FrameSpec) -> Result<&mut Self, CtxError>
pub fn frame(&mut self, spec: FrameSpec) -> Result<&mut Self, CtxError>
Declares a frame of the context stack, owned by this plugin (gone
with it). The plugin requires PLUGIN.
Sourcepub fn frame_keybinding(
&mut self,
frame: &FrameSpec,
keys: &str,
command: CommandId,
) -> Result<&mut Self, CtxError>
pub fn frame_keybinding( &mut self, frame: &FrameSpec, keys: &str, command: CommandId, ) -> Result<&mut Self, CtxError>
Binds keys to a command while a frame is on: the frame’s own
keymap layer, through its when clause (mode.<group> == 'id',
place == 'id'), winning over a binding without a clause.
Source§impl<'a> Ctx<'a>
impl<'a> Ctx<'a>
Sourcepub fn writer(&self) -> ValueWriter
pub fn writer(&self) -> ValueWriter
Writes to the value store as this plugin, to keep in closures: a write to a path it may not write (one it neither owns nor is named a writer of) is refused. Writes made while it connects and in its command handlers and lifecycle hooks name it already.
Sourcepub fn icon(
&mut self,
name: &str,
svg: impl Into<Arc<[u8]>>,
paint: Paint,
) -> Result<Icon, IconError>
pub fn icon( &mut self, name: &str, svg: impl Into<Arc<[u8]>>, paint: Paint, ) -> Result<Icon, IconError>
Registers an SVG icon of this plugin under <plugin-id>:<name>
(my-plugin:mask-circle), the name its declarations then use
(CommandSpec::icon, PanelSpec::icon). Needs the svg feature
of egui-pop-core.
Sourcepub fn is_connected(&self, plugin: &PluginId) -> bool
pub fn is_connected(&self, plugin: &PluginId) -> bool
Whether another plugin is connected.
Sourcepub fn command(
&mut self,
spec: CommandSpec,
handler: impl Fn(&Call<'_>) -> Result<Json, String> + 'static,
) -> Result<&mut Self, CtxError>
pub fn command( &mut self, spec: CommandSpec, handler: impl Fn(&Call<'_>) -> Result<Json, String> + 'static, ) -> Result<&mut Self, CtxError>
Declares a command and everything derived from it (its default
key bindings, its menu entries, its palette entry and its agent
surface), with an in-process handler: the default LocalHost
runs it on the interface thread.
Sourcepub fn declare(&mut self, spec: CommandSpec) -> Result<&mut Self, CtxError>
pub fn declare(&mut self, spec: CommandSpec) -> Result<&mut Self, CtxError>
Declares a command the application’s host runs (AppBuilder::host):
keys, menus, palette and traces as for Ctx::command, no
handler here.
Sourcepub fn keybinding(
&mut self,
keys: &str,
command: CommandId,
when: &str,
layer: Layer,
) -> Result<&mut Self, CtxError>
pub fn keybinding( &mut self, keys: &str, command: CommandId, when: &str, layer: Layer, ) -> Result<&mut Self, CtxError>
Binds keys to a command (layer defaults: use Layer::Default
for a plugin’s own, Layer::Suggestion for a soft one).
Sourcepub fn keybinding_with(
&mut self,
keys: &str,
command: CommandId,
when: &str,
layer: Layer,
options: BindOptions,
) -> Result<&mut Self, CtxError>
pub fn keybinding_with( &mut self, keys: &str, command: CommandId, when: &str, layer: Layer, options: BindOptions, ) -> Result<&mut Self, CtxError>
Binds keys to a command, listening as options say (on a
surface, while typing, through modals).
Sourcepub fn unbind(
&mut self,
keys: &str,
layer: Layer,
) -> Result<&mut Self, CtxError>
pub fn unbind( &mut self, keys: &str, layer: Layer, ) -> Result<&mut Self, CtxError>
Unbinds keys (in the layers below layer).
Sourcepub fn command_icon(
&mut self,
command: CommandId,
icon: &str,
icon_on: Option<&str>,
) -> &mut Self
pub fn command_icon( &mut self, command: CommandId, icon: &str, icon_on: Option<&str>, ) -> &mut Self
Sets the icon of a command, whoever declared it (one of
egui-pop’s own, another plugin’s): icon and icon_on (shown
while its checked clause holds; None for none) replace the
declared ones on every surface running the command. The last
plugin to set one wins; it goes with the plugin. A command not
declared is reported (unknown-command); names are checked as a
declaration’s (unknown-icon).
Contributes a menu item.
Sourcepub fn list_provider(
&mut self,
name: &str,
f: impl Fn(&AppHandle, &WhenContext) -> Vec<ListItem> + 'static,
) -> &mut Self
pub fn list_provider( &mut self, name: &str, f: impl Fn(&AppHandle, &WhenContext) -> Vec<ListItem> + 'static, ) -> &mut Self
Fills the lists named name (MenuItem::list) when their menu
opens: the entries f gives in the context of that moment (the
last plugin to provide a name wins).
Declares a submenu under a menu (app.menu.view).
Sourcepub fn panel(
&mut self,
spec: PanelSpec,
draw: impl FnMut(&mut Ui, &AppHandle) + 'static,
) -> Result<&mut Self, CtxError>
pub fn panel( &mut self, spec: PanelSpec, draw: impl FnMut(&mut Ui, &AppHandle) + 'static, ) -> Result<&mut Self, CtxError>
Declares a panel and how to draw it; the workbench places it in
its area (see workbench), inside a fault boundary and a focus
scope, and its commands <id>.focus and <id>.toggle are
declared with it.
Sourcepub fn instance_panel(
&mut self,
spec: PanelSpec,
draw: impl FnMut(&mut Ui, &AppHandle, &Instance) + 'static,
) -> Result<&mut Self, CtxError>
pub fn instance_panel( &mut self, spec: PanelSpec, draw: impl FnMut(&mut Ui, &AppHandle, &Instance) + 'static, ) -> Result<&mut Self, CtxError>
Declares a panel that opens as many times as asked
(Instances::Multiple),
and the one function drawing each instance, told which it draws
(Instance): the panel
declared is instance 1, pop.panel.open with instance: "new"
opens <id>#<n>. Each instance’s payload is the application’s
(AppHandle::instance_payload), kept in the layout.
Sourcepub fn zone(&mut self, zone: ZoneId, title: &str) -> Result<&mut Self, CtxError>
pub fn zone(&mut self, zone: ZoneId, title: &str) -> Result<&mut Self, CtxError>
Declares a zone other plugins may contribute blocks to.
Sourcepub fn block(&mut self, zone: ZoneId, block: Block) -> &mut Self
pub fn block(&mut self, zone: ZoneId, block: Block) -> &mut Self
Contributes a block to a zone: add, replace, extend or wrap. What cannot apply (unknown zone, missing target, duplicate id) is reported when the application resolves zones.
Sourcepub fn value(
&mut self,
path: &str,
descriptor: Descriptor,
) -> Result<&mut Self, CtxError>
pub fn value( &mut self, path: &str, descriptor: Descriptor, ) -> Result<&mut Self, CtxError>
Declares a value of the application’s state at path, owned by
the plugin and removed with it: each change is an undo step, and
widgets bind to it (egui_pop_core::param::bound). Its value
starts at the descriptor’s default. A setting, saved and in the
settings window, is a Ctx::setting.
use egui_pop_api::{App, Ctx, Plugin, PluginError};
use egui_pop_model::ids::PluginId;
use egui_pop_model::values::Descriptor;
struct Swatch;
impl Plugin for Swatch {
fn id(&self) -> PluginId { PluginId::from_static("swatch") }
fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
ctx.value("swatch/hue", Descriptor::float("Hue", 0.0, 360.0, 200.0))?;
Ok(())
}
}
let app = App::builder().plugin(Swatch).build(&egui::Context::default()).unwrap();
assert_eq!(app.handle().value::<f64>("swatch/hue"), Some(200.0));Sourcepub fn setting(
&mut self,
id: SettingId,
descriptor: Descriptor,
) -> Result<&mut Self, CtxError>
pub fn setting( &mut self, id: SettingId, descriptor: Descriptor, ) -> Result<&mut Self, CtxError>
Declares a setting at settings/<id> (SettingId::path),
applied live, with its reset; shown in the settings form under the
plugin’s title. Read it with AppHandle::setting.
Sourcepub fn collector(
&mut self,
collector: FnCollector,
) -> Result<&mut Self, CtxError>
pub fn collector( &mut self, collector: FnCollector, ) -> Result<&mut Self, CtxError>
Adds a collector to the debug bridge (removed with the plugin).
Sourcepub fn service<T: Send + Sync + 'static>(
&mut self,
token: &ServiceToken<T>,
value: T,
) -> Result<&mut Self, CtxError>
pub fn service<T: Send + Sync + 'static>( &mut self, token: &ServiceToken<T>, value: T, ) -> Result<&mut Self, CtxError>
Provides a service.
Sourcepub fn local_scope(
&mut self,
surface: &str,
scope: impl LocalScope + 'static,
) -> &mut Self
pub fn local_scope( &mut self, surface: &str, scope: impl LocalScope + 'static, ) -> &mut Self
Registers a local scope (ADR 0014) for a focus surface: while the
focus is in surface (egui_pop_core::focus::scope), Ctrl+Z and
Ctrl+Shift+Z undo and redo there, not in the application’s
history, also in a modal (the settings window). A text field
inside keeps its own undo. One scope per surface: a second
replaces the first. It goes with the plugin.
Sourcepub fn history_target(&mut self, surface: &str, scope: ScopeId) -> &mut Self
pub fn history_target(&mut self, surface: &str, scope: ScopeId) -> &mut Self
Declares which of the owner’s histories a focus surface (or a
panel, by its id) works on: under
Routing::Focus, Ctrl+Z and
Ctrl+Shift+Z go there while the focus is in it, whatever step is
newest elsewhere. The surface-side twin of a scope’s focus targets
(ScopeInfo::focus), which also make the scope active: this does
not, so an always-active history can claim surfaces too. One
history per surface: a second replaces the first. It goes with the
plugin.
Sourcepub fn on(
&mut self,
when: On,
f: impl FnMut(&AppHandle, &Lifecycle) + 'static,
) -> &mut Self
pub fn on( &mut self, when: On, f: impl FnMut(&AppHandle, &Lifecycle) + 'static, ) -> &mut Self
Calls f at a moment of the application’s life.
Sourcepub fn on_change(
&mut self,
prefix: &str,
f: impl FnMut(&Changed) + Send + 'static,
) -> &mut Self
pub fn on_change( &mut self, prefix: &str, f: impl FnMut(&Changed) + Send + 'static, ) -> &mut Self
Calls f after each change of a store path under prefix.
Sourcepub fn step(&mut self, spec: StepSpec) -> Result<&mut Self, CtxError>
pub fn step(&mut self, spec: StepSpec) -> Result<&mut Self, CtxError>
Declares a step of this plugin’s features that other plugins may watch, veto, replace or extend (ADR 0011).
Sourcepub fn before(
&mut self,
step: StepId,
f: impl Fn(&AppHandle, &Json) -> Before + 'static,
) -> &mut Self
pub fn before( &mut self, step: StepId, f: impl Fn(&AppHandle, &Json) -> Before + 'static, ) -> &mut Self
Runs before a step: lets it go, vetoes it or changes its arguments.
Sourcepub fn replace(
&mut self,
step: StepId,
f: impl Fn(&AppHandle, &Json) -> Result<Json, String> + 'static,
) -> &mut Self
pub fn replace( &mut self, step: StepId, f: impl Fn(&AppHandle, &Json) -> Result<Json, String> + 'static, ) -> &mut Self
Does a step instead of its default (the last plugin to replace a step wins).
Sourcepub fn after(
&mut self,
step: StepId,
f: impl Fn(&AppHandle, &Json, &Result<Json, String>) + 'static,
) -> &mut Self
pub fn after( &mut self, step: StepId, f: impl Fn(&AppHandle, &Json, &Result<Json, String>) + 'static, ) -> &mut Self
Runs after a step, with its arguments and result.
Sourcepub fn indicator(&mut self, indicator: Indicator) -> &mut Self
pub fn indicator(&mut self, indicator: Indicator) -> &mut Self
Adds an indicator to the status bar, fed by the journal’s events
(shown by strips::StripsPlugin), or, speaking for a panel
(Indicator::panel), to that panel’s icon in a folded side
area’s strip.
Its when clause, when it has one, must parse: one that does not
keeps the indicator hidden and is reported (indicator-when).
Sourcepub fn arrangement(&mut self, name: &str, layout: Layout) -> &mut Self
pub fn arrangement(&mut self, name: &str, layout: Layout) -> &mut Self
Offers a named layout of the workbench (an arrangement template):
what switching to name starts from and what resetting it goes
back to (see arrangements).
Source§impl Ctx<'_>
impl Ctx<'_>
Sourcepub fn mountable(&mut self, needs: Mountable) -> &mut Self
pub fn mountable(&mut self, needs: Mountable) -> &mut Self
Declares a component of the plugin’s (ADR 0013): what it needs. A component of the same id declared by another owner wins: this one is ignored, with a diagnostic; declared again by the same plugin (connected again), it replaces its own.
Sourcepub fn host_offer(&mut self, offer: HostOffer) -> &mut Self
pub fn host_offer(&mut self, offer: HostOffer) -> &mut Self
Declares a host of the plugin’s (ADR 0013): what it offers, with the same rule for a second declaration of an id.
Source§impl Ctx<'_>
impl Ctx<'_>
Sourcepub fn settings_page(
&mut self,
page: SettingsPage,
body: impl FnMut(&mut Ui, &AppHandle) + 'static,
) -> &mut Self
pub fn settings_page( &mut self, page: SettingsPage, body: impl FnMut(&mut Ui, &AppHandle) + 'static, ) -> &mut Self
Mounts a custom page in the settings window, drawn by body
(see crate::settings_pages). The page’s component is checked
against the settings page host first; a refusal, an empty id or
an id another plugin took is reported as a diagnostic and adds
nothing. Declared again by the same plugin, it replaces its own.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Ctx<'a>
impl<'a> !RefUnwindSafe for Ctx<'a>
impl<'a> !Send for Ctx<'a>
impl<'a> !Sync for Ctx<'a>
impl<'a> Unpin for Ctx<'a>
impl<'a> UnsafeUnpin for Ctx<'a>
impl<'a> !UnwindSafe for Ctx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more