Molten

.ui files

A .ui file declares a widget tree in JSX-style markup. It may start with imports of Cast event handlers, then exactly one export default ui(...) with a single root widget.

import { resume, menu, hover, masterVolume } from "./actions";

export default ui(
    <panel class="stage overlay">
        <text class="title">Shift paused</text>
        <slider id="volumeMaster" min={0} max={1} step={0.05} value={volume.master} onChange={masterVolume} />
        <button id="resume" class="primary" onClick={resume} onHover={hover}>Resume</button>
    </panel>
);

Widgets and their attributes

Every widget accepts id (a string, unique in the file), class (space-separated class names) and disabled (a bool; a bare disabled means true).

Widget Children Extra attributes
panel widgets
list widgets (laid out as authored)
scrollView widgets (clipped, scrolls vertically)
text text and {bindings}
button text and {bindings} onClick, onHover
image none src (a texture path under assets/)
progress none value, max, min, step (numbers)
slider none value, min, max, step (numbers), onChange
toggle none checked (bool), onChange
textInput none value (string), placeholder, onChange

Attribute values

Form Meaning
"text" A string literal
{12}, {true}, {"x"} A literal
{player.health.current} A binding: the value Cast published under that dotted name
{handlerName} For onClick, onHover, onChange: a function imported at the top of the file

Text content can mix literal text and several bindings: <text>{grid.served} of {grid.houses} homes</text>. {} on its own is an empty JSX comment.

Handlers

Attribute Widget Cast export signature
onClick button (): void
onHover button (): void. Fires when the pointer enters an enabled button
onChange slider (value: float): void or (): void
onChange toggle (value: bool): void or (): void
onChange textInput (value: string): void or (): void

Imports use relative paths without .cast: import { play } from "./actions";.

Errors

Message Cause
unknown widget 'div' A tag that isn't in the table
invalid attribute 'bogus' on <text> An attribute the widget doesn't take, or a value of the wrong kind
widget id must be nonempty and unique: 'x'
duplicate attribute 'class'
text expressions belong inside text or button widgets {binding} in a panel
this widget cannot contain child widgets Children inside text, button, slider, ...
event handler must name an imported Cast function onClick={nope} without an import
unknown or incompatible Cast handler 'play' The export doesn't exist or has the wrong signature
expected closing tag </panel>
widget nesting exceeds 128 levels

Reload

Saving rebuilds the tree and keeps widget state (focus, scroll, typed text, caret) for widgets whose id and type match. A broken file keeps the previous tree.

View this page's source on GitHub