Skip to content

UI Divider

Updated

A thin separator line.

Type
ent-ui-divider
Script class
UIDividerEntity
Family
UI

A UI Divider is a thin line that separates parts of a UI: a header from its content, one group of settings from the next, the buttons of a toolbar. Its UI Divider component (comp-ui-divider) draws a line that stretches across its parent unless you give it a fixed length. It is purely visual and takes no pointer.

A divider sits nested in a panel or layout, between the elements it separates. Pick its orientation from its parent’s flow: in a column, a 'horizontal' line separates stacked rows; in a row, a 'vertical' line separates the items side by side.

Use a divider when a visible line helps the eye group things. When you only need space, use the layout’s gap, or a UI Spacer to push elements apart.

The props that matter most:

  • orientation: 'horizontal' (the default) or 'vertical'.
  • color: the line colour (the theme’s divider colour by default).
  • thickness: the line thickness in layout pixels (px), 1 by default.
  • length: a fixed length in px instead of stretching.
  • margin: space around the line, in px.
  1. Add a UI Divider under a UI Panel or UI Layout, between the two elements it separates. See Scenes and hierarchy.
  2. Set orientation to match the parent: 'horizontal' in a column, 'vertical' in a row.
  3. Adjust color, thickness and margin if needed.

Goal: build a card with two sections separated by a divider, all from code.

SettingsCard.jx
#pragma lifecycle(startup)
// Scene: a UI Panel named 'Settings'. The script fills it.
function startup() {
const card = findEntity('Settings');
card.getComponent(UILayoutComponent).setProps({ width: 320, padding: 16, gap: 10 });
const audio = new UILabelEntity();
audio.getComponent(UILabelComponent).setProps({ text: 'Audio', fontWeight: 'bold' });
const music = new UISwitchEntity();
music.getComponent(UISwitchComponent).setProps({ text: 'Music' });
const line = new UIDividerEntity();
line.getComponent(UIDividerComponent).setProps({ color: '#334155', margin: [4, 0] });
const video = new UILabelEntity();
video.getComponent(UILabelComponent).setProps({ text: 'Video', fontWeight: 'bold' });
const shadows = new UISwitchEntity();
shadows.getComponent(UISwitchComponent).setProps({ text: 'Shadows' });
card.add(audio, music, line, video, shadows);
}

How it works:

  • The panel is a column, so the default 'horizontal' divider spans its width between the two sections.
  • margin: [4, 0] adds 4 px above and below the line, on top of the panel’s gap.

Goal: separate two groups of toolbar buttons with a short vertical line.

ToolbarDivider.jx
#pragma lifecycle(startup)
// Scene: a UI Layout named 'Toolbar' (flexDirection 'row', alignItems 'center')
// holding buttons, with a UI Divider named 'Toolbar Split' between two groups.
function startup() {
const split = findEntity('Toolbar Split').getComponent(UIDividerComponent);
split.setProps({ orientation: 'vertical', length: 24, thickness: 2, color: '#475569', margin: [0, 6] });
}

How it works:

  • In a row, a 'vertical' divider stands between items.
  • length: 24 keeps it shorter than the buttons; without it, the line stretches to the row’s height.
  • margin: [0, 6] puts 6 px of space on its left and right.

What a new UI Divider is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.

Component Type Role Per entity What it does
Layer comp-layer Required One Puts the entity on a render/raycast layer so cameras and rays can include or skip it.
Lock comp-lock Required One Editor-only flag that stops the entity from being selected or moved.
Enable comp-enable Required One Turns the entity and its children on or off: hides them and stops their behavior.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
UI Divider comp-ui-divider Required One A thin separator line.

You can also add 1 optional components, such as Signal Emitter.

The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).

Prop Default Range
orientation "horizontal"

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

It reports the events every entity has: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My UI Divider.

UIDividerEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My UI Divider');
if (!(entity instanceof UIDividerEntity)) return;
// Its UI Divider component holds the settings listed under Props.
const component = entity.getComponent(UIDividerComponent);
log(component.props);
}