Ui

:= []

Defaults and small helpers for the UI tree in Scene.ui. A game writes the Element tags itself, Box(config, children) and Text(text), and takes the config and the Text from here. The types have the same shapes as the UI types in Vocabulary. Sizes are in logical pixels.

For example, Box(Ui.float_at(LeftTop, { x: 16.0, y: 16.0 }), [Text(Ui.label("Score"))]) puts one line of text in the top-left corner of the window.

default_box : BoxConfig

Clay's defaults: fits its children, no padding, no gap, a Row, children at the start, no background, square corners and not floating.

default_text : Text

An empty string, 24 pixels high, opaque white, that breaks lines between words.

label : Str -> Text

A default_text that shows str.

float_at : AttachPoint, Offset -> BoxConfig

A default_box that floats to the window. It puts its own attach point on the window's, then moves by offset. It ignores its parent's layout.

panel : AttachPoint, Offset -> BoxConfig

A float_at Box for a HUD: 8 pixels of padding, a black background at half alpha and corners with a radius of 8.

pad_all : F32 -> Padding

The same padding on all four sides.

Padding : { left : F32, right : F32, top : F32, bottom : F32 }

The space between a Box's edges and its children.

Offset : { x : F32, y : F32 }

A distance from an AttachPoint.

Rgba : { r : F32, g : F32, b : F32, a : F32 }

A colour with linear channels from 0 to 1. Alpha is not premultiplied.

Sizing : [Fit({ min : F32, max : F32 }), Grow({ min : F32, max : F32 }), Fixed(F32), Percent(F32)]

How a Box sizes along one axis. See Vocabulary.Sizing.

Align : [Start, Center, End]

Where a Box puts its children along one axis.

AttachPoint : [LeftTop, LeftCenter, LeftBottom, CenterTop, CenterCenter, CenterBottom, RightTop, RightCenter, RightBottom]

The point of a floating Box that the host puts on the same point of the window.

BoxConfig : { width : Sizing, height : Sizing, pad : Padding, gap : F32, direction : [Row, Col], child_align : { x : Align, y : Align }, background : Rgba, radius : F32, floating : [NoFloat, Float({ attach : AttachPoint, offset : Offset })] }

The layout and look of a Box. Start from default_box. See Vocabulary.BoxConfig.

Text : { str : Str, size : F32, color : Rgba, wrap : [Words, None] }

One string at a size and a colour. Start from default_text or label. See Vocabulary.Text.