Skip to main content

EditorHandle

Trait EditorHandle 

Source
pub trait EditorHandle: Send + 'static {
    type Window;
    type Error: Error;

    // Required methods
    fn run_until_closed(window: Self::Window) -> Result<(), Self::Error>;
    fn set_parent(
        &self,
        parent: ParentWindowHandle,
        window: &Self::Window,
    ) -> Result<(), Self::Error>;
    fn show(&self, window: &Self::Window) -> Result<(), Self::Error>;
    fn hide(&self, window: &Self::Window) -> Result<(), Self::Error>;
    fn set_size(
        &self,
        new_size: PhysicalSize<u32>,
        window: &Self::Window,
    ) -> Result<(), Self::Error>;
    fn host_main_thread_callback(&self, window: &Self::Window);
    fn param_value_changed(&self, id: &str, normalized_value: f32);
    fn param_modulation_changed(&self, id: &str, modulation_offset: f32);

    // Provided methods
    fn adjust_size(
        &self,
        new_size: PhysicalSize<u32>,
        window: &Self::Window,
    ) -> Option<PhysicalSize<u32>> { ... }
    fn set_fallback_scale_factor(
        &self,
        scale_factor: f64,
        window: &Self::Window,
    ) -> Result<(), Self::Error> { ... }
    fn on_virtual_key_from_host(
        &self,
        key_code: VirtualKeyCode,
        is_down: bool,
        modifiers: Modifiers,
    ) -> bool { ... }
    fn state_changed(&self) { ... }
}
Expand description

A handle to spawned instance of an Editor.

The host uses this to resize the editor’s window and to dispatch key events.

Required Associated Types§

Required Methods§

Source

fn run_until_closed(window: Self::Window) -> Result<(), Self::Error>

Open the window, and block the current thread until the window is closed. Used only for standalone targets.

Source

fn set_parent( &self, parent: ParentWindowHandle, window: &Self::Window, ) -> Result<(), Self::Error>

Source

fn show(&self, window: &Self::Window) -> Result<(), Self::Error>

Show the window

This will never be called on the standalone target.

Source

fn hide(&self, window: &Self::Window) -> Result<(), Self::Error>

Hide the window

This will never be called on the standalone target.

Source

fn set_size( &self, new_size: PhysicalSize<u32>, window: &Self::Window, ) -> Result<(), Self::Error>

Called by the wrapper when the host has resized the plugin’s view. The editor should resize its own window and contents to match these dimensions.

This is the counterpart to size(): after a successful set_size, size() should report the new dimensions.

This will never be called on the standalone target.

Source

fn host_main_thread_callback(&self, window: &Self::Window)

Source

fn param_value_changed(&self, id: &str, normalized_value: f32)

Called whenever a specific parameter’s value has changed. 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.

Source

fn param_modulation_changed(&self, id: &str, modulation_offset: f32)

Called whenever a specific parameter’s monophonic modulation value has changed.

Provided Methods§

Source

fn adjust_size( &self, new_size: PhysicalSize<u32>, window: &Self::Window, ) -> Option<PhysicalSize<u32>>

Return the closest supported size.

This will never be called on the standalone target.

Source

fn set_fallback_scale_factor( &self, scale_factor: f64, window: &Self::Window, ) -> Result<(), Self::Error>

Called when the host has a new suggested scale factor to use.

Right now this is never called on macOS since DPI scaling is built into the operating system there.

This will never be called on the standalone target.

Source

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.

This will never be called on the standalone target.

§Parameters
  • key_code: the virtual key the host reports.
  • is_down: true for key-down, false for key-up.
  • modifiers: which modifier keys were held when the event was generated.
Source

fn state_changed(&self)

Called when the plugin’s state has changed (i.e. a preset was loaded). The editor should rescan all of its parameters.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl EditorHandle for ()

Source§

type Window = ()

Source§

type Error = DummyEditorError

Source§

fn run_until_closed( _window: <() as EditorHandle>::Window, ) -> Result<(), <() as EditorHandle>::Error>

Source§

fn set_parent( &self, _parent: ParentWindowHandle, _window: &<() as EditorHandle>::Window, ) -> Result<(), <() as EditorHandle>::Error>

Source§

fn show( &self, _window: &<() as EditorHandle>::Window, ) -> Result<(), <() as EditorHandle>::Error>

Source§

fn hide( &self, _window: &<() as EditorHandle>::Window, ) -> Result<(), <() as EditorHandle>::Error>

Source§

fn host_main_thread_callback(&self, _window: &<() as EditorHandle>::Window)

Source§

fn set_size( &self, _new_size: PhysicalSize<u32>, _window: &<() as EditorHandle>::Window, ) -> Result<(), <() as EditorHandle>::Error>

Source§

fn param_value_changed(&self, _id: &str, _normalized_value: f32)

Source§

fn param_modulation_changed(&self, _id: &str, _modulation_offset: f32)

Implementors§