Skip to content

Content

Updated

Content elements show things inside a UI: text (UI Label), pictures (UI Image, UI Avatar), video (UI Video), a canvas your scripts draw on (UI Drawing) and a small 3D world (UI Render View with its UI Render Scene). They sit in a panel or layout like any control, or stand alone in the world as a root of their own. Most content is passive, but labels, images and avatars can be pressed, videos report playback, and a drawing reports every pointer movement.

  • Read the UI overview for roots, nesting and layout pixels.
  • Content usually sits in a panel; see Panels and layout for spacing rules (padding, margin, borderRadius).
  • Events reach scripts through a Signal Emitter, as for Controls.
  • For world-space video, streams and Chroma Key, see Media and text.

The UI Label component (comp-ui-label) draws text in a box you style with CSS-like props. Entity: UI Label (ent-ui-label), which also takes a Billboard, a Link, a Signal Emitter and an Enable on Signal.

Prop Type Default Description
text string 'Text' The text to draw.
fontSize number 16 from the theme Glyph size in px.
font string the theme’s Font family, by name. See Placement and fonts.
fontWeight 'light', 'normal', 'medium', 'semi-bold', 'bold' 'normal' Weight, when the family has it.
color string the theme’s foreground Text colour.
opacity number opaque Text alpha, 0 to 1.
textAlign 'left', 'center', 'right' 'left' Alignment inside a box wider than the text.
lineHeight number 1.2 Line spacing as a multiple of the font size.
letterSpacing number 0 Extra space between glyphs, in px.
width number or 'N%' fits the text Fixed width in px or a percentage of the parent.
maxWidth number or 'N%' none The text wraps past this width. Without it, the label is one line.
textOverflow 'ellipsis' wraps With width set, show one line ending in an ellipsis when the text is too wide.
wordBreak 'break-word', 'break-all', 'keep-all' normal How words break inside a constrained width.
overflowWrap boolean none Break a word too long for the width.
minHeight, maxHeight number none Height limits in px.
overflow 'hidden' or 'scroll' none What text past maxHeight does.
padding, margin number or number[] 1, none In px.
backgroundColor string none Box fill.
borderRadius number or number[] none Corner radius in px.
borderColor, borderWidth string, number or number[] none, 2 Outline, drawn only when borderColor is set.
  • Pressable. With a Signal Emitter the label sends UILabel::press {} (EventType.UILabel.Press) when pressed; with a Link it opens the link instead. Without either it takes no pointer, unless overflow: 'scroll' makes it scrollable.
  • Shared text. A label’s props can be a network trait (NetworkTraitType.UILabel), so a scoreboard reads the same for everyone in a room. See Multiplayer.
  • A label floating over an object is covered in Placement and fonts.

The UI Image component (comp-ui-image) shows a picture in its box. Entity: UI Image (ent-ui-image).

Prop Type Default Description
src string none The picture: a URL or one of the project’s image assets.
width, height number automatic Size in px.
keepAspectRatio boolean true Keep the picture’s proportions when only one size is set.
objectFit 'cover' or 'fill' 'cover' cover crops to fill the box; fill stretches.
padding, margin number or number[] none In px.
borderRadius number or number[] none Corner radius in px.
borderColor, borderWidth string, number or number[] none Outline, drawn only when borderWidth is set.

With both sizes automatic, the image uses its natural size and scales down to fit the space it has. With one size set, keepAspectRatio derives the other.

Event EventType Data Sent when
UIImage::ready EventType.UIImage.Ready { width, height } The image shows, and again after each rebuild.
UIImage::error EventType.UIImage.Error { message } It cannot load.
UIImage::press EventType.UIImage.Press {} It is pressed, with a Signal Emitter and no Link.

The UI Avatar component (comp-ui-avatar) is a round profile picture with an optional status dot at its lower right. While the picture is missing or loading, it shows the initials you give it, or a user icon. Entity: UI Avatar (ent-ui-avatar).

Prop Type Default Description
src string none The picture, cropped to a circle.
initials string none Fallback text while there is no picture.
initialsBackgroundColor, initialsColor string from the theme Fill and text colour of the initials.
initialsFontSize number the theme’s font size Initials size in px.
size number 40 Diameter in px.
borderColor, borderWidth string, number or number[] none, 1 Ring, drawn only when borderColor is set.
statusColor string none Status dot colour, such as green for online. Absent: no dot.
padding, margin number or number[] none In px.

Event: UIAvatar::press {} (EventType.UIAvatar.Press), with a Signal Emitter and no Link.

The UI Video component (comp-ui-video) plays a video on a surface inside a panel. It plays the same sources as the world-space Video, including live streams through a Media Stream component, and a Chroma Key can make its green screen transparent. Entity: UI Video (ent-ui-video).

