Ui
Draws the widgets of a plugin’s panel or dialog, the same widgets Modlumi’s own panels use. Value widgets take the current value and return it, or the user’s change of it:
state.width = ui.length("Width", state.width, { min: 0.1 });if (ui.button("Build", { primary: true })) build(state);Consecutive fields line up in a form, labels on the left. A widget is identified by its
label within the sections, tabs and columns around it, so keep labels stable or pass an
id. Repeated labels are told apart by their order.
Methods
Section titled “Methods”angle()
Section titled “angle()”angle(
label,radians,options?):number
An angle in radians, shown and typed in degrees.
Parameters
Section titled “Parameters”string
radians
Section titled “radians”number
options?
Section titled “options?”Returns
Section titled “Returns”number
button()
Section titled “button()”button(
label,options?):boolean
Returns true in the draw that reports the click. That draw may edit the model, so
call Model.operation right there.
Parameters
Section titled “Parameters”string
options?
Section titled “options?”WidgetOptions & object
Returns
Section titled “Returns”boolean
canvas()
Section titled “canvas()”canvas(
label,height,draw,options?):CanvasEvent|null
A canvas height pixels high that fills the window’s width. draw adds its shapes and
receives what the user did with the mouse on it, or null, so it can show the effect
right away; canvas returns the same event. The draw that reports an event may edit the
model, like a clicked button’s.
ui.canvas("Nodes", 200, (canvas, event) => { if (event?.type === "drag" && event.item === "node") { node.x += event.dx; node.y += event.dy; } canvas.rect(node.x, node.y, 80, 40, { id: "node", fill: { r: 0.2, g: 0.3, b: 0.5, a: 1 } });});Parameters
Section titled “Parameters”string
height
Section titled “height”number
(canvas, event) => void
options?
Section titled “options?”Returns
Section titled “Returns”CanvasEvent | null
checkbox()
Section titled “checkbox()”checkbox(
label,value,options?):boolean
Parameters
Section titled “Parameters”string
boolean
options?
Section titled “options?”Returns
Section titled “Returns”boolean
close()
Section titled “close()”close():
void
Closes this panel or dialog.
Returns
Section titled “Returns”void
color()
Section titled “color()”color(
label,value,options?):Color
Parameters
Section titled “Parameters”string
options?
Section titled “options?”WidgetOptions & object
Returns
Section titled “Returns”columns()
Section titled “columns()”columns(
draws,options?):void
Equal-width columns, one per function.
Parameters
Section titled “Parameters”readonly () => void[]
options?
Section titled “options?”Returns
Section titled “Returns”void
disabled()
Section titled “disabled()”disabled(
when,draw):void
Grays out the widgets draw adds while when is true.
Parameters
Section titled “Parameters”boolean
() => void
Returns
Section titled “Returns”void
dropdown()
Section titled “dropdown()”dropdown<
T>(label,value,choices,options?):T
Chooses one of many options from a list; returns the chosen one.
Type Parameters
Section titled “Type Parameters”T extends string
Parameters
Section titled “Parameters”string
T
choices
Section titled “choices”readonly T[]
options?
Section titled “options?”Returns
Section titled “Returns”T
form()
Section titled “form()”form<
T>(values,schema):T
Draws one field per entry of schema, identified by its key, and returns a copy of
values with the user’s changes.
state = ui.form(state, { width: { type: "length", label: "Width", min: 0.1 }, shape: { type: "dropdown", label: "Shape", choices: ["Straight", "L-shaped"] },});Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
Parameters
Section titled “Parameters”values
Section titled “values”T
schema
Section titled “schema”Readonly<Record<string, FormField>>
Returns
Section titled “Returns”T
heading()
Section titled “heading()”heading(
text,options?):void
Parameters
Section titled “Parameters”unknown
options?
Section titled “options?”Returns
Section titled “Returns”void
image()
Section titled “image()”image(
image,options?):void
Shows an image the plugin loaded, at its own size in pixels, or at a width or height
that keeps its proportions when only one is given.
Parameters
Section titled “Parameters”options?
Section titled “options?”WidgetOptions & object
Returns
Section titled “Returns”void
integer()
Section titled “integer()”integer(
label,value,options?):number
Parameters
Section titled “Parameters”string
number
options?
Section titled “options?”Returns
Section titled “Returns”number
length()
Section titled “length()”length(
label,meters,options?):number
A length in meters, shown in the model’s units. It accepts everything the
measurements box accepts, such as 1.2m, 18cm, 7" or 5' 3 1/2".
Parameters
Section titled “Parameters”string
meters
Section titled “meters”number
options?
Section titled “options?”Returns
Section titled “Returns”number
material()
Section titled “material()”material(
label,value,options?):Material|null
Chooses one of the model’s materials, shown with their colors, or null for the default
material. Assign the result inside Model.operation in the draw that reports it.
Parameters
Section titled “Parameters”string
Material | null
options?
Section titled “options?”Returns
Section titled “Returns”Material | null
number()
Section titled “number()”number(
label,value,options?):number
A decimal number; typed text outside the range is refused.
Parameters
Section titled “Parameters”string
number
options?
Section titled “options?”Returns
Section titled “Returns”number
progress()
Section titled “progress()”progress(
fraction,options?):void
Parameters
Section titled “Parameters”fraction
Section titled “fraction”number
options?
Section titled “options?”WidgetOptions & object
Returns
Section titled “Returns”void
radio()
Section titled “radio()”radio<
T>(label,value,choices,options?):T
Chooses one of a few options shown side by side; returns the chosen one.
Type Parameters
Section titled “Type Parameters”T extends string
Parameters
Section titled “Parameters”string
T
choices
Section titled “choices”readonly T[]
options?
Section titled “options?”Returns
Section titled “Returns”T
readOnly()
Section titled “readOnly()”readOnly(
label,value,options?):void
A labeled value that can’t be edited.
Parameters
Section titled “Parameters”string
unknown
options?
Section titled “options?”Returns
Section titled “Returns”void
row(
draw,options?):void
Places the widgets draw adds side by side, such as a row of buttons.
Parameters
Section titled “Parameters”() => void
options?
Section titled “options?”Returns
Section titled “Returns”void
section()
Section titled “section()”section(
title,draw,options?):void
A heading that folds the widgets draw adds; open by default.
Parameters
Section titled “Parameters”string
() => void
options?
Section titled “options?”WidgetOptions & object
Returns
Section titled “Returns”void
separator()
Section titled “separator()”separator(
title?,options?):void
A horizontal rule, with an optional title set into it.
Parameters
Section titled “Parameters”title?
Section titled “title?”string
options?
Section titled “options?”Returns
Section titled “Returns”void
slider()
Section titled “slider()”slider(
label,value,options?):number
Drag to change; Ctrl+click to type a value.
Parameters
Section titled “Parameters”string
number
options?
Section titled “options?”Returns
Section titled “Returns”number
spacing()
Section titled “spacing()”spacing():
void
Vertical space between groups of widgets.
Returns
Section titled “Returns”void
table()
Section titled “table()”Call Signature
Section titled “Call Signature”table(
label,columns,rows,selection,options?):string|null
A table whose columns sort when the user clicks their header; cells that start with a
number, such as "1.2 m", sort by it. Pass the selected row’s id, or null, and get the
user’s new choice back. Pass an array of ids instead to let Ctrl+click and Shift+click
select several rows; the result is then an array too.
Parameters
Section titled “Parameters”string
columns
Section titled “columns”readonly TableColumn[]
readonly TableRow[]
selection
Section titled “selection”string | null
options?
Section titled “options?”Returns
Section titled “Returns”string | null
Call Signature
Section titled “Call Signature”table(
label,columns,rows,selection,options?):string[]
Parameters
Section titled “Parameters”string
columns
Section titled “columns”readonly TableColumn[]
readonly TableRow[]
selection
Section titled “selection”readonly string[]
options?
Section titled “options?”Returns
Section titled “Returns”string[]
tabs()
Section titled “tabs()”tabs(
pages,options?):void
Tabs, from each tab’s title to the function that draws it.
Parameters
Section titled “Parameters”Readonly<Record<string, () => void>>
options?
Section titled “options?”Returns
Section titled “Returns”void
text()
Section titled “text()”text(
text,options?):void
Wrapped text, optionally in a tone.
Parameters
Section titled “Parameters”unknown
options?
Section titled “options?”WidgetOptions & object
Returns
Section titled “Returns”void
textBox()
Section titled “textBox()”textBox(
label,value,options?):string
Multi-line text that wraps; 4 visible lines by default.
Parameters
Section titled “Parameters”string
string
options?
Section titled “options?”WidgetOptions & object
Returns
Section titled “Returns”string
textField()
Section titled “textField()”textField(
label,value,options?):string
Parameters
Section titled “Parameters”string
string
options?
Section titled “options?”WidgetOptions & object
Returns
Section titled “Returns”string
toggle()
Section titled “toggle()”toggle(
label,value,options?):boolean
An on/off switch, for settings that apply right away.
Parameters
Section titled “Parameters”string
boolean
options?
Section titled “options?”Returns
Section titled “Returns”boolean
tree()
Section titled “tree()”tree(
label,items,selected,options?):string|null
A tree of selectable items, such as an outliner. Returns the selected item’s id, or the
user’s new choice; null when nothing is selected. Arrows fold and unfold items.
Parameters
Section titled “Parameters”string
readonly TreeItem[]
selected
Section titled “selected”string | null
options?
Section titled “options?”Returns
Section titled “Returns”string | null