pub struct PluginContext<P: ?Sized = dyn Params> { /* 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: ?Sized> PluginContext<P>
impl<P: ?Sized> PluginContext<P>
Sourcepub fn new(bridge: Arc<dyn EditorBridge>, params: Arc<P>) -> Self
pub fn new(bridge: Arc<dyn EditorBridge>, params: Arc<P>) -> Self
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: ?Sized>(&self, params: Arc<Q>) -> PluginContext<Q>
pub fn with_params<Q: ?Sized>(&self, params: Arc<Q>) -> PluginContext<Q>
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<dyn Params>
impl PluginContext<dyn Params>
Sourcepub fn from_closures(bridge: ClosureBridge, params: Arc<dyn Params>) -> Self
pub fn from_closures(bridge: ClosureBridge, params: Arc<dyn Params>) -> Self
Build a dyn-erased context from a ClosureBridge. Convenience
for format wrappers that compose state inline via closures.
Source§impl<P: Params + 'static> PluginContext<P>
impl<P: Params + 'static> PluginContext<P>
Sourcepub fn dyn_erase(self) -> PluginContext<dyn Params>
pub fn dyn_erase(self) -> PluginContext<dyn Params>
Drop the typed <P> and return the dyn-erased context that
crosses the Editor::open trait-object boundary.
Trait Implementations§
Source§impl<P: ?Sized> Clone for PluginContext<P>
impl<P: ?Sized> Clone for PluginContext<P>
Source§impl<P: ?Sized> Deref for PluginContext<P>
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: ?Sized> Deref for PluginContext<P>
Plugin authors read parameter fields directly via Deref:
state.gain.read(), state.bypass.value(). The state
here is &PluginContext<MyParams> and Deref::Target = MyParams.