Prop Type Default Description
src string none The video: a URL or one of the project’s video assets.
width, height number from the parent Surface size in px.
objectFit 'cover' or 'fill' 'cover' cover crops to fill; fill stretches.
keepAspectRatio boolean true Keep the video’s proportions.
autoplay boolean true Play once the surface is live, and again when the scene is entered.
muted boolean true Start muted, since browsers block autoplay with sound.
volume number 1 Gain, 0 to 1.
repeat 'once' or 'repeat' 'repeat' Play to the end, or start again.
playbackRate number 1 Speed, 0.5 to 4.
restart boolean true Start from the beginning when the scene is entered again, instead of resuming.
crossOrigin string 'anonymous' Cross-origin mode. A video from another site must allow it to be drawn.
padding, margin, borderRadius, borderColor, borderWidth none The box, in px. borderRadius clips the video.
Method What it does
play() Start or resume.
pause() Pause, keeping the position.
stop() Stop and go back to the start.
setVolume(volume), getVolume() Set or read the gain, 0 to 1.
isPlaying() Whether it is playing.
Event EventType Data Sent when
UIVideo::ready EventType.UIVideo.Ready { duration } The first frame loaded. duration in seconds, Infinity for a live stream.
UIVideo::error EventType.UIVideo.Error { message } The video or stream failed.
UIVideo::play, ::pause, ::stop, ::end EventType.UIVideo.Play, .Pause, .Stop, .End {} Playback started, paused, was stopped, or reached its end without repeating.

The video never plays while you edit. In play, the first ready and autoplay play events of a UI Image or UI Video arrive after Behaviors start: register your listeners in startup, before any await.

The UI Drawing component (comp-ui-drawing) shows a 2D canvas in a panel. Scripts draw on it with the standard Canvas 2D API: paint tools, minimaps, charts, pictures made at runtime. Entity: UI Drawing (ent-ui-drawing).

Prop Type Default Description
width, height number 256 Surface size in layout px.
resolution number 1 Canvas pixels per layout px, 1 to 4. 2 keeps a drawing sharp up close and in VR, for four times the memory.
background string '#ffffff' Colour clear() fills with; 'transparent' clears to nothing.
cursor 'crosshair', 'pointer', 'default' 'crosshair' Cursor over the canvas. pointer suits buttons drawn on it.
borderRadius number or number[] 0 Corner radius in px, clipping the canvas. Half the width makes a round minimap.
padding, margin number or number[] none In px.
Member What it does
draw(paint) Runs paint(ctx) with the canvas’s 2D context, then shows the result on the next frame, however many draws come before it.
clear() Fills the canvas with background, or clears it when that is 'transparent'.
canvas The canvas element, to copy it into another canvas with drawImage.
  • Coordinates. Each draw starts the context in layout px, so you draw at the same coordinates whatever the resolution.
  • Lifetime. The drawing survives rebuilds of its panel. Changing its size or resolution starts a new, blank canvas, as an HTML canvas does.
  • Cost. An idle canvas costs nothing per frame. When you redraw every frame, pass one named function to draw rather than a new arrow function each time.
  • It has no border; put it in a UI Panel to frame it.

With a Signal Emitter on its entity, the canvas takes the pointer and sends these events, in VR too. x and y are layout px from the canvas’s top-left corner. Without a Signal Emitter the canvas ignores the pointer.

Event EventType Sent when
UIDrawing::pointer-down EventType.UIDrawing.PointerDown A pointer presses the canvas.
UIDrawing::pointer-move EventType.UIDrawing.PointerMove It moves while pressed. The press is captured, so x and y can leave the canvas.
UIDrawing::pointer-up EventType.UIDrawing.PointerUp It lets go.
UIDrawing::pointer-hover EventType.UIDrawing.PointerHover A pointer moves over it without pressing. Touch has no hover.
UIDrawing::pointer-leave EventType.UIDrawing.PointerLeave The pointer leaves, at the last point it was over.

Each sends { x, y, pointerId }. pointerId tells two pointers apart, such as two fingers or two controllers.

A UI Render View shows a small 3D world inside a panel: a model turning in a HUD, a character preview, an item in an inventory. The view is the UI Render View entity (ent-ui-render-view); the world it shows is the UI Render Scene entity (ent-ui-render-scene), its child.

UI Panel
└── UI Render View the picture: size and quality
└── UI Render Scene the world: camera, lights, background
├── Preview Model (a glTF model)
└── Behavior turns the model

The UI Render View component (comp-ui-render-view) is sized like an image:

