Hazel

Editor Panels from a Plugin

A plugin can add a dock panel built from the editor's own UI framework, ember: the same widgets, the same theme and the same reactive layer every built-in panel uses. There is no separate plugin UI toolkit and no bridge. This page is written for native plugins, which reach ember as renzora::ui; an in-workspace editor crate uses the same API through renzora_ember.

use bevy::prelude::*;
use renzora::core::RenzoraShellExt;
use renzora::ui::font::{ui_font, EmberFonts};
use renzora::ui::panel::RegisterPanelContent;
use renzora::ui::theme::{rgb, text_primary};

const PANEL_ID: &str = "my_panel";

pub struct MyPanelPlugin;

impl Plugin for MyPanelPlugin {
    fn build(&self, app: &mut App) {
        app.register_shell_panel(PANEL_ID, "My Panel", "sparkle", "Tools");
        app.register_panel_content(PANEL_ID, true, build)
            .systems(Update, my_panel_system);
    }
}

fn build(commands: &mut Commands, fonts: &EmberFonts) -> Entity {
    commands
        .spawn((
            Text::new("Hello from a plugin"),
            ui_font(&fonts.ui, 12.0),
            TextColor(rgb(text_primary())),
        ))
        .id()
}

fn my_panel_system() {}

renzora::plugin!(MyPanelPlugin);

Open it from Add Panel in the dock; it appears under the category you registered.

Getting ember into a plugin

Ember needs no build configuration. The renzora a native plugin is compiled against is the shared renzora_dylib image, which carries the UI framework beside the contract, so renzora::ui::... resolves with nothing more in the manifest. The bevy and renzora entries in a plugin's Cargo.toml are for the IDE only; the build driver strips them before it hands any third-party dependencies to cargo.

The two registrations

They are separate on purpose, and both are needed.

register_shell_panel(id, title, icon, category) (from renzora::core::RenzoraShellExt) is the panel's metadata for the dock tab and the Add Panel picker. icon is a Phosphor icon name in kebab-case ("broom", "bug"); an unknown name resolves to no glyph rather than an error, so check the spelling. category groups the entry in Add Panel and is a free-form string: reuse an existing one or make your own.

register_panel_content(id, scroll, build) (from renzora::ui::panel::RegisterPanelContent) is what to build inside the tab. scroll wraps the content in a scroll view; pass false if the panel scrolls itself or virtualizes its own list.

The ids must match. A shell panel with no content shows the dock's placeholder; content with no shell entry has no tab to appear in.

The build function runs once

build is fn(&mut Commands, &EmberFonts) -> Entity. It runs once, the first time the tab is shown, and returns the root entity the dock parents into the leaf. Everything after that is driven by bindings, not by rebuilding.

This is the most important thing to understand about ember. A panel is not an immediate-mode UI that redraws every frame; it is a retained bevy_ui tree that you declare once and then bind. Despawning and respawning a panel's children every frame is the single most expensive mistake available.

EmberFonts carries the fonts:

FieldWhat it is
uithe themed UI face, a FontSource: pass it to ui_font(&fonts.ui, size)
monothe monospace face, for code and numbers
phosphorthe icon font, a Handle<Font>
default_ui, default_monothe built-in faces, ignoring any theme override

Never build a TextFont by hand. ui_font applies the user's UI scale and snaps the pixel size, which is why a panel built with it stays legible at 150% scale.

Systems are visibility-gated by default

register_panel_content returns a PanelScope. Systems added through .systems(schedule, systems) run only while the panel is the active tab somewhere, including in a torn-off dock window:

app.register_panel_content(PANEL_ID, true, build)
    .systems(Update, (handle_clicks, refresh_preview))
    .always(Update, watch_for_external_changes);

That default is the point: panel systems that keep running while their tab is hidden are the largest avoidable cost in the editor's idle frame. Use .always(...) only for work that is wrong to pause, such as a background load or cleanup that must observe a despawn while the tab is hidden.

Gated systems run in the panel's own schedule, so they cannot be ordered with .before() / .after() against systems outside it. PanelScope::app() hands back the &mut App for anything unrelated to the panel.

Reactivity, not polling

Bind the parts that change. A binding is a closure that reads the world and produces a value; the reactive driver runs it, compares with the previous value, and writes only on a change.

use renzora::EditorSelection;
use renzora::ui::reactive::tracked::bind_text;

let label = commands.spawn((Text::new(""), ui_font(&fonts.ui, 11.0))).id();
bind_text(commands, label, |rx| {
    let n = rx.get_resource::<EditorSelection>().map(|s| s.get_all().len()).unwrap_or(0);
    format!("{n} selected")
});

The value handed to a binding is an Rx, not a &World. It records every resource and component it reads, and the binding re-runs only when something it read has changed. That is what makes a hundred bindings cost nothing on an idle frame.

