Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx<'a> { /* private fields */ }
Expand description

What a plugin registers through.

Implementations§

Source§

impl Ctx<'_>

Source

pub fn clip_type(&mut self, t: ClipType) -> Result<&mut Ctx<'_>, CtxError>

Declares a type of clipboard item, owned by this plugin (gone with it). Its format must not be declared already.

Source

pub fn clip_transform(&mut self, t: Transform) -> Result<&mut Ctx<'_>, CtxError>

Declares a clipboard transform, owned by this plugin.

Source

pub fn clip_sanitiser(&mut self, s: Sanitiser) -> Result<&mut Ctx<'_>, CtxError>

Declares a clipboard sanitiser, owned by this plugin.

Source

pub fn clip_endpoint( &mut self, name: &str, source: Option<Rc<dyn ClipSource>>, target: Option<Rc<dyn ClipTarget>>, ) -> &mut Ctx<'_>

Registers a component’s endpoint, owned by this plugin (gone with it); see register.

Source§

impl Ctx<'_>

Source

pub fn frame(&mut self, spec: FrameSpec) -> Result<&mut Ctx<'_>, CtxError>

Declares a frame of the context stack, owned by this plugin (gone with it). The plugin requires PLUGIN.

Source

pub fn frame_keybinding( &mut self, frame: &FrameSpec, keys: &str, command: CommandId, ) -> Result<&mut Ctx<'_>, 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>

Source

pub fn plugin(&self) -> &PluginId

The plugin registering.

Source

pub fn owner(&self) -> &OwnerId

The owner its registrations are tagged with.

Source

pub fn app(&self) -> AppHandle

The application, to keep in closures (blocks, handlers).

Source

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.

Source

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.

Source

pub fn is_connected(&self, plugin: &PluginId) -> bool

Whether another plugin is connected.

Source

pub fn command( &mut self, spec: CommandSpec, handler: impl Fn(&Call<'_>) -> Result<Value, String> + 'static, ) -> Result<&mut Ctx<'a>, 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.

Source

pub fn declare(&mut self, spec: CommandSpec) -> Result<&mut Ctx<'a>, CtxError>

Declares a command the application’s host runs (AppBuilder::host): keys, menus, palette and traces as for Ctx::command, no handler here.

Source

pub fn keybinding( &mut self, keys: &str, command: CommandId, when: &str, layer: Layer, ) -> Result<&mut Ctx<'a>, CtxError>

Binds keys to a command (layer defaults: use Layer::Default for a plugin’s own, Layer::Suggestion for a soft one).

Source

pub fn keybinding_with( &mut self, keys: &str, command: CommandId, when: &str, layer: Layer, options: BindOptions, ) -> Result<&mut Ctx<'a>, CtxError>

Binds keys to a command, listening as options say (on a surface, while typing, through modals).

Source

pub fn unbind( &mut self, keys: &str, layer: Layer, ) -> Result<&mut Ctx<'a>, CtxError>

Unbinds keys (in the layers below layer).

Source

pub fn command_icon( &mut self, command: CommandId, icon: &str, icon_on: Option<&str>, ) -> &mut Ctx<'a>

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).

Source

pub fn menu_item(&mut self, item: MenuItem) -> Result<&mut Ctx<'a>, CtxError>

Contributes a menu item.

Source

pub fn list_provider( &mut self, name: &str, f: impl Fn(&AppHandle, &WhenContext) -> Vec<ListItem> + 'static, ) -> &mut Ctx<'a>

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).

Source

pub fn submenu( &mut self, parent: MenuId, group: &str, order: i32, menu: MenuId, label: &str, ) -> Result<&mut Ctx<'a>, CtxError>

Declares a submenu under a menu (app.menu.view).

Source

