Skip to main content

RootPlugin

Trait RootPlugin 

Source
pub trait RootPlugin: Render + Sized {
    // Provided methods
    fn prepare(&mut self, _window: &mut Window, _cx: &mut Context<'_, Self>) { ... }
    fn style(
        &self,
        _surface: &mut Stateful<Div>,
        _window: &mut Window,
        _cx: &mut App,
    ) { ... }
    fn decorate(
        &self,
        surface: AnyElement,
        _root: &Root,
        _window: &mut Window,
        _cx: &mut App,
    ) -> impl IntoElement { ... }
}
Expand description

A presentation layer’s retained, per-window facilities.

Register during explicit application initialization, before creating windows. The view renders above application content. Base owns the root regardless of which plugins are registered; Cargo features never select its type.

On every root render, each plugin participates in three stages:

  1. RootPlugin::prepare synchronizes window state before elements are built.
  2. RootPlugin::style supplies defaults for the root surface.
  3. RootPlugin::decorate wraps the completed surface in presentation owned by the plugin.

The plugin’s Render output is mounted as an overlay above application content. Plugins and their overlays are processed in registration order, so later plugins appear above earlier ones. Notify the plugin entity after its state changes to render the root again; prepare and style must not notify, because they run during that render.

Factories are captured when a root is created, so registration affects only future windows.

Provided Methods§

Source

fn prepare(&mut self, _window: &mut Window, _cx: &mut Context<'_, Self>)

Synchronize settings derived from this plugin with the window.

This runs before the root surface and plugin overlays are built. It is intended for window-scoped state such as rem size or the active text selection scope, not for producing elements.

Source

fn style( &self, _surface: &mut Stateful<Div>, _window: &mut Window, _cx: &mut App, )

Apply this plugin’s default styles directly to the root surface.

Styles set on the Root instance are refined onto the surface after this hook and therefore take precedence over plugin defaults.

Source

fn decorate( &self, surface: AnyElement, _root: &Root, _window: &mut Window, _cx: &mut App, ) -> impl IntoElement

Add presentation around the completed root surface.

This runs after plugin defaults and instance styles have been applied. Return surface unchanged when no outer presentation is needed. Typical uses include client-side window borders or another structural wrapper. root provides read-only access to the root and its application view.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§