package toffee

  1. Overview
  2. Docs
CSS layout engine for OCaml (Flexbox, Grid, Block)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mosaic-0.1.0.tbz
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9

doc/toffee.style/Style/Length_percentage/index.html

Module Style.Length_percentageSource

CSS length-percentage values.

Length-percentage values represent linear measurements in CSS, supporting both absolute lengths and relative percentages. Values are stored in a compact tagged representation via Compact_length.

See Compact_length for conventions on percentage range, abstract units, and f32 precision.

A CSS length-percentage value.

Constructors

Sourceval length : float -> t

length value creates an absolute length.

Sourceval percent : float -> t

percent value creates a percentage length.

The value is a fraction in the range 0.0, 1.0, where 0.5 represents 50%. For 0–100 percentage inputs, prefer pct.

Sourceval px : float -> t

px value creates an absolute length, equivalent to length.

Sourceval pct : float -> t

pct percent creates a percentage length from a 0–100 value.

pct 50.0 is equivalent to percent 0.5.

Sourceval calc : int -> t

calc index creates a calc expression.

The index is an opaque handle to the actual calc representation. The low 3 bits are reserved as a tag and returned as 0.

Constants

Sourceval zero : t

Zero-length constant, equivalent to length 0.0.

Inspection

Sourceval is_length : t -> bool

is_length t returns true if t is an absolute length.

Sourceval is_percent : t -> bool

is_percent t returns true if t is a percentage.

Sourceval is_calc : t -> bool

is_calc t returns true if t is a calc expression.

Value Extraction

Sourceval value : t -> float

value t extracts the numeric value.

For length values, returns the length. For percentage values, returns the percentage in the range 0.0, 1.0.

Raises Failure if t is a calc or any unsupported tag.

Resolution

Sourceval resolve : t -> float -> float

resolve t context resolves t to an absolute length.

For length values, returns the length unchanged. For percentage values, computes context * value t with f32 precision.

Raises Failure if t is a calc expression or any unsupported tag (auto/min-/max-content or fit-content). Use resolve_with_calc for calc support.

Sourceval resolve_with_calc : t -> float -> (int -> float -> float) -> float

resolve_with_calc t context calc_resolver resolves t to an absolute length.

For length and percentage values, behaves like resolve. For calc values, invokes calc_resolver index context where index is the calc expression handle.

Raises Failure if t is not a length, percentage, or calc value.

Sourceval maybe_resolve : t -> float option -> (int -> float -> float) -> float option

maybe_resolve t context calc_resolver resolves t if context is available.

Returns Some length for absolute lengths. Returns Some resolved for percentages and calc expressions when context is Some dim. Returns None when context is None and t is a percentage or calc requiring context.

Raises Failure if t is not a length, percentage, or calc value.

Sourceval resolve_or_zero : t -> float option -> (int -> float -> float) -> float

resolve_or_zero t context calc_resolver resolves t, defaulting to 0.0.

Equivalent to maybe_resolve t context calc_resolver |> Option.value ~default:0.0.

Utilities

Sourceval uses_percentage : t -> bool

uses_percentage t returns true if t contains a percentage component.

Returns true for percentage values and calc expressions. Returns false for absolute lengths.

Sourceval resolved_percentage_size : t -> float -> float option

resolved_percentage_size t parent_size resolves percentage to absolute size.

Returns Some (parent_size * value t) if t is a percentage, None otherwise. Uses f32 precision.

Sourceval resolved_percentage_size_with_calc : t -> float -> (int -> float -> float) -> float option

resolved_percentage_size_with_calc t parent_size calc_resolver resolves percentage or calc to absolute size.

Returns Some size for percentages and calc expressions, None for absolute lengths.

Comparison and Formatting

Sourceval equal : t -> t -> bool

equal a b tests equality of two values.

Calc values are equal if their indices match. Non-calc values are equal if their tags and numeric values match within floating-point epsilon.

Sourceval compare : t -> t -> int

compare a b provides total ordering.

Calc values sort before non-calc values. Within each category, values are ordered by tag, then by numeric value.

Sourceval to_string : t -> string

to_string t formats t for debugging.

Formats as "Npx" for lengths, "N%" for percentages, and "calc(#N)" for calc expressions.

Sourceval pp : Format.formatter -> t -> unit

pp fmt t formats t using to_string.