Constraint Expressions (DSL Reference)
expr("...") is Rezi’s constraint expression escape hatch. It’s used for derived layout relationships (parent/viewport/sibling/intrinsic).
expr("...") is Rezi’s constraint expression escape hatch. It’s used for derived layout relationships (parent/viewport/sibling/intrinsic).
Prefer the helper layer for common patterns:
docs/reference/constraints-api.mddocs/guide/constraints.md
Where expressions are allowed
Constraint expressions are accepted on supported layout props such as:
width,heightminWidth,minHeight,maxWidth,maxHeightflexBasisdisplay(layout-driven visibility)
Notably, grid.columns is not expression-enabled in the alpha contract:
ui.grid({ columns: 3 }, children) // ok
ui.grid({ columns: "14 auto 1fr" }, children) // ok
ui.grid({ columns: expr("...") }, children) // invalid in alphaReferences
Inside expr("..."), these references are supported:
parent.w,parent.h— parent content sizeviewport.w,viewport.h— terminal viewport sizeintrinsic.w,intrinsic.h— widget’s measured natural size (when available)#id.w,#id.h,#id.min_w,#id.min_h— sibling widget metrics
Notes:
- Direct
#id.*references require a unique target id in scope. - Shared ids are allowed (for non-interactive nodes) but must be used with sibling aggregation functions (
max_sibling,sum_sibling) to avoid ambiguity. max_sibling/sum_siblingonly aggregate matching ids that share the same parent as the consuming widget.
Operators and syntax
Supported operators:
- Arithmetic:
+,-,*,/ - Comparisons:
>,>=,\<,\<=,==,!= - Ternary:
cond ? then : else - Grouping:
( ... )
There is no && / || operator. Combine conditions using if(...) or ternary.
Comparison operators evaluate to numeric truthiness:
- true →
1 - false →
0
Division by zero evaluates deterministically as 0.
Function allowlist
Supported functions:
clamp(min, value, max)min(a, b)max(a, b)floor(x)ceil(x)round(x)abs(x)if(cond, then, else)(cond > 0is truthy)max_sibling(#id.<metric>)sum_sibling(#id.<metric>)steps(value, t1: r1, t2: r2, ...)
Unknown function names are deterministic errors (ZRUI_INVALID_CONSTRAINT).
Examples
expr("parent.w * 0.5")
expr("clamp(20, viewport.w * 0.25, 50)")
expr("viewport.w >= 110 ? 1 : 0")
expr("if(viewport.w >= 120, 60, 100)")
expr("max(0, parent.w - #sidebar.w - #rail.w - 1)")
expr("max_sibling(#kv-key.min_w)")
expr("steps(viewport.w, 80: 10, 120: 20, 160: 30)")steps(...) is a compact breakpoint helper:
- returns the first matching
valuewhereinput \< threshold - uses the final provided value as the fallback when
inputexceeds all thresholds
Diagnostics
Parse-time (expr(...))
Invalid DSL syntax throws ConstraintSyntaxError and includes source + position.
Frame-time
Constraint and layout integration failures surface deterministically:
ZRUI_INVALID_CONSTRAINT— unknown function, unknown/ambiguous ref, invalid graph usageZRUI_CIRCULAR_CONSTRAINT— a dependency cycle was detectedZRUI_INVALID_PROPS— constraint usage violates widget/layout contracts (for example%size strings, responsive-map size constraints, orgrid.columns: expr(...))
See docs/guide/debugging-constraints.md for a diagnosis flow.
Constraints API Reference
Rezi supports constraint-driven layout via expr("...") and a helper-first API layer that generates constraint expressions for common patterns.
Benchmarks
Rezi includes a benchmark suite comparing terminal UI pipelines across 22 scenarios. The authoritative write-up, methodology, and raw artifacts live in: