pub trait Editor: Send {
// Required methods
fn spawn(
&self,
parent: ParentWindowHandle,
context: Arc<dyn GuiContext>,
) -> Box<dyn Any + Send>;
fn size(&self) -> (u32, u32);
fn set_scale_factor(&self, factor: f32) -> bool;
fn param_value_changed(&self, id: &str, normalized_value: f32);
fn param_modulation_changed(&self, id: &str, modulation_offset: f32);
fn param_values_changed(&self);
// Provided method
fn on_virtual_key_from_host(
&self,
_key_code: VirtualKeyCode,
_is_down: bool,
_modifiers: Modifiers,
) -> bool { ... }
}Expand description
An editor for a Plugin.
Required Methods§
Sourcefn spawn(
&self,
parent: ParentWindowHandle,
context: Arc<dyn GuiContext>,
) -> Box<dyn Any + Send>
fn spawn( &self, parent: ParentWindowHandle, context: Arc<dyn GuiContext>, ) -> Box<dyn Any + Send>
Create an instance of the plugin’s editor and embed it in the parent window. As explained in
Plugin::editor(), you can then read the parameter
values directly from your Params object, and modifying the
values can be done using the functions on the ParamSetter.
When you change a parameter value that way it will be broadcasted to the host and also
updated in your Params struct.
This function should return a handle to the editor, which will be dropped when the editor
gets closed. Implement the Drop trait on the returned handle if you need to explicitly
handle the editor’s closing behavior.
If set_scale_factor() has been called, then any created
windows should have their sizes multiplied by that factor.
The wrapper guarantees that a previous handle has been dropped before this function is called again.
Sourcefn size(&self) -> (u32, u32)
fn size(&self) -> (u32, u32)
Returns the (current) size of the editor in pixels as a (width, height) pair. This size
must be reported in logical pixels, i.e. the size before being multiplied by the DPI
scaling factor to get the actual physical screen pixels.
Sourcefn set_scale_factor(&self, factor: f32) -> bool
fn set_scale_factor(&self, factor: f32) -> bool
Set the DPI scaling factor, if supported. The plugin APIs don’t make any guarantees on when this is called, but for now just assume it will be the first function that gets called before creating the editor. If this is set, then any windows created by this editor should have their sizes multiplied by this scaling factor on Windows and Linux.
Right now this is never called on macOS since DPI scaling is built into the operating system there.
Sourcefn param_value_changed(&self, id: &str, normalized_value: f32)
fn param_value_changed(&self, id: &str, normalized_value: f32)
Called whenever a specific parameter’s value has changed while the editor is open. You don’t need to do anything with this, but this can be used to force a redraw when the host sends a new value for a parameter or when a parameter change sent to the host gets processed.
Sourcefn param_modulation_changed(&self, id: &str, modulation_offset: f32)
fn param_modulation_changed(&self, id: &str, modulation_offset: f32)
Called whenever a specific parameter’s monophonic modulation value has changed while the editor is open.
Sourcefn param_values_changed(&self)
fn param_values_changed(&self)
Called whenever one or more parameter values or modulations have changed while the editor is
open. This may be called in place of param_value_changed()
when multiple parameter values hcange at the same time. For example, when a preset is
loaded.
Provided Methods§
Sourcefn on_virtual_key_from_host(
&self,
_key_code: VirtualKeyCode,
_is_down: bool,
_modifiers: Modifiers,
) -> bool
fn on_virtual_key_from_host( &self, _key_code: VirtualKeyCode, _is_down: bool, _modifiers: Modifiers, ) -> bool
Called when the host delivers a virtual-key event to the plugin’s
view. Return true if the editor consumed the key (the wrapper
will tell the host to skip its own accelerator handling); return
false to let the host process the key normally.
The wrapper only invokes this for non-character “virtual” keys
(VirtualKeyCode::Backspace, the arrow keys, function keys,
modifier presses, etc.). Plain printable characters arrive through
the plugin window’s native keyboard path (on macOS, AppKit
keyDown: + NSTextInputContext) and are not routed here; consuming
them through this hook would double-dispatch text input.
Both key-down and key-up events are delivered; is_down is
true for press, false for release. Plug-ins that consume a
key on press should generally also return true for the
matching release so the host doesn’t pick up the release as a
separate accelerator.
This is primarily for text-input routing in hosts (notably
REAPER) that intercept certain keys (Space, Backspace, arrows,
Cmd-shortcuts) before they reach the plugin’s native view. The
editor should only return true if a text input in the editor
currently has focus and can consume the key.
§Parameters
key_code: the virtual key the host reports.is_down:truefor key-down,falsefor key-up.modifiers: which modifier keys were held when the event was generated.