Skip to content
AEOWUN
Docs Menu

UI

Create controls or find controls made in the editor.

Create a control

Use ui.new(type) to create a control for the current Play session.

const button = ui.new("Button")
button.text = "Start"
button.position = [20, 20]
button.size = [160, 40]
button.on_click = fn() {
    debug.log("Start clicked")
}

Available control types are Panel, Text, Button, Image, and Video. Positions and sizes use playable-viewport pixels.

Display images and video

An Image or Video control can display a media file from your project. Assign its source and choose how the content fits.

const picture = ui.new("Image")
picture.position = [20, 20]
picture.size = [320, 180]
picture.source = "Media/title.png"
picture.fit = "Contain"

Replace the example source with the path of an image you've imported into the project. Fit modes are Contain, Cover, and Stretch.

A Video control additionally supports playing, looped, and playback_rate:

const movie = ui.new("Video")
movie.position = [20, 20]
movie.size = [640, 360]
movie.source = "Media/intro.mp4"
movie.fit = "Contain"
movie.looped = false
movie.playback_rate = 1.0
movie.playing = true

Set playing = false to pause playback. See UI control properties for the individual property contracts.

Find authored controls

Set a control's Script key in the editor. Use that key in your script.

const health = ui.find("health_text")
if health != nil {
    health.text = "75 / 100"
}

Keys are case-sensitive. Display names are not script keys. ui.get() reports an error if the key is missing; ui.find() returns nil.

The optional document key must match the document loaded for Play.

Anchors

Set anchor to a named point such as "TopRight". Position becomes an offset from that point.

"Stretch" uses position as left/top margins and size as right/bottom margins.

Parent controls

Set parent to another Ui handle, or nil to use the root. A hidden or disabled parent also affects its children.

Text layout

Text and Button controls support font size, alignment, wrapping, padding, and line spacing. See the UI reference for allowed values.

Play changes

Runtime controls and property changes do not change the saved UI document. Starting a new Play session restores authored values.