Function (in renzora::ui::reactive::tracked)WritesUse for
bind_text(cmds, e, |rx| -> String)the entity's Textlabels, counters, names
bind_text_color(cmds, e, |rx| -> Color)TextColorstatus colouring
bind_bg(cmds, e, |rx| -> Color)BackgroundColorselection highlight, validity
bind_display(cmds, e, |rx| -> bool)Node.displayshowing or hiding a whole subtree
bind_with(cmds, e, value, apply)anythingthe general form the others are built on
bind_2way(cmds, e, get, set)a widget's value, both wayssliders, checkboxes, dropdowns

bind_2way makes a widget an editor of state rather than a display of it: get reads the value for the widget to show, set writes the widget's new value back, and the binding keeps the widget honest when the value changes elsewhere (an undo, a script, another panel).

use renzora::ui::reactive::tracked::bind_2way;
use renzora::ui::widgets::checkbox;

let cb = checkbox(commands, false);
bind_2way(
    commands,
    cb,
    |rx| rx.get_resource::<MySettings>().is_some_and(|s| s.enabled),
    |world, on| {
        if let Some(mut s) = world.get_resource_mut::<MySettings>() {
            s.enabled = *on;
        }
    },
);

Text inputs have their own helper, renzora::ui::widgets::bind_text_input(cmds, input, get, set), because a text field has an editing state that must not be overwritten mid-keystroke.

Lists

keyed_list is the right tool whenever the number of rows can change:

use renzora::ui::reactive::tracked::keyed_list;
use renzora::ui::reactive::KeyedSnapshot;

keyed_list(commands, list_container, |rx| {
    let names: Vec<(Entity, String)> = vec![/* read from rx */];
    KeyedSnapshot {
        items: names.iter().map(|(e, n)| (e.to_bits(), hash_of(n))).collect(),
        build: Box::new(move |cmds, fonts, i| {
            let (_, name) = &names[i];
            cmds.spawn((Text::new(name.clone()), ui_font(&fonts.ui, 11.0))).id()
        }),
    }
});

items is one (stable key, content hash) pair per row, in display order. A row whose key and hash are unchanged is left alone, a changed hash rebuilds that row only, and added or removed keys spawn or despawn only those rows. Pick a key that survives reordering (an Entity's bits, a path's hash) and a content hash that covers everything the row draws; a hash that misses a field means that row stops updating.

The tracked keyed_list re-runs the snapshot only when something it read through the Rx changed. When the "did anything change" signal is not an ECS read (a scroll window computed from layout, say), renzora::ui::reactive::keyed_list_tokened(cmds, container, token, snapshot) skips the snapshot while token returns the same u64.

Despawns inside a reactive list must be try_despawn. The list may already have removed that row this frame.

What the Rx tracks

  • rx.get_resource::<R>(), rx.resource::<R>(), rx.contains_resource::<R>(): tracked.
  • rx.get::<C>(entity): tracked, per entity.
  • rx.untracked(): the raw &World, recorded as nothing. A binding whose reads are all untracked runs every frame, which is occasionally what you want (a clock) and usually a bug.
  • rx.manually_tracked(): the raw &World, for when you declare what you read with track_resource_id / track_component_id.

A binding that does not update usually reads something untracked. A binding that runs every frame usually slipped into untracked().

Widgets

renzora::ui::widgets is the editor's full set. Each is a builder that spawns a subtree and returns its root Entity, which you parent where you want and usually bind. The main groups:

  • Form controls: button(cmds, &fonts.ui, label), icon_button, icon_label_button, icon_label_button_parts, checkbox(cmds, checked), slider, slider_ranged, dropdown, dropdown_with_icons, text_input, password_input, textarea, radio, segmented, stepper, toggle_switch, multi_select, tags_input, search, form, font_picker, folder_picker.
  • Value editors: drag_value, spin_slider, vec3_edit, xy_pad, knob, fader, gauge, color_picker, property_row, asset_slot, asset_tile, curve, gradient. property_row is the labelled row the inspector is built from; use it and your panel lines up with the built-in ones.
  • Containers: section, card, accordion, collapsible, tabs, divider, grid, table, list_group, scroll_area, navbar, breadcrumb, pagination, sortable, tree.
  • Feedback and overlays: alert, badge, chip, progress, spinner, skeleton, toast, tooltip, modal, popover, popup, context_menu, menu, submenu, icon_menu.
  • Specialised: code_editor, node_graph, timeline, timeline_view, chart, markdown, rich_text, mixer, vu_meter, waveform, audio_player, image, scene, drag_window.

section is the workhorse:

use renzora::ui::theme::accent;
use renzora::ui::widgets::section;

