Style.DimensionSourceCSS dimension values supporting length, percentage, auto, and calc().
A dimension represents a CSS size value used for properties like width, height, and flex_basis. Dimensions are stored in a compact tagged representation backed by Compact_length.
See Compact_length for conventions on percentage range, abstract units, and f32 precision.
A CSS dimension value.
percent value creates a percentage dimension.
The value is a fraction in the range 0.0, 1.0, where 0.5 represents 50%. For 0–100 percentage inputs, prefer pct.
px value creates an absolute length dimension in abstract pixel units.
Equivalent to length. Provided for CSS-style naming.
pct percent creates a percentage dimension from a 0–100 value.
pct 50.0 is equivalent to percent 0.5.
calc index creates a calc() dimension from an opaque index.
The index identifies a calc expression to be resolved later. The lower 3 bits are reserved as a tag and returned as 0.
uses_percentage t returns true if t involves percentage computation.
Returns true for percent and calc dimensions.
value t extracts the numeric value from t.
Raises Failure if t is auto, min-content, max-content, or calc.
to_option t returns Some value if t is a length, None otherwise.
resolved_percentage_size t parent_size resolves percentage dimensions.
Returns Some (value * parent_size) if t is a percentage, None otherwise. The result is rounded to f32 precision to match Taffy behavior.
val resolved_percentage_size_with_calc :
t ->
float ->
(int -> float -> float) ->
float optionresolved_percentage_size_with_calc t parent_size calc_resolver resolves percentage and calc dimensions.
Returns:
Some (value * parent_size) if t is a percentageSome (calc_resolver index parent_size) if t is a calcNone otherwiseThe calc resolver receives the calc index and parent size, returning the computed value. Percentage results are rounded to f32 precision.
maybe_resolve t context calc_resolver resolves t using context.
Returns:
None if t is auto or context is None for percent/calcSome value if t is a lengthSome (context * value) if t is a percent and context is SomeSome (calc_resolver index context) if t is a calc and context is SomePercentage and calc results are rounded to f32 precision.
Raises Failure if t is not length, percentage, auto, or calc.
resolve_or_zero t context calc_resolver resolves t or returns 0.0.
Equivalent to Option.value ~default:0.0 (maybe_resolve t context calc_resolver).
equal a b tests structural equality.
Calc dimensions are equal if their indices match. Lengths and percentages are compared within Float.epsilon tolerance.
compare a b provides total ordering.
Calc dimensions sort before others by index. Non-calc dimensions sort by tag then value.
pp fmt t formats t for debugging.