🧹
venik
Flexbox layout engine built for JavaScript games.
✨ Simple API
import { Node, Edge, Justify, Align, Direction } from "venik";
const hud = new Node();
hud.setPadding(Edge.All, 16);
hud.setJustifyContent(Justify.SpaceBetween);
hud.setAlignItems(Align.FlexEnd);
const healthBar = new Node();
healthBar.setWidth("25%");
healthBar.setHeight(24);
hud.insertChild(healthBar, 0);
// Runs every frame. A clean tree returns immediately;
// a dirty one revisits only dirty branches.
function frame(w: number, h: number) {
hud.setWidth(w);
hud.setHeight(h);
hud.calculateLayout(undefined, undefined, Direction.LTR);
drawRect(
healthBar.getComputedLeft(),
healthBar.getComputedTop(),
healthBar.getComputedWidth(),
healthBar.getComputedHeight(),
);
}
⚡ Best-in-class speed
| venik | flexily | yoga-layout |
|---|
| One leaf changes | 25µs | 200µs | 260µs |
|---|
| 50 leaves change | 510µs | 730µs | 1660µs |
|---|
| Full relayout | 1000µs | 1050µs | 3190µs |
|---|
♻️ Small runtime footprint
| venik | flexily | yoga-layout |
|---|
| One leaf changes | 1 KB | 16 KB | 1 KB |
|---|
| 50 leaves change | 15 KB | 77 KB | 22 KB |
|---|
| Full relayout | 65 KB | 181 KB | 2.1 KB |
|---|
📦 Small bundle size
| venik | flexily | yoga-layout |
|---|
| Minified | 72 KB | 71 KB | 125 KB |
|---|
| Minified + gzip | 19 KB | 22 KB | 50 KB |
|---|