package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/toffee.style/Style/Dimension/index.html
Module Style.DimensionSource
CSS 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.
Constructors
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.
Constants
Inspection
uses_percentage t returns true if t involves percentage computation.
Returns true for percent and calc dimensions.
Value Extraction
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.
Resolution
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)iftis a percentageSome (calc_resolver index parent_size)iftis a calcNoneotherwise
The 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:
Noneiftis auto orcontextisNonefor percent/calcSome valueiftis a lengthSome (context * value)iftis a percent andcontextisSomeSome (calc_resolver index context)iftis a calc andcontextisSome
Percentage 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).
Comparison
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.