Screens, areas and regions

Blender's resizable, splittable, dockable editor layout in every language. Drag the edges between areas, drag a corner to split, join or dock, maximize with Ctrl+Space; regions (headers, toolbars, sidebars) resize, hide and flip; panels reorder and pin. Ported from Blender's editors/screen.

Blender’s window is a screen of areas, each showing one editor, and each area is made of regions: a header, a toolbar, a sidebar, the main view. BUI has the same thing, ported from Blender’s editors/screen (screen_geometry.cc, screen_edit.cc, area.cc, screen_ops.cc, screen_draw.cc), so it behaves like Blender in every language.

The layout lives on Blender’s graph of shared vertices and edges, not on nested boxes. That is what makes joining, docking and moving several aligned edges at once possible.

What the user can do

Do this And this happens Blender’s operator
Drag the edge between two areas Both resize; the edge snaps near its limits SCREEN_OT_area_move
… with Shift Every edge aligned with it moves too the same, extending
… with Ctrl It snaps to 24ths of the screen and to other areas’ edges the same, SNAP_FRACTION_AND_ADJACENT
Escape or right-click while dragging The edge goes back the same, cancel
Drag an area’s corner inward The area splits; hold Ctrl during the drag (not at the press, which swaps) to snap to 12ths and other edges SCREEN_OT_area_join (split)
Drag a corner into a neighbor The two areas join the same (join)
Drag a corner into any other area The area docks beside it (left, right, top, bottom) or replaces it (center), with a preview; Ctrl and Alt adjust the size the same (dock)
Drag a corner out of the window The host is asked to open the area in a window of its own the same (new window)
Ctrl-drag a corner Two areas swap places SCREEN_OT_area_swap
Shift-drag a corner The host is asked to open a copy in a new window SCREEN_OT_area_dupli
Right-click an edge Vertical/Horizontal Split, Join, Swap Areas, Merge Edge SCREEN_OT_area_options
Right-click a header (not in Rust and JavaScript) Hide Header, Flip to Bottom, Move/Split Area, Maximize Area, Focus Mode, Duplicate Area into New Window, Close Area the header context menu
Click the header’s left corner The same area options the touch menu
Ctrl+Space / Ctrl+Alt+Space Maximize the area under the pointer / focus mode (regions hidden); again restores SCREEN_OT_screen_full_area
Drag a region’s inner edge The region resizes (toolbars snap to their columns, sidebars to their tabs) SCREEN_OT_region_scale
… all the way to the side The region hides, leaving a small tab; click the tab or drag it out to show it again the same
Press a region’s hotkey The region toggles (N for a sidebar, T for a toolbar, as you set them) SCREEN_OT_region_toggle
Drag a panel’s grip Panels reorder (the host hears where it went) panel dragging
Shift+click a panel header in a tabbed sidebar The panel is pinned: it shows under every tab PNL_PIN

Areas are drawn as in Blender: rounded corners, the theme’s editor border (editor_border, editor_outline, editor_outline_active), the highlight on the edge being dragged, and Blender’s previews for splitting, joining and docking.

Regions

An area’s children are its regions and one main view. A region is a header, tool_header, footer, asset_shelf, channels, nav_bar, toolbar, sidebar, execute or hud (the floating Adjust Last Operation panel), one of each, laid out in Blender’s order with Blender’s defaults:

Region Side Default size Notes
header, tool_header, footer, execute top/bottom the header height can’t be resized, only hidden and flipped
toolbar left/right one toolbar column snaps to 1, 2 or 2.7 columns; drawn over the main view
sidebar left/right 280 tabs for panel categories; drawn over the main view; narrow, it keeps only its tabs
channels, nav_bar left/right 200 / 160
asset_shelf top/bottom 120 drawn over the main view
hud floating its content’s size at the lower left of the main view

Each region takes these properties: size (unscaled pixels across the area), hidden, side, overlap (drawn over the main view or beside it), resizable (false: only hides), maxsize and hotkey. The user resizing, hiding or flipping it is reported to the region (BK_EV_RESIZE: the size and whether it is hidden).

An area works on its own too, outside a screen: a panel with a header and sidebars that resize and hide.

Areas the user makes

Splitting, docking and restoring a layout make areas. Each area has an editor name; a new area shows the editor of the one it came from, and the screen asks the host to fill it (BK_AREA_NEW) once the operation is done, as Blender queues its notifiers, so the handler may change the screen again. The bindings do this for you from a table of editors: one factory per editor name, which also lists the header’s editor-type menu.

Saving and restoring

The screen’s layout property is its arrangement as JSON: the vertices, each area’s corners and editor, and each region’s side, size and hidden state. Store it when the screen reports a change and set it back to restore: the screen makes or closes areas to match, and the vertices scale to the screen’s size.

