Panels and layout
Updated
Panels and layouts are the containers of a UI. A UI Layout arranges its children in a row or a column; a UI Panel is a layout with a visible surface: a fill, rounded corners and an optional border. Around them sit a few helpers: UI Screen Space pins a panel to the screen, UI Backdrop gives a world panel a solid back, UI Divider and UI Spacer separate and push elements apart, UI Selection Group makes toggles behave like radio buttons, and UI Handle shows a grip to drag a panel by.
Before you start
Section titled “Before you start”- Read the UI overview for roots, nested elements, layout pixels and the theme.
- Scripts react to UI through a Signal Emitter and
on(signal, …). See Scripting for hooks and signals. - A panel can be dragged with a Grabbable; see Input and interaction.
UI Layout
Section titled “UI Layout”The UI Layout component (comp-ui-layout) makes its entity a flexbox container: its children flow along flexDirection, spaced by gap, inside padding. It draws nothing. The UI Layout entity (ent-ui-layout) carries only a Layout; the UI Panel and UI List entities carry one too.
| Prop | Type | Default | Description |
|---|---|---|---|
flexDirection |
'row' or 'column' |
'column' |
Direction the children flow along. |
alignItems |
'center', 'flex-start', 'flex-end', 'stretch' |
'stretch' |
How children line up across the flow. |
justify |
'center', 'flex-start', 'flex-end', 'space- |
'flex-start' |
How children spread along the flow. |
width, height |
number or 'N%' |
root: 300 px wide; otherwise fits the content | Fixed size in px, or a percentage of the parent. |
minWidth, maxWidth, minHeight, maxHeight |
number or 'N%' |
none | Floors and ceilings for a size that fits its content or flexes. |
flexGrow |
number | none | Share of the parent’s leftover space: 1 on each of two children splits it evenly. |
gap |
number | 12 from the theme; 0 in a UI List |
Space between children, in px. |
padding |
number or number[] | 0 |
Space inside the box, in px. See Spacing. |
margin |
number or number[] | none | Space outside the box, in px. See Spacing. |
positionType |
'relative' or 'absolute' |
'relative' |
An absolute nested layout is placed against its parent’s edges and takes no room in the flow. |
positionTop, positionRight, position, positionLeft |
number | unset | Insets from the parent’s edges, in px, for an absolute layout. |
foreground |
boolean | false |
Draw a nested layout above images in the normal flow, for badges and overlays. |
pixelSize |
number | 0.003 |
Metres per layout pixel. Root only; ignored under UI Screen Space. |
stackOrder |
number | automatic | Root only. Among overlapping roots, higher draws in front and takes the pointer first. |
renderMode |
'world' or 'overlay' |
'overlay' |
Root only. See Drawing order. |
- Root size. A root is 300 px wide by default and as tall as its content: 0.9 m wide at the default
pixelSize. Scale the entity, or changepixelSize, to resize it in the world. - Rows and columns. A nested layout with no
widthfits its content. Give its childrenflexGrow: 1to share a row, or put a UI Spacer between them to push them apart.
Drawing order
Section titled “Drawing order”Root layouts and panels are drawn as an overlay by default: after the scene, so walls and objects never cut through them, while they keep their place and size in the world. Set renderMode: 'world' on a root when the panel should be hidden behind objects in front of it, like a real sign. Nested elements always follow their root.
When roots overlap, each gets a distinct order from the scene hierarchy. Set stackOrder when one must stay in front, such as a dialog over a menu: the higher number draws in front and receives the pointer first. Clearing it goes back to the automatic order.
UI Panel
Section titled “UI Panel”The UI Panel component (comp-ui-panel) paints the box behind a layout’s children. The UI Panel entity (ent-ui-panel) carries a Layout and a Panel, and it is the entity that takes a panel’s extras: UI Backdrop, UI Handle, Grabbable, Billboard, Selectable, Outline, UI Tooltip, Enable on Signal and Don’t Unload. Moving or animating a panel moves all its controls with it.
| Prop | Type | Default | Description |
|---|---|---|---|
background |
string | the theme’s surface colour | Fill colour. |
opacity |
number | 1 |
Alpha of the fill, 0 to 1. 0 draws no fill, for an invisible grouping panel. Text and controls stay opaque. |
borderRadius |
number or number[] | 12 from the theme |
Corner radius in px, per corner. See Spacing. |
borderColor |
string | none | Outline colour. The border is drawn only when this is set. |
borderWidth |
number or number[] | 2 from the theme, when borderColor is set |
Outline thickness in px, per side. |
Spacing
Section titled “Spacing”Every UI component that draws a box takes padding and margin as CSS does: one number, or an array of one to four numbers, in px.
| Value | Applies to |
|---|---|
8 |
All four sides. |
[4, 12] |
Top and bottom 4, left and right 12. |
[4, 12, 16] |
Top 4, left and right 12, bottom 16. |
[4, 8, 12, 16] |
Top, right, bottom, left, clockwise. |
Padding is inside the box, under its fill and border; margin is outside, in the parent’s layout. Margin may be negative; padding may not. borderWidth takes the same one to four values, one per side. borderRadius takes one to four corners clockwise from the top-left: [16, 16, 0, 0] rounds only the top corners. A value that is not a number or an array of one to four numbers throws when you set it.
UI Panel, UI List, UI Menu Item, UI Screen Space, UI Selection Group and UI Render Scene draw no box of their own: space them with their entity’s UI Layout.
UI Screen Space
Section titled “UI Screen Space”The UI Screen Space component (comp-ui-screen-space) pins a root panel to the viewport, for HUDs, docks and overlays on desktop and mobile. The panel draws one layout pixel per screen pixel, over the scene, and keeps its place through every window resize.
| Prop | Type | Default | Description |
|---|---|---|---|
anchor |
'top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom- |
'center' |
The point of the screen, and of the panel, pinned together. |
insetX |
number | 0 |
Screen pixels in from the anchored edge horizontally. On a centred anchor, positive moves right. |
insetY |
number | 0 |
Screen pixels in from the anchored edge vertically: down from top, up from bottom, down on a centred anchor. |
screenScale |
number | 1 |
Size on screen: 1 is one layout pixel per screen pixel, 0.5 half size. Insets stay in screen pixels. |
- Always on top. Nothing in the scene hides or cuts a screen-space panel, and a pointer ray through it hits the panel, not the wall behind. Outlines and bloom never land on it.
- Root only. On a nested element it does nothing.
- Transform. The entity’s Transform has no effect while Screen Space places it; move it with
anchorand the insets. Disabling or removing Screen Space puts the panel back at its transform in the world. - Editor and play. It places the panel in both, so you see the HUD where it will be.
- Shared placement. A panel’s screen placement can be shared with everyone in a room through the
ui-screen-spacenetwork trait (NetworkTraitType.UIScreenSpace). See Multiplayer.
UI Backdrop
Section titled “UI Backdrop”The UI Backdrop component (comp-ui-backdrop) adds a solid plane behind a root UI Panel, so it is not see-through from behind. The plane follows the panel’s size and corners as its content changes. A nested panel has no backdrop.
| Prop | Type | Default | Description |
|---|---|---|---|
color |
string | the theme’s surface colour | Colour of the back. |
opacity |
number | 0.5 |
0 to 1. Below 1 the scene shows through the back. |
padding |
number or number[] | 0 |
How far it bleeds past the panel, in px, per side. |
offset |
number | 0.002 |
Distance behind the panel, in metres. |
UI Divider
Section titled “UI Divider”The UI Divider component (comp-ui-divider) draws a thin line between elements. It stretches across its parent unless length is set and takes no pointer. Entity: UI Divider (ent-ui-divider).
| Prop | Type | Default | Description |
|---|---|---|---|
orientation |
'horizontal' or 'vertical' |
'horizontal' |
horizontal separates stacked rows; vertical separates the items of a row. |
color |
string | the theme’s divider colour | Line colour. |
thickness |
number | 1 |
Line thickness in px. |
length |
number | stretches | Fixed length in px. |
padding, margin |
number or number[] | none | See Spacing. |
UI Spacer
Section titled “UI Spacer”The UI Spacer component (comp-ui-spacer) is an invisible, flexible gap. Between siblings in a row or column it takes the free space and pushes them apart: A · Spacer · B sends A and B to opposite ends. Entity: UI Spacer (ent-ui-spacer).
| Prop | Type | Default | Description |
|---|---|---|---|
grow |
number | 1 |
Share of the free space it takes, relative to other growing siblings. 0 keeps it at size. |
size |
number | 0 |
Minimum size in px along the parent’s flow, kept even with no free space. |
padding, margin |
number or number[] | none | See Spacing. |
UI Selection Group
Section titled “UI Selection Group”The UI Selection Group component (comp-ui-selection-group) makes toggles exclusive, like radio buttons: when one member turns on, every other member of the same group turns off. Add it to UI Checkbox, UI Switch, UI Toggle Button or UI List Item entities and give them the same group.
| Prop | Type | Default | Description |
|---|---|---|---|
group |
string | '' |
Members with the same name are exclusive. Empty: not grouped. |
- A group spans the whole scene, so its members can sit in different panels.
- A member that starts checked turns the others off when it joins.
- Turning a member on from a script with
setChecked(true)applies the group too. - Turning a member off leaves the group with nothing selected; the group never forces one on.
- A disabled or inactive member leaves the group.
- Pair it with a checkbox’s
radio: truefor the round radio look.
UI Handle
Section titled “UI Handle”The UI Handle component (comp-ui-handle) draws a pill-shaped grip just outside one edge of a UI Panel, to show the player where to grab it. It is a visual cue only: the drag comes from a Grabbable on the same panel, which treats the grip as part of the panel.
| Prop | Type | Default | Description |
|---|---|---|---|
placement |
'top', 'bottom', 'left', 'right' |
'top' |
Edge the grip sits on. |
length |
number | 64 |
Length along the bar, in px. |
thickness |
number | 12 |
Thickness across the bar, in px. |
color |
string | the theme’s handle colour | Fill colour. |
radius |
number | half the thickness |
Corner radius in px; the default is a full pill. |
margin |
number or number[] | 8 |
Gap between the panel edge and the bar, in px. Only the placement side is used. |
Examples
Section titled “Examples”1. Build a panel from code
Section titled “1. Build a panel from code”#pragma lifecycle(startup)
function startup() { const panel = new UIPanelEntity(); panel.getComponent(UILayoutComponent).setProps({ width: 360, padding: 20, gap: 12, alignItems: 'center' }); panel.getComponent(UIPanelComponent).setProps({ backgroundColor: '#111827', borderColor: '#334155', borderRadius: 18 });
const title = new UILabelEntity(); title.getComponent(UILabelComponent).setProps({ text: 'Welcome', fontSize: 28 });
const line = new UIDividerEntity();
const hint = new UILabelEntity(); hint.getComponent(UILabelComponent).setProps({ text: 'Walk to the portal to begin.', color: '#a5b4fc' });
panel.add(title, line, hint); panel.position.set(0, 1.6, -2); scene.add(panel);}A Behavior script builds a world-space panel from code, with a title, a divider and a hint laid out as a column: UIPanelEntity, UILabelEntity and UIDividerEntity added to the scene.
Drag to orbit the camera around the panel, scroll to zoom.
How it works:
new UIPanelEntity()creates a panel that already carries a UI Layout and a UI Panel;getComponentreaches each one to set its props.- The labels and the divider are added under the panel with
panel.add(...), in the order they should appear. Because they are nested, their own transforms are ignored and the column layout places them. scene.add(panel)puts the root in the scene. Its position sets where it stands in the world.
2. A toolbar row with a spacer
Section titled “2. A toolbar row with a spacer”#pragma lifecycle(startup)
// Scene: a UI Panel named 'Toolbar' whose UI Layout is a row// (flexDirection 'row', alignItems 'center').// The script fills it: a title on the left, two buttons on the right.function startup() { const toolbar = findEntity('Toolbar'); toolbar.getComponent(UILayoutComponent).setProps({ width: 480, padding: [8, 12], gap: 8 });
const title = new UILabelEntity(); title.getComponent(UILabelComponent).setProps({ text: 'Gallery', fontSize: 20 });
const spacer = new UISpacerEntity();
const share = new UIButtonEntity(); share.getComponent(UIButtonComponent).setProps({ text: 'Share', variant: 'subtle' }); share.addComponent(new SignalEmitterComponent({ signal: 'toolbar/share' }));
const close = new UIButtonEntity(); close.getComponent(UIButtonComponent).setProps({ text: 'Close' }); close.addComponent(new SignalEmitterComponent({ signal: 'toolbar/close' }));
toolbar.add(title, spacer, share, close);
on('toolbar/close', (event) => { if (event.eventType === EventType.UIButton.Press) toolbar.setEnabled(false); }); on('toolbar/share', (event) => { if (event.eventType === EventType.UIButton.Press) log('share pressed'); });}A script fills a row panel with a title, a UI Spacer and two buttons, so the title sits on the left and the buttons on the right; Close hides the toolbar.
Press Share to log a message, and Close to hide the toolbar. Drag outside the panel to orbit the camera, scroll to zoom.
How it works:
- The spacer between the title and the buttons takes all the free space in the row, so the title sits at the left edge and the buttons at the right.
padding: [8, 12]puts 8 px above and below and 12 px left and right.- Each button gets its own Signal Emitter, so each press arrives on its own signal. Disabling the toolbar entity hides it and everything in it.
3. A HUD that moves between corners
Section titled “3. A HUD that moves between corners”#pragma lifecycle(startup)
// Scene: a UI Panel named 'HUD' with a UI Screen Space component,// containing a UI Button named 'Move' whose Signal Emitter uses 'hud/move'.const CORNERS = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];let index = 0;
function startup() { const screen = findEntity('HUD').getComponent(UIScreenSpaceComponent); screen.setProps({ anchor: CORNERS[index], insetX: 16, insetY: 16 });
on('hud/move', (event) => { if (event.eventType !== EventType.UIButton.Press) return; index = (index + 1) % CORNERS.length; screen.setProps({ anchor: CORNERS[index] }); });}Each press of Move steps a screen-space HUD round the four corners of the screen by changing its UI Screen Space anchor.
Press Move to send the HUD to the next corner of the screen.
How it works:
- UI Screen Space pins the panel to an
anchorof the screen; the insets keep it 16 screen pixels away from the edges whatever the window size. - Each press moves the anchor to the next corner. The panel’s Transform plays no part while Screen Space places it.
4. A draggable panel with a grip and a solid back
Section titled “4. A draggable panel with a grip and a solid back”#pragma lifecycle(startup)
function startup() { const panel = findEntity('Inventory');
// Pointers and XR hands can drag it, by a handle along the bottom. panel.addComponent(new GrabbableComponent()); panel.addComponent(new UIHandleComponent({ placement: 'bottom', length: 96 }));
// An opaque back, so the panel is not see-through from behind. panel.addComponent(new UIBackdropComponent({ opacity: 1, padding: 4 }));
// Keep it in front of other overlapping panels. panel.getComponent(UILayoutComponent).setProps({ stackOrder: 50 });}An inventory panel that a Behavior script makes draggable: a Grabbable, a UI Handle grip under it and an opaque UI Backdrop so it is not see-through from behind.
Drag the grip under the panel, or the panel itself, to move it. Drag the background to orbit round and see its solid back; scroll to zoom.
How it works:
- A Grabbable on the panel lets the player drag it with a mouse, a finger or an XR controller. The UI Handle only draws the grip; the Grabbable treats the grip as part of the panel, so grabbing the grip drags the whole panel.
- The UI Backdrop adds a solid plane behind the panel;
padding: 4lets it bleed 4 px past each edge. - A higher
stackOrderkeeps this panel in front of any other root it overlaps.
5. Radio buttons with a selection group
Section titled “5. Radio buttons with a selection group”#pragma lifecycle(startup)
const NAMES = ['Easy', 'Normal', 'Hard'];let difficulty = 'Normal';
function startup() { for (const name of NAMES) { const entity = findEntity(name); entity.getComponent(UICheckboxComponent).setProps({ text: name, radio: true }); entity.addComponent(new UISelectionGroupComponent({ group: 'difficulty' })); } findEntity(difficulty).getComponent(UICheckboxComponent).setChecked(true);
on('settings/difficulty', (event) => { if (event.eventType !== EventType.UICheckbox.Change || !event.data.checked) return; difficulty = findEntity(event.entityId).name; log('difficulty is now', difficulty); });}Three UI Checkboxes drawn as radio buttons and made exclusive by a UI Selection Group, which a Behavior script adds; the log reports the chosen difficulty.
Pick Easy, Normal or Hard: the others turn off and the log names your choice. Drag outside the panel to orbit the camera, scroll to zoom.
How it works:
radio: truedraws each checkbox as a ring and dot. The UI Selection Group with the samegroupname makes them exclusive: checking one unchecks the others.setChecked(true)from the script applies the group too, so the starting choice is clean.- Every checkbox sends
UICheckbox::changeon the same signal. Turning one on also turns another off, so the script only acts onchecked: trueand reads which entity sent it fromevent.entityId.
Common mistakes
Section titled “Common mistakes”- Moving a nested element with its Transform. A nested element is placed by its parent’s layout; its position, rotation and scale do nothing. Change the parent’s
flexDirection,alignItems,gaporpadding, or the element’s ownmarginand size. - A UI under a plain group is a separate root. Only the direct parent counts. A UI Label under a Group under a panel is not laid out by the panel; it becomes a root of its own.
- Expecting a fill from a UI Layout. A layout draws nothing. Use a UI Panel, or add a UI Panel component, for a visible surface.
- Screen-space HUDs in XR. They are head-locked in a headset. Use a world-space panel there.
- Panels see-through from behind. Add a UI Backdrop to world panels players can walk around.
- Padding on containers that draw no box. UI Panel, UI List and UI Screen Space are spaced through their entity’s UI Layout props, not their own.
- Many separate roots. Each root is its own tree with its own layout and drawing. Many controls under one panel cost less than as many free-standing roots.