Prop Type Default Description
width, height number 256 Size in px.
quality 'low', 'medium', 'high' 'medium' Picture resolution on its long side: 256, 512 or 1024 pixels.
borderRadius number or number[] 0 Corner radius in px.
padding, margin number or number[] none In px.

The UI Render Scene component (comp-ui-render-scene) gives the small world its own camera and lights. The camera sits on the scene’s +Z axis at distance, looking at its origin; a key light, a fill light and an ambient light light it.

Prop Type Default Description
fov number 30 Vertical field of view of the camera, in degrees.
distance number 3 Distance of the camera from the origin, in metres.
background string 'transparent' 'transparent', or the colour behind the scene.
  • What it holds. Primitives, models (glTF, FBX, OBJ, USDZ, Collada, kit pieces) and Behaviors, nested at any depth. Adding any other kind of entity to it throws.
  • Its own world. Everything in it is drawn only in its view: the main camera, shadows and reflections never see it, and the world’s lights never reach it. You still select and edit its entities in the editor.
  • Turning a model. Turn the model, not the render scene: the camera follows the scene.
  • Cost. While on screen, the view draws its small world once per frame, one extra draw per mesh in it. A hidden or off-screen view draws nothing.
Gallery.jx
#pragma lifecycle(startup)
// Scene: a UI Panel with a UI Image named 'Photo' (Signal Emitter: 'gallery:photo'),
// a UI Label named 'Caption', and two UI Buttons named 'Previous' and 'Next'
// (Signal Emitters: 'gallery:prev' and 'gallery:next').
const PHOTOS = [
{ src: '/example-assets/lemon-decal.png', caption: 'Lemon slice' },
{ src: '/example-assets/bang.png', caption: 'Comic bang' },
{ src: '/example-assets/alpha.png', caption: 'Star burst' },
];
let index = 0;
let photo;
let caption;
function show() {
photo.setProps({ src: PHOTOS[index].src });
caption.setProps({ text: 'Loading…' });
}
function startup() {
photo = findEntity('Photo').getComponent(UIImageComponent);
caption = findEntity('Caption').getComponent(UILabelComponent);
photo.setProps({ width: 320, height: 200, objectFit: 'cover', borderRadius: 12 });
on('gallery:photo', (event) => {
if (event.eventType === EventType.UIImage.Ready) caption.setProps({ text: PHOTOS[index].caption });
if (event.eventType === EventType.UIImage.Error) caption.setProps({ text: 'Could not load this photo.' });
});
on('gallery:prev', (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
index = (index + PHOTOS.length - 1) % PHOTOS.length;
show();
});
on('gallery:next', (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
index = (index + 1) % PHOTOS.length;
show();
});
show();
}

How it works:

  • Setting src loads a new picture; the fixed width and height with objectFit: 'cover' keep the box the same size whatever the photo’s proportions.
  • The caption says “Loading…” until UIImage::ready arrives, and reports a failure on UIImage::error.
  • The listeners are registered in startup before anything else happens, so the first ready event is not missed.
VideoPlayer.jx
#pragma lifecycle(startup)
function startup() {
const video = findEntity('Screen').getComponent(UIVideoComponent);
const button = findEntity('PlayPause').getComponent(UIToggleButtonComponent);
const volume = findEntity('TV Volume').getComponent(UISliderComponent);
on('tv:play', (event) => {
if (event.eventType !== EventType.UIToggleButton.Change) return;
if (event.data.checked) {
video.setProps({ muted: false });
video.play();
} else {
video.pause();
}
});
on('tv:volume', (event) => {
if (event.eventType === EventType.UISlider.Change) video.setVolume(event.data.value / 100);
});
on('tv:video', (event) => {
if (event.eventType === EventType.UIVideo.Ready) log('video length', event.data.duration, 's');
if (event.eventType === EventType.UIVideo.Play) button.setProps({ text: 'Pause' });
if (event.eventType === EventType.UIVideo.Pause) button.setProps({ text: 'Play' });
if (event.eventType === EventType.UIVideo.End) button.setChecked(false);
});
volume.setValue(video.getVolume() * 100);
}

How it works:

  • The toggle button latches: checked is true while it should play. The script unmutes on the first play, which happens after a user’s press, so the browser allows sound.
  • The button’s label follows the video’s own play and pause events, so it stays right even when something else starts or pauses the video.
  • At the end of a video set to play once, UIVideo::end resets the toggle. setChecked(false) sends a change event that calls pause(), which is harmless at the end.