pub fn panel( &mut self, spec: PanelSpec, draw: impl FnMut(&mut Ui, &AppHandle) + 'static, ) -> Result<&mut Ctx<'a>, 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.

Source

pub fn instance_panel( &mut self, spec: PanelSpec, draw: impl FnMut(&mut Ui, &AppHandle, &Instance) + 'static, ) -> Result<&mut Ctx<'a>, 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.

Experimental: may change in any release (docs/stability.md).
Source

pub fn zone( &mut self, zone: ZoneId, title: &str, ) -> Result<&mut Ctx<'a>, CtxError>

Declares a zone other plugins may contribute blocks to.

Source

pub fn block(&mut self, zone: ZoneId, block: Block) -> &mut Ctx<'a>

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.

Source

pub fn value( &mut self, path: &str, descriptor: Descriptor, ) -> Result<&mut Ctx<'a>, 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));
Source

pub fn setting( &mut self, id: SettingId, descriptor: Descriptor, ) -> Result<&mut Ctx<'a>, 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.

Source

pub fn collector( &mut self, collector: FnCollector, ) -> Result<&mut Ctx<'a>, CtxError>

Adds a collector to the debug bridge (removed with the plugin).

Source

pub fn service<T>( &mut self, token: &ServiceToken<T>, value: T, ) -> Result<&mut Ctx<'a>, CtxError>
where T: Send + Sync + 'static,

Provides a service.

Source

pub fn local_scope( &mut self, surface: &str, scope: impl LocalScope + 'static, ) -> &mut Ctx<'a>

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.

Experimental: may change in any release (docs/stability.md).
Source

pub fn history_target(&mut self, surface: &str, scope: ScopeId) -> &mut Ctx<'a>

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.

Experimental: may change in any release (docs/stability.md).
Source

pub fn on( &mut self, when: On, f: impl FnMut(&AppHandle, &Lifecycle) + 'static, ) -> &mut Ctx<'a>

Calls f at a moment of the application’s life.

Source

pub fn on_change( &mut self, prefix: &str, f: impl FnMut(&Changed) + Send + 'static, ) -> &mut Ctx<'a>

Calls f after each change of a store path under prefix.

Source

pub fn hook(&mut self, hook: Hook) -> Result<&mut Ctx<'a>, CtxError>

Registers an alter hook.

Source

pub fn step(&mut self, spec: StepSpec) -> Result<&mut Ctx<'a>, CtxError>

Declares a step of this plugin’s features that other plugins may watch, veto, replace or extend (ADR 0011).

Source

pub fn before( &mut self, step: StepId, f: impl Fn(&AppHandle, &Value) -> Before + 'static, ) -> &mut Ctx<'a>

Runs before a step: lets it go, vetoes it or changes its arguments.

Source

pub fn replace( &mut self, step: StepId, f: impl Fn(&AppHandle, &Value) -> Result<Value, String> + 'static, ) -> &mut Ctx<'a>

Does a step instead of its default (the last plugin to replace a step wins).

Source

pub fn after( &mut self, step: StepId, f: impl Fn(&AppHandle, &Value, &Result<Value, String>) + 'static, ) -> &mut Ctx<'a>

Runs after a step, with its arguments and result.

Source

pub fn indicator(&mut self, indicator: Indicator) -> &mut Ctx<'a>

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).

Experimental: may change in any release (docs/stability.md).
Source

pub fn arrangement(&mut self, name: &str, layout: Layout) -> &mut Ctx<'a>

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

pub fn story(&mut self, story: Story) -> Result<&mut Ctx<'a>, CtxError>

Contributes a gallery story.

Source§

impl Ctx<'_>

Declares a link this plugin shows (its About, a help entry, a tip): lint checks it; it goes with the plugin.

Source§

impl Ctx<'_>

Source

pub fn mountable(&mut self, needs: Mountable) -> &mut Ctx<'_>

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.

Source

pub fn host_offer(&mut self, offer: HostOffer) -> &mut Ctx<'_>

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<'_>

Source

pub fn settings_page( &mut self, page: SettingsPage, body: impl FnMut(&mut Ui, &AppHandle) + 'static, ) -> &mut Ctx<'_>

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§

Source§

impl Debug for Ctx<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,