The screen reports a change once the edit is done, as Blender queues its notifiers: an area you remove yourself is gone from the layout you save then. An area that is closing (its close handler is running, or one further down the chain) refuses split, join, dock and close, so close handlers that close each other close every area once.

In your language

Every example below is a whole file: the editors, a layout kept in layout.json between runs, and a window. The first run uses the starting layout; every change the user makes is saved, and the next run restores it.

Rust

src/main.rs
use blenderui::prelude::*;
use blenderui::screen::{AreaRef, AreaSplit, Editor, Editors, Region, Screen, ScreenEvent};
const LAYOUT_FILE: &str = "layout.json";
fn editors() -> Editors {
Editors::new()
.editor("3D Viewport", "VIEW3D", |_area: &AreaRef| {
Editor::new(div().child("viewport"))
.header(div().child("View"))
.toolbar(div())
.sidebar(Region::new(div().child("Item")).size(280).hotkey("n")
.on_resize(|e, _, _| println!("{} {}", e.size, e.hidden)))
})
.editor("Outliner", "OUTLINER", |area: &AreaRef| Editor::new(div().child(area.editor().to_owned())))
}
struct Layout {
saved: Option<String>,
}
impl Render for Layout {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
rsx! {
<body m-0 min-h-screen>
<Screen editors={editors()}
layout={AreaSplit::v(0.75, "3D Viewport", "Outliner")}
saved={self.saved.as_deref()}
on_change={|e: &ScreenEvent, _, _| { let _ = std::fs::write(LAYOUT_FILE, e.layout()); }} />
</body>
}
}
}
fn main() {
Application::new().run(|cx| {
let opts = WindowOptions {
window_bounds: Some(WindowBounds::Windowed(Bounds {
origin: point(px(0.0), px(0.0)),
size: size(px(900.0), px(600.0)),
})),
..Default::default()
};
let saved = std::fs::read_to_string(LAYOUT_FILE).ok();
cx.open_window(opts, |_, cx| cx.new(|_| Layout { saved })).unwrap();
});
}

Region contents are your HTML elements: the kit lays the areas and regions out, and each region’s elements are placed at its rect (they follow one render behind, as container queries do, and live during a drag). AreaRef (passed to each editor’s factory) has editor(), split, join, dock, swap, close, maximize, focus and restore. on_window gets the editor’s name of an area dragged out of the window; the window itself is yours to open.

The other languages

screen.jsx
import fs from 'node:fs'
import { render, Screen, Editor, Region, AreaSplit } from '@blender-ui/react' // Vue and Svelte: the same components
const LAYOUT_FILE = 'layout.json'
const saved = fs.existsSync(LAYOUT_FILE) ? fs.readFileSync(LAYOUT_FILE, 'utf8') : undefined
const editors = {
'3D Viewport': { icon: 'VIEW3D', render: area =>
<Editor header={<div>View</div>} toolbar={<div />}
sidebar={<Region size={280} hotkey="n" onResize={e => console.log(e)}><div>Item</div></Region>}>
<div>viewport</div>
</Editor> },
Outliner: { icon: 'OUTLINER', render: area => <Editor><div>{area.editor}</div></Editor> },
}
const { window } = render(
<Screen editors={editors} layout={AreaSplit.v(0.75, '3D Viewport', 'Outliner')}
saved={saved}
onChange={e => fs.writeFileSync(LAYOUT_FILE, e.layout)}
onWindow={e => console.log('open a window for', e.editor)} />,
{ title: 'Screens', width: 900, height: 600 })
window.body.style = 'margin: 0'

Run it as in JavaScript (bui build screen.jsx, or bundle it for Android).

The native DOM API has createScreen(document, { editors, layout, saved, onChange, onWindow }) and editorElement(document, { main, header, sidebar: { element, size, hotkey, onResize } }). An area keeps its editor element (and a text field’s draft) while the user drags an edge, and keeps its component state in React, Vue and Svelte while its neighbors are split, joined or closed; areas that close are released. JavaScript has no area operations (split, join, dock) yet: the user does them.

What isn’t there

  • Workspaces: several screens with tabs above them.
  • Global areas: Blender’s top bar and status bar that snap between two sizes.
  • Moving the HUD: the floating region stays at its corner.
  • Header-less panels and Blender’s floating panel drag (the dragged panel follows the pointer while the others slide): panels reorder as the grip crosses them.
  • JavaScript area operations (split, join, dock from code), and in Rust and JavaScript the header’s right-click menu (the corner and edge menus work).
  • Blender’s dedicated cursors (split, swap, the arrows) show as the nearest kit cursor.

Next steps

Edit this page on GitHub

Last updated