Coldwave Read the docs

ui#

Part of the scripting reference, written by the engine so it matches your frost. Start with your first game if you are new.

Use when building menus, buttons, sliders or HUD layout, changing focus, displaying text or loading fonts.

In a scriptDoes
ui.measure("text", "style"?)Width and height in design units at Text.size 1, using the declared font style; omit style for the built-in font. Unknown styles are errors
ComponentFieldTypeDefaultMeaning
Texttexttext""What to write. \n starts a new line
Textsizewhole number1World units to one font pixel: a glyph is 5 by 8 font pixels, the next starts 6 further on and the next line 10 down, so a line of n letters is (6n - 1) * size wide. Less than 1 is 1
Textcolorwhole number0xffffffThe colour as 0xRRGGBB
Textalignnumber0.5Where Transform.x is along each line: 0 its left end, 0.5 its middle, 1 its right end
Textlayerwhole number0Drawing order, shared with Rect and Sprite
Shadowcolorwhole number0x000000The colour of the copy of the entity's text drawn under it
Shadowxnumber2How far right of the text the copy is drawn, in the text's units
Shadowynumber-2How far up; below the text is negative
Fontstyletext""The text style the entity's Text is written in: a name under [fonts] in the project file. "" is the built-in font
Wrapwnumber0The entity's Text starts a new line before a word that would pass this width, in units. 0: it does not
Wrapellipsistrue or falsefalseTruncate each explicit line to w with ... instead of wrapping; dots shorten when the width cannot fit them

Text#

One font is built in: 5 by 8 pixels a glyph, the printable ASCII characters, drawn for this engine (760 bytes). A character it does not have is drawn as ?. It has one width for every glyph, 6 font pixels from one to the next, and lines are 10 apart. size is a whole number, and each line starts on a whole unit, so in a frame with one unit to a pixel every font pixel is a sharp square. This is enough for a score and a title.

A game's own fonts. The project file names text styles under [fonts]: each is a size in pixels and one or more TrueType or OpenType files (.ttf, .otf). A Text on an entity that also has Font = { style = "body" } is written in that style:

TOML
# game.toml
[fonts]
body = { files = ["fonts/Inter.ttf", "fonts/NotoSansSC.otf"], size = 24 }

# a scene
[greeting]
Transform = { x = 160, y = 90 }
Text = { text = "Hello, 你好" }
Font = { style = "body" }
  • Each character is drawn from the first file of the style that has it, so a second file adds an alphabet the first lacks. One that none has is the first file's sign for a missing glyph (often a box).

  • The style's size is the height of the font's em in pixels, 4 to 200, as in a drawing program. Text.size multiplies it and stays a whole number: 1 is the style as it is, sharp; 2 is the same glyphs drawn twice as large and blended. For large sharp letters make a second style at the larger size.

  • Letters have their own widths and pairs like AV close up (kerning). Lines are the font's own distance apart. align, color, layer, Shadow, Opacity and Scale work as for the built-in font, and each glyph stands on whole pixels.

  • Not here: joining letters (Arabic, Devanagari), right-to-left lines, emoji in colour, and marks that combine with the letter before them.

  • A glyph is drawn once, the first time a text shows it, and kept: a page of 512 by 512 pixels holds a few hundred letters at 24 pixels, and more pages are made as needed (1 MB each). A game that shows thousands of different large characters uses memory for each.

  • Fonts are the game's own files and ship with it. Never let a player or a server supply one: the reader (stb_truetype) trusts what a font file says about itself.

  • A game with no [fonts] is exported without any of this.

Interface#

Menus and controls are entities in the scene file. An entity with a Node is a box; boxes sit in boxes; a Button, a Slider, a Choice or a Toggle on a node is used by a person, and a Bar shows a number. The engine lays the boxes out and drives them from input actions each step, before the scripts, which read what was pressed in that step.

Set [ui] fit = 720 to author the interface at a design height of 720. Layout, Anchor offsets, Node sizes, Stack/Grid spacing, and ui.tree use design units. Everything with Screen (including text, shapes and Slice borders without a Node) is drawn at frame height / 720 in both 2D and 3D. The pointer uses the same layout. Omit fit to keep pixel units. frame.size() still reports frame pixels.

local width, height = ui.measure("Hello", "body") measures text in a declared font style, in design units at Text.size 1. Omit the style for the built-in pixel font. Multiply both results by Text.size for a larger text. Unknown styles are errors. Wrap = { w = 240 } wraps text; Wrap = { w = 240, ellipsis = true } truncates each explicit line with ..., shortened further if even the dots cannot fit.

