veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

ui/layout

lib/ui/layout.vk

lib/ui/layout.vk Pure-Veko 1D/2D flex, CSS-like grid, split-pane, and nested clip-stack layout engine. Zero capabilities required; works standalone or through ui/widgets.

Box struct
signature
Box = struct { x i64, y i64, w i64, h i64 }

Axis-aligned integer layout rectangle.

Track struct
signature
Track = struct { kind i64, value i64 }

1D flex/grid track specification (kind == 0 fixed pixels; kind == 1 proportional flex weight).

Span struct
signature
Span = struct { offset i64, length i64 }

Solved 1D [offset, length] span along an axis.

ClipStack struct
signature
ClipStack = struct { frames block[Box] }

Stack of nested clipping boxes for scrollable containers, split panes, and modals.

px fn
signature
px = fn [pixels i64] Track

Creates a fixed-pixel Track.

flex fn
signature
flex = fn [weight i64] Track

Creates a proportional flex-grow Track (weight >= 1).

signature
solve-tracks = fn [origin i64, total_len i64, tracks block[Track], gap i64] block[Span]

Solves a 1D list of Tracks across [origin .. origin + total_len] with inter-track gap.

Executable Example
veko
use [lay = ui/layout]
spans = lay/solve-tracks 10 310 [(lay/px 100) (lay/flex 1) (lay/flex 1)] 5
if (len spans) != 3 or spans[0].length != 100 or spans[1].length != 100 or spans[2].offset != 220 [
    err 'solve-tracks'
] else [ .ok ]
signature
pad-edges = fn [b Box, top i64, right i64, bottom i64, left i64] Box

Insets b by (top, right, bottom, left) padding.

pad fn
signature
pad = fn [b Box, p i64] Box

Uniformly insets b on all 4 sides by p pixels.

signature
flex-row = fn [bounds Box, tracks block[Track], gap i64] block[Box]

Lays out horizontal columns inside bounds from tracks with gap.

signature
flex-col = fn [bounds Box, tracks block[Track], gap i64] block[Box]

Lays out vertical rows inside bounds from tracks with gap.

grid fn
signature
grid = fn [bounds Box, rows i64, cols i64, row_gap i64, col_gap i64] block[Box]

Lays out a 2D rows x cols uniform grid inside bounds (row-major r * cols + c).

signature
split-h = fn [bounds Box, ratio_pct i64, divider_w i64] block[Box]

Splits bounds horizontally into [left_box, divider_box, right_box] at ratio_pct (10..90).

signature
split-v = fn [bounds Box, ratio_pct i64, divider_h i64] block[Box]

Splits bounds vertically into [top_box, divider_box, bottom_box] at ratio_pct (10..90).

signature
new-clip-stack = fn [] ClipStack

Creates an empty ClipStack.

signature
push-clip = fn [mut cs ClipStack, mut c cv/Canvas, rect Box]

Pushes an intersected clip box onto cs and activates it on c.

signature
pop-clip = fn [mut cs ClipStack, mut c cv/Canvas]

Pops the top clip box from cs and restores the parent clip (or full canvas if empty).