Skip to content

UI Layout

Estella provides a complete UI framework with layout, interaction, text rendering, and a library of ready-made widgets. Layout computation runs in C++/WASM for performance, while all components are configured from TypeScript.

Quick Start

In the editor: right-click the Hierarchy → CreateUI → choose a widget (Button, Slider, Text, etc.). The editor creates the entity hierarchy with all required components pre-configured.

To create UI from code:

import { defineSystem, addStartupSystem, Commands, Transform, Sprite, UIRect, Text, Parent } from 'esengine';
addStartupSystem(defineSystem([Commands()], (cmds) => {
const root = cmds.spawn()
.insert(Transform)
.insert(UIRect, { anchorMin: { x: 0, y: 0 }, anchorMax: { x: 1, y: 1 } })
.id();
cmds.spawn()
.insert(Transform)
.insert(Sprite)
.insert(UIRect, { size: { x: 200, y: 40 } })
.insert(Text, { content: 'Hello World', fontSize: 24 })
.insert(Parent, { entity: root });
}));

UIRect

Every UI element needs a UIRect to participate in layout. It defines position and size relative to the parent using an anchor-based system.

PropertyTypeDefaultDescription
anchorMinVec2{0.5, 0.5}Bottom-left anchor (0–1)
anchorMaxVec2{0.5, 0.5}Top-right anchor (0–1)
offsetMinVec2{0, 0}Pixel offset from anchorMin
offsetMaxVec2{0, 0}Pixel offset from anchorMax
sizeVec2{100, 100}Width and height (when anchors are equal)
pivotVec2{0.5, 0.5}Pivot point for rotation and scaling

When anchorMin equals anchorMax, the element has a fixed size at the anchor point. When they differ, the element stretches between anchors and size is computed automatically.

FlexContainer

CSS Flexbox-like layout for automatic child arrangement.

PropertyTypeDefaultDescription
directionFlexDirectionRowRow, Column, RowReverse, ColumnReverse
wrapFlexWrapNoWrapNoWrap, Wrap
justifyContentJustifyContentStartStart, Center, End, SpaceBetween, SpaceAround, SpaceEvenly
alignItemsAlignItemsStretchStart, Center, End, Stretch
gapVec2{0, 0}Spacing between items
paddingVec4{x:0, y:0, z:0, w:0}Padding as {x: top, y: right, z: bottom, w: left}

FlexItem

Child properties for entities inside a FlexContainer.

PropertyTypeDefaultDescription
flexGrownumber0How much the item grows to fill space
flexShrinknumber1How much the item shrinks when space is tight
flexBasisnumber-1Base size before grow/shrink (-1 = auto)
ordernumber0Display order override

LayoutGroup

Grid-like layout with direction, spacing, and alignment.

PropertyTypeDefaultDescription
directionLayoutDirectionHorizontalHorizontal (0), Vertical (1)
spacingnumber0Space between children
paddingobject{left:0, top:0, right:0, bottom:0}Border spacing
childAlignmentChildAlignmentStartStart, Center, End
reverseOrderbooleanfalseReverse layout order

Next Steps