Immediate-Mode In-Game UI (`engine.UI`)
An immediate-mode graphical user interface system. Rather than managing complex retained widget trees, calling UI functions in your draw loop renders controls and returns user interaction state in a single step.
Functions Reference
| Function | Signature | Description |
|---|---|---|
engine.UI.button(x, y, w, h, text) |
(num, num, num, num, str) → bool |
Renders a button control. Returns true in the exact frame the user clicks it. |
engine.UI.label(x, y, text) |
(num, num, str) → void |
Renders a text label at the specified position. |
engine.UI.slider(x, y, w, min, max, val) |
(num, num, num, num, num, num) → num |
Renders an interactive draggable slider and returns the updated value. |
engine.UI.panel(x, y, w, h) |
(num, num, num, num) → void |
Renders a dark translucent backdrop container for menus and dialog overlays. |
In-Game Pause Menu Example
pause_menu.lua
import engine
isPaused = false
masterVolume = 0.8
function drawGameUI() {
-- Pause button in top-right corner:
if (engine.UI.button(1140, 20, 120, 36, "Pause")) {
isPaused = not isPaused
}
if (isPaused) {
-- Render modal backdrop:
engine.UI.panel(440, 200, 400, 320)
engine.UI.label(540, 230, "=== PAUSED ===")
-- Audio volume slider:
engine.UI.label(480, 290, "Audio Volume:")
masterVolume = engine.UI.slider(480, 320, 320, 0.0, 1.0, masterVolume)
-- Resume game:
if (engine.UI.button(500, 390, 280, 40, "Resume")) {
isPaused = false
}
-- Exit game:
if (engine.UI.button(500, 445, 280, 40, "Quit to Desktop")) {
engine.stop()
}
}
}