Hazel

Editor Panels

How the editor shell hosts panels, how a crate registers one, and the rules that keep a panel cheap when it is not on screen.

This page is the engine-side view: how the dock, the shell and the panel registries fit together, and why they are shaped the way they are. For a step-by-step guide to adding a panel from a plugin, see Editor Panels.

The model

The editor shell (renzora_shell) is plain bevy_ui. The dock model it lays panels out with (DockTree, splits, tabs, drag-docking, drop zones) lives in renzora_ember::dock; the shell supplies the workspace layouts and the chrome around them (top bar, ribbon, status bar). A panel is a tree of ordinary UI entities (Node, Text, BackgroundColor) built into a dock leaf, plus a little metadata so the dock tab and the Add Panel picker can name it.

Panels come from editor-scope plugins: a crate whose plugin table in Cargo.toml says scope = "Editor". Those plugins are linked into the renzora_editor image, so none of this code exists in a shipped game.

Registering a panel

A panel is two registrations, made from the plugin's build:

CallTraitWhat it does
register_shell_panel(id, title, icon, category)renzora_shell_api::RenzoraShellExtPuts the panel's title, Phosphor icon name and Add Panel category into ShellPanelRegistry.
register_panel_content(id, scroll, build)renzora_ember::panel::RegisterPanelContentRegisters the function that builds the panel's content, and marks the id in NativePanelIds so the shell does not draw its placeholder there.

The two are separate because they live in different crates for a dependency reason: the metadata is contract vocabulary (renzora_shell_api, which a game also links), while content building needs the UI framework. A native plugin reaches the trait as renzora::RenzoraShellExt.

The shell seeds metadata for its own panels from the PANEL_META table in renzora_shell/src/panels.rs. It inserts those as defaults only, so a crate that registers metadata for an id keeps its own entry.

fn register_shell_panel(
    &mut self,
    id: impl Into<String>,
    title: impl Into<String>,    // dock tab and picker label
    icon: impl Into<String>,     // kebab-case Phosphor name, e.g. "list-numbers"
    category: impl Into<String>, // groups the entry in Add Panel
) -> &mut Self;