Paint.jx
#pragma lifecycle(startup)
const strokes = new Map(); // pointerId -> last point
function startup() {
const paint = findEntity('Paint').getComponent(UIDrawingComponent);
paint.setProps({ width: 400, height: 300, resolution: 2 });
on('paint', (event) => {
const { x, y, pointerId } = event.data;
if (event.eventType === EventType.UIDrawing.PointerDown) {
strokes.set(pointerId, { x, y });
} else if (event.eventType === EventType.UIDrawing.PointerMove && strokes.has(pointerId)) {
const from = strokes.get(pointerId);
strokes.set(pointerId, { x, y });
paint.draw((ctx) => {
ctx.strokeStyle = '#2563eb';
ctx.lineWidth = 4;
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(from.x, from.y);
ctx.lineTo(x, y);
ctx.stroke();
});
} else if (event.eventType === EventType.UIDrawing.PointerUp) {
strokes.delete(pointerId);
}
});
on('paint/clear', (event) => {
if (event.eventType === EventType.UIButton.Press) paint.clear();
});
}

How it works:

  • The drawing’s Signal Emitter makes it take the pointer. Each press, move and release arrives with the point in layout px.
  • The script keeps the last point of each pointer in a Map keyed by pointerId, so two fingers or two XR controllers draw two separate lines.
  • Each move draws one short segment with the standard Canvas 2D calls. resolution: 2 keeps the lines sharp up close.
  • clear() fills the canvas with its background colour.
Minimap.jx
#pragma lifecycle(startup, update)
// Scene: a HUD panel with a UI Drawing named 'Minimap',
// and an entity named 'Player' that moves around a 40 m square level.
const SIZE = 160; // layout px
const WORLD = 40; // metres shown across the map
let map;
let player;
function startup() {
map = findEntity('Minimap').getComponent(UIDrawingComponent);
map.setProps({ width: SIZE, height: SIZE, borderRadius: SIZE / 2, background: '#0f172a' });
player = findEntity('Player');
}
function drawMap(ctx) {
map.clear();
const x = SIZE / 2 + (player.position.x / WORLD) * SIZE;
const y = SIZE / 2 + (player.position.z / WORLD) * SIZE;
ctx.fillStyle = '#f87171';
ctx.beginPath();
ctx.arc(x, y, 5, 0, M_TAU);
ctx.fill();
}
function update() {
map.draw(drawMap);
}

How it works:

  • borderRadius at half the width clips the canvas into a circle.
  • update runs every frame and redraws with one named function, drawMap, instead of creating a new function each frame.
  • The player’s x and z are mapped from metres to layout px around the map’s centre. M_TAU is a full turn in radians.
Turntable.jx
#pragma lifecycle(startup, update)
const SPEED = 0.6; // radians a second
let model;
let scene3d;
function startup() {
model = findEntity('Preview Model');
scene3d = model.parent.getComponent(UIRenderSceneComponent);
scene3d.setProps({ distance: 2.5, fov: 35, background: 'transparent' });
}
function update(dt) {
model.rotation.y += dt * SPEED;
}

How it works:

  • The model lives inside the UI Render Scene, so it is drawn only in the panel’s view, lit by the render scene’s own lights.
  • The script turns the model, not the scene: the render scene’s camera is fixed to the scene, looking at its origin from distance metres away.
  • model.parent is the UI Render Scene entity here, because the model is its direct child.
Score.jx
#pragma lifecycle(startup)
// Scene: a UI Label named 'Score'. Other scripts emit 'game:point' with
// the number of points scored, for example emit('game:point', 10).
let score = 0;
function startup() {
const label = findEntity('Score').getComponent(UILabelComponent);
label.setProps({ fontSize: 32, fontWeight: 'bold', padding: [6, 14], backgroundColor: '#1e293b', borderRadius: 10 });
on('game:point', (points) => {
score += points;
label.setProps({ text: `Score: ${score}`, color: score >= 100 ? '#facc15' : '#ffffff' });
});
}

How it works:

  • setProps styles the label’s box: padding of 6 px above and below and 14 px on the sides, a fill and rounded corners.
  • A signal raised with emit(signal, data) passes data straight to the on callback, so points is the number another script sent.
  • The colour switches to gold once the score reaches 100; the label resizes around its text by itself.
  • A label that never wraps. Without maxWidth (or width), a label is one line however long its text. Set a width to make it wrap.
  • Images and videos that never report. Without a Signal Emitter on the element, ready, error and press are not sent.
  • Missing the first ready. Register listeners in startup before any await, or the first event can arrive before you listen.
  • Video that stays silent. muted is true by default because browsers block sound before the user interacts. Unmute after a press.
  • Drawing on a canvas without a Signal Emitter. The canvas ignores the pointer until it has one.
  • A new closure every frame. map.draw(() => …) in update creates a function per frame. Pass a named function.
  • Putting lights or cameras in a UI Render Scene. It accepts only primitives, models and Behaviors, and has its own camera and lights.