let (root, body) = section(commands, fonts, "sliders", "Options", accent());
// parent `root` into your panel; spawn rows as children of `body`

The header collapses on click with no work from you. section_with_header, section_with_header_open and section_with_header_icon_open return more handles (the header, the initial open state, the leading icon).

The editor's gallery_* panels (Typography, Buttons, Inputs, Selection and the rest) render the widgets live from crates/renzora_ember/src/widgets/gallery.rs, which is also the shortest complete example of building a large tree from one build function. Widget behaviour in depth is in Widgets and Reactivity.

Theme colours

Never write a literal colour. renzora::ui::theme exposes the active palette as functions returning (u8, u8, u8), and rgb() converts one to a Bevy Color:

use renzora::ui::theme::{card_bg, rgb, text_muted};

BackgroundColor(rgb(card_bg()));
TextColor(rgb(text_muted()));

They are functions, not constants, because the palette changes when the user switches theme. Read them inside build and inside bindings, never into a static. menu_hover_bg() is the exception that returns a ready Color, since it carries alpha; it is the wash a menu row takes on hover, and every other hoverable surface uses hover_bg. For per-widget styling beyond colour, renzora::ui::theme::style(Role) returns the style a theme declares for a widget role. See Theming.

Handling interaction

A click is handled the ordinary Bevy way, with a marker component and a change filter on ember's UiInteraction:

use renzora::ui::UiInteraction;
use renzora::ui::widgets::button;

#[derive(Component)]
struct ResetButton;

fn build(commands: &mut Commands, fonts: &EmberFonts) -> Entity {
    let root = commands.spawn(Node::default()).id();
    let b = button(commands, &fonts.ui, "Reset");
    commands.entity(b).insert(ResetButton);
    commands.entity(root).add_child(b);
    root
}

fn my_panel_system(q: Query<&UiInteraction, (With<ResetButton>, Changed<UiInteraction>)>) {
    for interaction in &q {
        if *interaction == UiInteraction::Pressed {
            // ...
        }
    }
}

Changed<UiInteraction> matters: Pressed lasts as long as the button is held, so without it the action fires every frame of the click.

UiInteraction (Pressed, Hovered, None) is derived each frame from picking's hover and press state; Bevy's own Interaction is not on ember's widgets, so a query for it never sees a press. A node of your own opts in by carrying UiInteraction::default(). Hovered counts descendants, so a row stays hovered while the pointer is on a button inside it.

  • Give every node that owns a press renzora::ui::interaction::BLOCK. UI nodes default to PASS_THROUGH, so an unmarked node lets a press fall through to whatever is behind it, including the viewport, which reads it as a click in the scene.
  • Gate empty-space actions on ScrollbarBusy. A click handler on a panel's background otherwise fires while the user drags its scrollbar.

Other surfaces a plugin can contribute

A settings section

renzora::ui::settings_sections::RegisterSettingsSection adds a section to the Plugins tab of Settings, where users look for a plugin's preferences:

use renzora::ui::settings_sections::RegisterSettingsSection;

app.register_settings_section("my_plugin", "My Plugin", "sparkle", |cmds, fonts| {
    let root = cmds.spawn(Node { flex_direction: FlexDirection::Column, ..default() }).id();
    // rows, bound the same way as a panel
    root
});

The build runs each time Settings opens. Registering an existing id replaces it.

A status-bar item

use renzora::core::{RenzoraShellExt, ShellStatusAlign, ShellStatusItem, ShellStatusSegment};
use renzora::EditorSelection;

app.register_shell_status_item(ShellStatusItem {
    id: "my_count",
    align: ShellStatusAlign::Right,
    order: 10,
    render: |world| {
        let n = world.get_resource::<EditorSelection>().map(|s| s.get_all().len()).unwrap_or(0);
        vec![ShellStatusSegment::new("cursor-click", format!("{n}"), [160, 160, 170])]
    },
});

