Skip to main content

Editor

Trait Editor 

Source
pub trait Editor: Send {
Show 15 methods // 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 can_maximize(&self) -> bool { ... } fn min_size(&self) -> (u32, u32) { ... } fn max_size(&self) -> (u32, u32) { ... } fn size_increment(&self) -> Option<(u32, u32)> { ... } fn aspect_ratio(&self) -> Option<(u32, u32)> { ... } fn prefers_pow2(&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 can_maximize(&self) -> bool

Whether the editor permits the standalone window to be maximized (the WM maximize button / double-click-titlebar maximize / macOS zoom-and-fullscreen / Windows maximize box).

Standalone-only: in CLAP / VST3 / AU the host owns the window frame, so this is ignored there (same as size_increment’s WM-snap note). Subordinate to Self::can_resize - a non-resizable editor can never be maximized regardless of this value, since the standalone pins min == max, which already blocks it.

Defaults to false: the standalone host removes the maximize affordance from resizable editors, so the window stays within the edge-drag bounds the WM already enforces and can’t jump past the editor’s Self::max_size into an unpainted margin around the clamped surface. Override to true for editors that render correctly at arbitrary size (typically an unbounded max_size) and want the maximize affordance.

Source

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

Minimum size the editor can render at, in logical points. Defaults to (1, 1). Wrappers consult this for CLAP’s gui_get_resize_hints and VST3’s checkSizeConstraint. Ignored when can_resize() returns false.

Source

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

Maximum size the editor can render at, in logical points. Defaults to (u32::MAX, u32::MAX). Same wrapper consumers as min_size.

Source

fn size_increment(&self) -> Option<(u32, u32)>

Logical-point granularity for interactive resize, or None for free (pixel-precise) resizing. The standalone X11 host maps this onto WM resize increments (PResizeInc) so the window manager snaps edge-drags to whole cells - the same mechanism terminal emulators use to snap to character cells. The snap counts from Self::min_size, which is already cell-aligned, so every allowed size lands on a boundary. Ignored when can_resize() returns false.

Source

fn aspect_ratio(&self) -> Option<(u32, u32)>

Aspect-ratio constraint as (numerator, denominator), or None for free resizing. CLAP, VST3, AU v3, and standalone honour this; VST2 / LV2 / AAX silently ignore. Integer pair (not f64) avoids the Cubase-9 aspect-rounding quirk JUCE special-cases.

Source

fn prefers_pow2(&self) -> bool

Hint that the renderer prefers power-of-two surface sizes (some GPU-backed editors). Maps onto CLAP’s clap_gui_resize_hints.preserve_aspect_ratio / aspect_ratio_width siblings; ignored on formats without an equivalent.

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§