ui/layout
lib/ui/layout.vklib/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.
Track = struct { kind i64, value i64 }
1D flex/grid track specification (kind == 0 fixed pixels; kind == 1 proportional flex weight).
ClipStack = struct { frames block[Box] }
Stack of nested clipping boxes for scrollable containers, split panes, and modals.
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.
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 ]
pad-edges = fn [b Box, top i64, right i64, bottom i64, left i64] Box
Insets b by (top, right, bottom, left) padding.
flex-row = fn [bounds Box, tracks block[Track], gap i64] block[Box]
Lays out horizontal columns inside bounds from tracks with gap.
flex-col = fn [bounds Box, tracks block[Track], gap i64] block[Box]
Lays out vertical rows inside bounds from tracks with gap.
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).
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).
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).
push-clip = fn [mut cs ClipStack, mut c cv/Canvas, rect Box]
Pushes an intersected clip box onto cs and activates it on c.
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).