render is a plain fn(&World) -> Vec<ShellStatusSegment> called every frame, so keep it cheap. The colour is a [u8; 3] (a theme function's tuple must be converted) and is a request: the shell adjusts its lightness until it is readable against the status bar, keeping the hue.

  • .bar(ShellStatusBar::Fraction(f)) draws a determinate progress fill; ShellStatusBar::Busy draws a sweeping block. Use Busy whenever you do not genuinely know the total, and put the real numbers in the text.
  • .action(id) makes the segment clickable: a click sends a ShellActionInvoked with that id, the same message a top-bar button sends.
  • ShellReadyStatus replaces the status bar's left-hand "Ready" text: set label to Some(text) for a transient message and back to None to restore it.

A top-bar button

use renzora::core::{RenzoraShellExt, ShellActionInvoked, ShellActionItem};

app.register_shell_action(ShellActionItem {
    id: "my_plugin.open",
    icon: "storefront",
    label: Some(|| "My Thing".to_string()),
    color: Some([167, 130, 245]),
    tooltip: || "Open My Thing".to_string(),
    order: 0,
});

fn open_my_thing(mut invoked: MessageReader<ShellActionInvoked>) {
    if invoked.read().any(|m| m.0 == "my_plugin.open") {
        // ...
    }
}

Only the id crosses the boundary (no callback, no type), so a plugin the shell has never linked can put a control in the chrome, and anything else that should open the same thing writes the same message. label and tooltip are functions because registration happens during App assembly, before the user's language is known. color tints the glyph and fill; leave it None for an icon-only button.

register_shell_tool takes the same ShellActionItem and places it just right of the Settings gear as an icon-only glyph (label and color are ignored there). Presses arrive as ShellActionInvoked in the same way.

Viewport toolbar and strips

Three free functions in renzora::ui::toolbar, each taking a Fn(&mut Commands, &EmberFonts) -> Entity:

FunctionWhere it lands
register_viewport_tool_trailing(build)the right-hand end of the viewport tool strip
register_viewport_tool_group(key, build)spliced into the tool strip as a draggable group that remembers its position
register_viewport_top_strip(order, build)a full-width bar between the tool strip and the scene

Choose by width: the strip has little room left, so two or three controls belong there and anything wider belongs in a top strip. A tool group should bind_display its root off when it is not relevant. Keep a group's key stable across releases, or users' arranged toolbars reset.

For buttons on the viewport's left-edge shelf, use register_tool from the Editor API.

A viewport mode

A mode only exists while something makes it do something, so modes are registered:

use renzora::viewport_types::{ViewportMode, ViewportModeRegistry, ViewportView};

app.init_resource::<ViewportModeRegistry>();
app.world_mut()
    .resource_mut::<ViewportModeRegistry>()
    .register(ViewportMode::Sculpt, &[ViewportView::Three]);

The Mode dropdown lists the built-in modes for each view (ViewportMode::for_view) plus registered ones. A mode the active view does not offer is reset on the next frame, so an unregistered mode cannot be entered at all. Gate your systems on the mode with run_if.

Gizmos

An ordinary Gizmos system draws into the viewport with no registration: read EditorSelection and draw around what is selected. Gate it with in_three_view / in_two_view when the visual only makes sense through one camera.

Switching the workspace

register_workspace(name, DockTree) contributes a layout. renzora::ui::workspace::WorkspaceSwitch drives which one is showing: the shell writes names and active into it every frame and takes requested back.

use renzora::ui::workspace::WorkspaceSwitch;

fn go_to_materials(mut switch: ResMut<WorkspaceSwitch>) {
    if switch.names.iter().any(|name| name == "Materials") {
        switch.requested = Some("Materials".into());
    }
}

Ask by name, never by index: the list changes as plugins register. A name that matches nothing is dropped with a warning.

Why a plugin's panel is themed correctly

Ember keeps the theme palette, the stylesheet, the UI font scale and the viewport toolbar lists in process-global statics, one set per process. A plugin that linked a private copy of ember would get its own set and every one would fail silently: default colours whatever the theme, and toolbar registrations pushed into a list nothing reads. So ember is embedded in the shared renzora_dylib image and a plugin reaches it through that image. It is the same reason the loader refuses every native plugin when dynamic_linking is off.

Pitfalls

  • Spawn floating UI at the root, never as a child. A popup, menu, tooltip or modal parented under the widget that opened it inherits that widget's clipping; an Overflow::clip() anywhere up the chain hides it. Ember's own popup, menu and modal builders spawn parentless.
  • A floating surface must carry OverlaySurface (renzora::ui::widgets::popup), or clicks pass through it into whatever is behind.
  • Never query Query<&Window>.single() unfiltered. With a torn-off dock window open there is more than one window.
  • UI nodes have no GlobalTransform. A system that queries one compiles and never matches anything. Use UiGlobalTransform.
  • Do not order systems against screen_menu_dismiss.
  • Give scene content a Name. The Hierarchy lists (Entity, &Name), and only named entities are saved.

Where to look for examples

The reference for panel code is the editor's own panels: they use exactly this API, with nothing a plugin lacks.

Look atFor
crates/renzora_ember/src/widgets/gallery.rsbuilding a large tree from one build function, rendered live in the gallery panels
crates/renzora_inspectorproperty_row, sections, and two-way bindings over live component data
crates/renzora_hierarchykeyed_list over a changing entity set, with selection
crates/renzora_ember/src/widgets/exactly what each builder spawns

For the editor's behaviour hooks (inspector sections, presets, shortcuts, tools, context menu rows), see Editor API.