ComponentFieldTypeDefaultMeaning
Nodeparenttext""The node this one is in, by name. Empty: the frame
Nodewnumber0Its box's width. 0: that of its Text, or of what its Stack or Grid holds
Nodehnumber0Its box's height, the same way
Nodeorderwhole number0Its turn in its stack or grid, lower first; equal ones go by name
Nodeshowntrue or falsetrueFalse hides it and every node in it
Nodefocustrue or falsetrueFalse: keys and a gamepad cannot reach it, only the pointer
Nodemin_wnumber0The least width of its box
Nodemin_hnumber0The least height
Nodebacktext""The event sent, about this node, on back with the focus on or in it
Nodemodaltrue or falsefalseTrue: while shown, only nodes in it can be used
Nodelockedtrue or falsefalseTrue: it takes the focus and refuses to be used
Nodeuptext""The node, by name, the focus goes to going up. Empty: the rules say
Nodedowntext""Going down
Nodelefttext""Going left
Noderighttext""Going right
Nodepointertrue or falsetrueFalse: the pointer goes through it, and a press on it is the game's
Anchorxnumber0.5Which point of the node sits on the same point of what it is in: 0 left edges, 0.5 middles, 1 right edges
Anchorynumber0.5The same from the bottom: 0 bottom edges, 1 top edges
Anchordxnumber0Units right of there
Anchordynumber0Units up from there
Anchorstretch_xtrue or falsefalseTrue: from the left edge of what it is in to the right, less dx at each end
Anchorstretch_ytrue or falsefalseThe same from bottom to top, less dy at each end
Stackdirtext"down"Which way its nodes follow one another: "down", "up", "right" or "left"
Stackgapnumber0The space between one and the next
Stackpadnumber0The space kept clear inside its edges
Stackalignnumber0.5Where each sits across the stack: 0 left or bottom, 0.5 middle, 1 right or top
Gridcolumnswhole number2Cells in a row. They share the width equally
Gridrownumber0A row's height
Gridgapnumber0The space between cells, both ways
Gridpadnumber0The space kept clear inside its edges
Buttoneventtext""The event sent, about the button, when it is used
Buttonofftrue or falsefalseTrue: it cannot be used or take the focus
Slidervaluenumber0Where it stands, min to max
Sliderminnumber0Its least value
Slidermaxnumber1Its greatest
Sliderstepnumber0.1How far apart its values are. 0: any value, and a key moves it a tenth of the way
Slidereventtext""The event sent, with its new value, when a person moves it
Sliderfilltext""A node, by name, kept as wide as the slider is full
Sliderlabeltext""The entity, by name, whose Text reads the value, with the decimals of step
ComponentFieldTypeDefaultMeaning
Choiceoptionstext""What can be chosen, | between: "Low|Medium|High"
ComponentFieldTypeDefaultMeaning
Choiceindexwhole number0Which is chosen, from 0
Choiceeventtext""The event sent, with the new index, when a person changes it
Choicelabeltext""The entity, by name, whose Text reads the chosen option. Empty: the choice's own Text
Toggleontrue or falsefalseWhether it is on
Toggleeventtext""The event sent, with the new on, when a person switches it
Togglemarktext""A node, by name, shown only while it is on: a tick
Barvaluenumber0What it shows, min to max
Barminnumber0The value at which it is empty
Barmaxnumber1The value at which it is full
Barfilltext""A node, by name, kept as wide as the bar is full
Inheritalphanumber1The interface's to write: what a node takes from those it is in. Multiplies its Opacity; 0 while hidden
Inheritxnumber1Multiplies its Scale.x
Inheritynumber1Multiplies its Scale.y
  • Boxes. A node's box has its middle on the node's Transform and is w by h. Its Rect or Sprite is drawn that size (with a Slice, a panel of any size): write the size once, in Node. A button's words are its own Text. An icon inside a box is a node of its own with the box as its parent. Give interface entities Screen, so the camera does not move them.

  • Sizes nobody writes. A node with a Text and no w or h is as big as its words are drawn (Wrap = { w = 120 } breaks them into lines), so an Anchor places it by its edges. A Stack or Grid with none is as big as what is shown in it.

  • Where a node goes. Where the Stack or Grid of what it is in puts it; else where its Anchor says; else where its Transform is. A node in nothing is anchored to the frame: Anchor = { x = 1, y = 1, dx = -8, dy = -8 } is eight units in from the top right corner.

  • Stretching. Anchor = { stretch_x = true, dx = 8 } makes a node as wide as what it is in, less eight units at each side; with stretch_y too it fills the box: a backdrop is a node in nothing with both, and pointer = false unless it should swallow presses. A node stretched across its stack fills it from pad to pad, those stretched along it share what the rest leave, and one in a grid fills its cell.

  • Stacks and grids. A stack puts its nodes one after another by their order, from the edge its direction leaves. Give each its order (1, 2, 3): a scene file's entities are kept by name, not as written. A grid fills rows from the top, left to right, each node in the middle of its cell. A node that is not shown takes no room.

  • Showing and hiding. set(find("pause"), "Node", "shown", true) shows a menu and everything in it. A node's Opacity and Scale are its children's too. What a script changes is laid out, and the focus given, at the end of that step.

  • Focus. One node that can be used has the focus. A direction moves it to the nearest node that way: one level with it first, else one no further to the side than ahead. With none, a node of a stack that runs that way goes round to the stack's other end, and any other stays. In a grid it goes along the row or the column, past cells that cannot be used, and leaves by an edge only for a node beyond it; coming back, it returns to the cell it left. Where these guess wrong, a node names its neighbour: up, down, left, right. A held direction counts again after 24 steps and then every 7. An axis counts past 0.5; a stick pushed both ways goes the way it is pushed further.

  • Where it starts. When nothing has the focus, the node that last had it among those usable now takes it: a screen shown again is where it was left. Else the [ui] start node, else the highest usable node, the leftmost of those level. ui.focus(entity) gives it to a node that can be used.

  • Modal nodes. While a node with modal = true is shown, only the nodes in it can be used. Of several, the one with the highest order has the interface. It opens as new each time; when it is hidden the focus is back where it was.

  • Using a node. The accept action uses the node with the focus: a button sends its event, a choice goes to its next option, a toggle switches. Left and right move a slider by its step and turn a choice; up and down still move the focus. The pointer gives the focus to the node it moves onto; a press takes hold of that node and letting go on it uses it, so sliding off first cancels. A pressed slider follows the pointer until it lets go. The pointer finds only nodes with Screen. A node with locked = true takes the focus and is not used: ui_locked is sent about it instead. An off button is not there at all.

  • A press on the interface is the interface's. When the pointer's press begins on a shown node's box (any with a w and an h), or anywhere while a modal node is shown, scripts read the [ui] press action as 0 until it is let go.

  • Bars. A Bar is a slider nobody moves: a script sets its value and its fill node follows, hidden when the bar is empty. A fill with an Anchor.dx keeps that much clear at both ends.

  • Events. A use sends the event the node names, about the node, and scripts read it in the same step with events. A slider's event carries its value, a choice's its index and a toggle's whether it is on. ui_moved is the engine's: about the node a person just moved the focus to. A script that sets a value, an index or an on sends nothing.

  • Going back. The back action sends the event named by the back of the node with the focus, else of the nearest node it is in that names one, about that node: give a menu back = "closed" and every control in it goes back the same way. With none, ui_back is sent about the node with the focus.

  • Colours. With a [ui.theme], a usable node takes the colour of its state each step: in its Rect.color, else its Sprite.tint, else its Text.color.

  • Errors are E1301 to E1306. E1306: a tween cannot move the Transform of a node the interface places; tween its Anchor.dx, Scale or Opacity.

A menu in the middle of the frame, in a scene file:

TOML
[menu]
Transform = {}
Screen = {}
Node = {}
Anchor = {}
Stack = { gap = 4 }

[start]
Transform = {}
Screen = {}
Node = { parent = "menu", w = 120, h = 28 }
Rect = { color = 0x334455, layer = 10 }
Text = { text = "START", layer = 11 }
Button = { event = "start" }
TOML
# Optional: text styles, which a text is written in with `Font = { style = "body" }`
# beside its `Text`. A style is a size in pixels (4 to 200) and one to eight TrueType or
# OpenType files; each character is drawn from the first that has it. The files ship
# with the game. Left out: every text is in the built-in pixel font. See Text.
[fonts]
body = { files = ["fonts/Inter.ttf", "fonts/NotoSansSC.otf"], size = 24 }
title = { files = ["fonts/Inter.ttf"], size = 64 }
TOML
[ui.theme]
focus = 0xf2a53b

Generated from Coldwave 0.0.1 r289, 2026-11-30 by the binary itself: do not edit by hand.