Caffeine

UI

Reference UI Last updated: Lua 6 · Dryad 0

Create canvases, labels and buttons, update them and hit-test screen positions.

All namespaces

Namespace: caffeine.ui

createCanvas#

Lua: caffeine.ui.createCanvas

text
createCanvas([w, h]) -> integer

Creates a UI canvas entity.

ParametersTypeDescription
wnumberWidth (default 1280).
hnumberHeight (default 720).

Returns: integer. Canvas entity id, or 0 without a UI system or world.

Example

lua
local canvas = caffeine.ui.createCanvas(1280, 720)

createLabel#

Lua: caffeine.ui.createLabel

text
createLabel(parent, text, pos) -> integer

Creates a text label under a parent.

ParametersTypeDescription
parentintegerParent canvas or widget id.
textstringLabel text.
postable{x, y} position.

Returns: integer. Label entity id, or 0.

Example

lua
local l = caffeine.ui.createLabel(canvas, 'Score: 0', { x = 10, y = 10 })

createButton#

Lua: caffeine.ui.createButton

text
createButton(parent, text, pos[, w, h]) -> integer

Creates a button under a parent.

ParametersTypeDescription
parentintegerParent canvas or widget id.
textstringButton text.
postable{x, y} position.
wnumberWidth (default 120).
hnumberHeight (default 40).

Returns: integer. Button entity id, or 0.

Example

lua
local b = caffeine.ui.createButton(canvas, 'Play', { x = 20, y = 60 })

hitTest#

Lua: caffeine.ui.hitTest

text
hitTest(sx, sy) -> integer

Finds the UI element at a screen position.

ParametersTypeDescription
sxnumberScreen x.
synumberScreen y.

Returns: integer. UI entity id under the point, or 0.

Example

lua
local hit = caffeine.ui.hitTest(100, 80)

setLabel#

Lua: caffeine.ui.setLabel

text
setLabel(entity, text)

Changes a label's text. Does nothing when the entity has no label.

ParametersTypeDescription
entityintegerEntity id.
textstringNew text (up to 255 characters).

Returns: none

Example

lua
caffeine.ui.setLabel(l, 'Score: 10')

setProgress#

Lua: caffeine.ui.setProgress

text
setProgress(entity, normalized)

Sets a progress bar between its min and max. Does nothing when the entity has no progress bar.

ParametersTypeDescription
entityintegerEntity id.
normalizednumber0..1; clamped.

Returns: none

Example

lua
caffeine.ui.setProgress(bar, 0.5)