Skip to main content

Editor

Trait Editor 

Source
pub trait Editor: Send {
    // Required methods
    fn size(&self) -> (u32, u32);
    fn open(&mut self, parent: RawWindowHandle, context: PluginContext);
    fn close(&mut self);

    // Provided methods
    fn idle(&mut self) { ... }
    fn set_size(&mut self, _width: u32, _height: u32) -> bool { ... }
    fn can_resize(&self) -> bool { ... }
    fn set_scale_factor(&mut self, _factor: f64) { ... }
    fn state_changed(&mut self) { ... }
    fn screenshot(
        &mut self,
        params: Arc<dyn Params>,
    ) -> Option<(Vec<u8>, u32, u32)> { ... }
}
Expand description

Plugin GUI editor.

Required Methods§

Source

fn size(&self) -> (u32, u32)

Initial window size in logical points.

On a 2x Retina display, (400, 300) produces an 800x600 pixel window. On a 1x display, it produces a 400x300 pixel window.

Source

fn open(&mut self, parent: RawWindowHandle, context: PluginContext)

Create the GUI as a child of the host-provided parent window.

Source

fn close(&mut self)

Destroy the GUI.

Provided Methods§

Source

fn idle(&mut self)

Called ~60fps on the host’s UI thread for repaint/animation.

Source

fn set_size(&mut self, _width: u32, _height: u32) -> bool

Host requests a resize. Return true to accept.

Source

fn can_resize(&self) -> bool

Whether the plugin supports resizing.

Source

fn set_scale_factor(&mut self, _factor: f64)

Host notifies the editor of a new content scale factor.

DPI/scale is a host→plugin concept: on VST3 Windows the host delivers it via IPlugViewContentScaleSupport; on CLAP via clap_plugin_gui::set_scale; on macOS/Cocoa AppKit handles Retina backing automatically and hosts typically never call this at all. Editors that need to size off-screen buffers in physical pixels should react here, not by exposing a pull-style scale_factor() method that format wrappers were tempted to multiply size() by (which caused double-scaling on macOS VST3).

Source

fn state_changed(&mut self)

Plugin state was restored (preset recall, undo, session load).

Called after load_state() while the editor is open. Re-read any cached state from the plugin. Parameter values are already updated and will be picked up on the next render - this is only needed for custom state stored outside the parameter system.

Source

fn screenshot(&mut self, params: Arc<dyn Params>) -> Option<(Vec<u8>, u32, u32)>

Render a headless screenshot of the editor at its natural size.

params is a type-erased default-state instance the caller constructs from the plugin’s Params type. Backends use it to build a synthetic PluginContext / render context so the screenshot reflects parameter defaults without needing a live host.

Returns (rgba_pixels, physical_width, physical_height) - RGBA8 row-major, ready to feed into truce_test::assert_screenshot_pixels. Default impl returns None; backends that support headless capture (built-in widgets, egui, iced, slint) override.

Used by truce_test::assert_screenshot::<Plugin>(...) for one-line snapshot regression tests. Editors backed by frameworks that don’t expose a headless render path (e.g. raw-window-handle users wiring their own Metal/OpenGL) keep the default None.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§