fn register_panel_content<F>(&mut self, id: &'static str, scroll: bool, build: F) -> PanelScope<'_>
where
    F: Fn(&mut Commands, &EmberFonts) -> Entity + Send + Sync + 'static;
  • icon is resolved through renzora_ember::font::icon_glyph. An unknown name gives no glyph rather than an error.
  • scroll wraps the content in a scroll view. Pass false when the panel scrolls itself.
  • build returns the root entity of the content. EmberFonts carries ui, mono (both FontSource) and phosphor (Handle<Font>).
  • The returned PanelScope is where the panel's systems go (see below).

A complete panel

use bevy::prelude::*;
use renzora_editor_api::EditorSelection;
use renzora_ember::font::{icon_text, ui_font, EmberFonts};
use renzora_ember::panel::RegisterPanelContent;
use renzora_ember::reactive::tracked::bind_text;
use renzora_ember::theme::{accent, rgb, text_muted, text_primary};
use renzora_shell_api::RenzoraShellExt;

const PANEL_ID: &str = "selection_count";

#[derive(Default)]
pub struct SelectionCountPanelPlugin;

impl Plugin for SelectionCountPanelPlugin {
    fn build(&self, app: &mut App) {
        app.register_shell_panel(PANEL_ID, "Selection", "list-numbers", "Debug");
        app.register_panel_content(PANEL_ID, true, build_content);
    }
}

fn build_content(commands: &mut Commands, fonts: &EmberFonts) -> Entity {
    let root = commands
        .spawn(Node {
            align_items: AlignItems::Center,
            column_gap: Val::Px(8.0),
            padding: UiRect::all(Val::Px(16.0)),
            ..default()
        })
        .id();
    let icon = icon_text(commands, &fonts.phosphor, "list-numbers", accent(), 18.0);
    let label = commands
        .spawn((Text::new("Selected:"), ui_font(&fonts.ui, 13.0), TextColor(rgb(text_muted()))))
        .id();
    let value = commands
        .spawn((Text::new(""), ui_font(&fonts.mono, 13.0), TextColor(rgb(text_primary()))))
        .id();

    // Re-run only on a frame where EditorSelection changed.
    bind_text(commands, value, |rx| {
        let n = rx.get_resource::<EditorSelection>().map_or(0, |s| s.get_all().len());
        n.to_string()
    });

    commands.entity(root).add_children(&[icon, label, value]);
    root
}
[[package.metadata.renzora.plugin]]
type = "SelectionCountPanelPlugin"
scope = "Editor"

The build function only lays the panel out and declares bindings. Everything that changes afterwards is driven by the reactive layer; see Reactivity and Widgets.

Content is rebuilt on every activation

A dock leaf keeps only its active tab's content alive. dock::sync_panes despawns every inactive pane, and build_active_panels builds a pane again when its tab is activated. So build runs each time the panel is shown, not once per session.

The reason is layout cost. ui_layout_system walks the whole UI tree several times a frame and does not skip Display::None subtrees, and taffy's hidden-layout path clears its cache and recurses, so a hidden panel was never cheaper than a visible one. Keeping every panel ever opened alive meant every workspace visited kept charging layout for the rest of the session.

The cost of that trade is that view state on the entities (scroll offset, expanded rows, typed text) does not survive a tab switch. State that should survive goes in a Resource keyed by panel and read back in build; the inspector's InspectorSectionsOpen does this for its open sections. For scroll position, use a keyed scroll view (see Widgets).

No panel exists before a project is open. The shell's root is spawned when the app enters SplashState::Editor and despawned when it leaves, so do not look for a panel entity from Startup, and do not expect one to survive a project switch.

Systems: PanelScope

Bindings and keyed lists stop on their own when their panel is hidden, because the entities they target are gone. Ordinary systems do not. Add a panel's systems through the scope that register_panel_content returns:

app.register_panel_content("my_panel", true, build_content)
    .systems(Update, (refresh_thumbnails, relayout_tiles));

PanelScope::systems does not just add a run condition. A system behind a false condition is still visited by the executor every frame (access checked, condition run, dependents signalled), so gated systems of closed panels still cost an idle frame something each. Instead, the systems go into a schedule of the panel's own, PanelSchedule { outer, id }, and one exclusive dispatcher per outer schedule runs that panel schedule only while the panel is visible. A hidden panel costs one lookup a frame however many systems it has.

The consequence: a system added through .systems(..) cannot be ordered against a system outside the panel, because that system is in another schedule. .chain() and .after between the panel's own systems work as usual.

MethodUse
.systems(schedule, systems)View systems: run only while the panel is visible. The default.
.always(schedule, systems)Work that must not pause: an in-flight load, autosave, teardown that has to see a despawn. Also for a system that must sit at a particular point of a schedule; gate it yourself with .run_if(renzora_ember::dock::panel_active("my_panel")).
.app()The underlying &mut App, for resources, assets and reflection.

"Visible" means the live tab in any dock area: the primary dock, the global bottom panel (FixedDock) or a torn-off window (DockWindows). A panel dragged into the bottom panel keeps updating, because it is on screen.

run_if(in_state(SplashState::Editor)) is not a visibility gate. It is true for the whole editor session, so it keeps a system off the launcher and nothing more.

The regression guard

crates/renzora_ember/tests/panel_systems_gated.rs fails if a file that calls register_panel_content also has an ungated app.add_systems. It checks for gating of any kind, so a per-system .run_if(panel_active(..)) passes. A system that really must run while hidden is exempted at the call site, where the reason travels with the code:

// panel-systems-ungated: poll_store drains in-flight async requests
app.add_systems(Update, (poll_store, ..));

It is a test because a survey found 1283 of 1535 per-frame system registrations running unconditionally in an idle editor, almost all by authors who never knew the gate existed.

Dock areas

The editor draws three kinds of dock area, all from the same DockTree model and reconciler:

AreaTreeNotes
PrimaryDock::treeThe active workspace's layout, swapped on a workspace switch.
Bottom panelFixedDock::treeOne tree shared by every workspace, so a switch cannot disturb it.
Floating windowDockWindowState::treeOne per torn-off OS window.

The bottom panel is declared non-movable: its leaves have no whole-leaf drag grip (tabs still drag in and out), and its tab bar's filler carries FixedAreaHeader, which the shell uses as the panel's resize handle. Its Overlay and Layout modes (renzora_shell::dock::BottomDockMode, saved in layout.json) only change whether the panel node is absolutely positioned over the dock region or sits in flow beneath it; nothing in the tree or in panel_active depends on the mode.

The built-in workspaces are Scene, UI, Scripting, Animation, Materials and Particles (renzora_shell::dock::workspace_layouts). Every workspace's tree, the bottom panel and the active index are saved to ~/.renzora/layout.json; deleting that file resets to the shipped layouts. Registering a panel does not put it in a layout. It becomes available in Add Panel, under its category.

Depth inside a dock area

The bottom panel is overlaid at GlobalZIndex(100). GlobalZIndex lifts a node into the root stacking order, so any panel content that uses one below 100 disappears under the bottom panel's background once a user docks that panel there. Use renzora_ember::stacking::ZTier for depth inside panel content (see Widgets).

Press guards

A panel that acts on a press in its own empty space (clear the selection, start a box select, begin a drag) usually asks UiCursor::cursor_over on its content node. Two editor widgets sit over every panel's rect and pass the pointer through, so a press on them also reads as a press on your content:

ResourceSet whileImport
ScrollbarBusya visible scroll track is pressed, or a thumb is being draggedrenzora_ember::widgets::ScrollbarBusy
ResizeBusythe button is held after a press on any ResizeHandle: a dock divider, the bottom panel's grip, a floating window's edge, the window's own edgesrenzora_platform_api::resize::ResizeBusy (also at renzora_ember::resize::ResizeBusy)

A divider's visible line is 1 px but its grab strip is 11 px, so it overhangs about 5 px into the panes on both sides, inside your content rect. Bail out when either flag is set:

fn my_empty_press(
    mouse: Res<ButtonInput<MouseButton>>,
    scrollbar: Res<ScrollbarBusy>,
    resizing: Option<Res<ResizeBusy>>,
) {
    if !mouse.just_pressed(MouseButton::Left)
        || scrollbar.active()
        || renzora_platform_api::resize::resize_in_flight(&resizing)
    {
        return;
    }
    // ...
}

Both are refreshed in PreUpdate, so any Update system reads this frame's value. ResizeBusy lives in the contract so crates outside the UI stack can obey it (scene picking in renzora_gizmo does). Take it as Option<Res<..>>, since it exists only once ember has registered it; not_resizing is the same test as a run condition, for a system that only acts on a press.

The status bar

Status items do not need a panel:

use renzora_shell_api::{RenzoraShellExt, ShellStatusAlign, ShellStatusItem, ShellStatusSegment};

app.register_shell_status_item(ShellStatusItem {
    id: "fps_status",
    align: ShellStatusAlign::Right,
    order: 0,
    render: fps_segments,
});

fn fps_segments(world: &World) -> Vec<ShellStatusSegment> {
    let fps = world
        .get_resource::<bevy::diagnostic::DiagnosticsStore>()
        .and_then(|d| d.get(&bevy::diagnostic::FrameTimeDiagnosticsPlugin::FPS))
        .and_then(|f| f.average())
        .unwrap_or(0.0);
    vec![ShellStatusSegment::new("gauge", format!("{fps:.0} FPS"), [180, 190, 200])]
}

render runs every frame with &World. A segment is an icon name, text and an RGB colour, plus optionally .bar(ShellStatusBar::Busy) or .bar(ShellStatusBar::Fraction(f)) for progress, and .action(id) to send ShellActionInvoked(id) on click. Busy exists because a download with no known size has no honest fraction to show.

ShellStatusAlign::Ready is for work the editor is busy with (scripts or a plugin compiling): while such an item returns segments they replace the Ready label, and when it returns none, Ready comes back.

Top-bar buttons follow the same seam. register_shell_action adds a labelled chip at the right of the top bar and register_shell_tool an icon beside the Settings gear; a press writes ShellActionInvoked(id), which the owning crate reads. No callback crosses between the shell and the plugin.

Toolbars belong in the panel

There is no shared toolbar strip. A panel's controls are built inside its own content (the code editor and the material graph do this), so they are only built when the panel is docked and only drawn when it is visible.

The viewport is the exception, for a dependency reason. The shell has to put things in the viewport (its scene tabs), and renzora_shell depends on renzora_viewport, not the other way round. So renzora_ember::toolbar offers two mount points the viewport builds from:

FunctionWhere it mounts
register_viewport_tool_trailing(build)The right-hand end of the in-viewport tool strip (Select, Move, Rotate, Scale).
register_viewport_top_strip(order, build)A full-width bar under that strip. Lower order sits higher; the shell's scene tabs use 0.

Both are static registries rather than resources because the viewport is built from a panel-content closure that has no World to read a resource from. Register from Plugin::build.

Launcher pages

The launcher is a dashboard: a rail of pages, one shown at a time. renzora_splash owns the rail and its Projects and Changelog pages; other crates add pages:

use renzora_splash::{register_splash_section, SplashSection};

register_splash_section(app, SplashSection::new("plugins", "puzzle-piece", "Plugins", 40, build_page));

The arguments are a stable id, a Phosphor icon, the English rail label, the rail order (Projects is 0, Changelog 80) and a builder Fn(&mut Commands, &EmberFonts) -> Entity. Registering an id again replaces the earlier page.

  • The builder runs every time the page is opened, and again when the language changes, so anything live inside it must be a binding.
  • The rail label is translated through splash.section.<id>; the string passed in is only the fallback, since Plugin::build runs before a language is chosen.
  • The page's own systems need run_if(in_state(SplashState::Splash)). Registering a page schedules nothing.
  • The dependency runs from your crate to renzora_splash, never back. renzora_splash is linked into the runtime, so a splash that reached for an editor crate would drag it into every shipped game. renzora_marketplace's splash_plugins is the worked example.
  • The launcher draws before a project (and so a theme) is loaded, and uses its own fixed palette in renzora_splash::launcher::style.

Panels with a 3D preview

Material previews, the particle preview, the import dialog's model view and the thumbnail captures are each a camera, lights and sometimes a floor, spawned into the same World as the scene and as each other. A RenderLayers index is the only thing that keeps them apart, so every rig owns one layer.

The layers are allocated in one place, renzora_viewport_api (MATERIAL_PREVIEW_LAYER, PARTICLE_PREVIEW_LAYER, MODEL_THUMBNAIL_LAYER and the rest). Add a constant there for a new rig rather than a private one beside the camera: a rig can only tell a layer is free by seeing every other rig, and the crates that own them do not depend on each other. Two rigs sharing a layer never errors; one rig's floor and lights quietly render into the other's image.

use renzora_scene_api::{EditorLocked, HideInHierarchy, IsolatedCamera};
use renzora_viewport_api::MY_PREVIEW_LAYER; // the constant you added

commands.spawn((
    Camera3d::default(),
    Camera { is_active: false, ..default() },
    RenderTarget::Image(image.into()),
    RenderLayers::layer(MY_PREVIEW_LAYER),
    IsolatedCamera,
    HideInHierarchy,
    EditorLocked,
));

IsolatedCamera keeps the editor's environment and skybox systems from attaching the scene's environment map to an offscreen camera. HideInHierarchy and EditorLocked belong on every entity of the rig, to keep it out of the Hierarchy and out of selection.