pub struct PluginContext<P = dyn Params>where
P: ?Sized,{ /* private fields */ }Expand description
Context passed to Editor::open. Carries:
- An
Arc<dyn EditorBridge>- the host-plugin protocol surface (begin/set/end edit,request_resize,get_state, transport, …). - An
Arc<P>typed parameter store - plugin authorsDerefto&Pand read fields directly:state.gain.read().
The default P = dyn Params keeps the trait-object boundary
(Editor::open(ctx: PluginContext)) one-typed; editor crates
that want typed access (truce-egui, truce-slint, truce-iced) carry
their own <P> and reconstitute PluginContext<P> internally
via PluginContext::with_params using the Arc<P> they stored
at editor construction.
Clone is two refcount bumps (bridge + params). Editors that need
to hand the context to UI worker threads or animation timers clone
freely.
Implementations§
Source§impl<P> PluginContext<P>where
P: ?Sized,
impl<P> PluginContext<P>where
P: ?Sized,
Sourcepub fn new(bridge: Arc<dyn EditorBridge>, params: Arc<P>) -> PluginContext<P>
pub fn new(bridge: Arc<dyn EditorBridge>, params: Arc<P>) -> PluginContext<P>
Build a typed context from any EditorBridge implementor and
the plugin’s typed param store.
Sourcepub fn bridge(&self) -> &Arc<dyn EditorBridge> ⓘ
pub fn bridge(&self) -> &Arc<dyn EditorBridge> ⓘ
Access the underlying bridge handle. Editors that want to clone
the bridge into a worker thread without cloning the surrounding
PluginContext use this.
Sourcepub fn params(&self) -> &Arc<P> ⓘ
pub fn params(&self) -> &Arc<P> ⓘ
Access the typed param store as an Arc. Use this when you
need to capture the params in a 'static closure (e.g. an iced
Subscription or a worker thread).
Sourcepub fn with_params<Q>(&self, params: Arc<Q>) -> PluginContext<Q>where
Q: ?Sized,
pub fn with_params<Q>(&self, params: Arc<Q>) -> PluginContext<Q>where
Q: ?Sized,
Replace the param-store generic parameter while reusing the
same bridge. Used by editor crates that receive the dyn-erased
PluginContext from Editor::open and want the typed
PluginContext<P> for their UI closure.
pub fn begin_edit(&self, id: impl Into<u32>)
pub fn set_param(&self, id: impl Into<u32>, normalized: f64)
pub fn end_edit(&self, id: impl Into<u32>)
Sourcepub fn automate(&self, id: impl Into<u32>, normalized: f64)
pub fn automate(&self, id: impl Into<u32>, normalized: f64)
Begin + set + end in one call. Use for click-to-toggle widgets and similar single-shot edits where the gesture and the value arrive together.
pub fn request_resize(&self, w: u32, h: u32) -> bool
pub fn format_param(&self, id: impl Into<u32>) -> String
Sourcepub fn format_param_into(&self, id: impl Into<u32>, out: &mut String)
pub fn format_param_into(&self, id: impl Into<u32>, out: &mut String)
Format into a caller-owned buffer. See
EditorBridge::format_param_into for the allocation
trade-off - the caller’s buffer is reused, but bridges that
don’t override the default impl still allocate internally.
pub fn get_meter(&self, id: impl Into<u32>) -> f32
pub fn get_state(&self) -> Vec<u8> ⓘ
pub fn set_state(&self, data: Vec<u8>)
pub fn transport(&self) -> Option<TransportInfo>
Source§impl PluginContext
impl PluginContext
Sourcepub fn from_closures(
bridge: ClosureBridge,
params: Arc<dyn Params>,
) -> PluginContext
pub fn from_closures( bridge: ClosureBridge, params: Arc<dyn Params>, ) -> PluginContext
Build a dyn-erased context from a ClosureBridge. Convenience
for format wrappers that compose state inline via closures.
Source§impl<P> PluginContext<P>where
P: Params + 'static,
impl<P> PluginContext<P>where
P: Params + 'static,
Sourcepub fn dyn_erase(self) -> PluginContext
pub fn dyn_erase(self) -> PluginContext
Drop the typed <P> and return the dyn-erased context that
crosses the Editor::open trait-object boundary.
Trait Implementations§
Source§impl<P> Clone for PluginContext<P>where
P: ?Sized,
impl<P> Clone for PluginContext<P>where
P: ?Sized,
Source§fn clone(&self) -> PluginContext<P>
fn clone(&self) -> PluginContext<P>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<P> Deref for PluginContext<P>where
P: ?Sized,
Plugin authors read parameter fields directly via Deref:
state.gain.read(), state.bypass.value(). The state
here is &PluginContext<MyParams> and Deref::Target = MyParams.
impl<P> Deref for PluginContext<P>where
P: ?Sized,
Plugin authors read parameter fields directly via Deref:
state.gain.read(), state.bypass.value(). The state
here is &PluginContext<MyParams> and Deref::Target = MyParams.