package toffee

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Tree.Available_spaceSource

Available space constraints for layout computation.

Available space represents the amount of space available to a node in a given axis during CSS layout computation. It distinguishes between definite sizes (concrete pixel values) and intrinsic sizing constraints (min-content and max-content). See CSS Sizing Level 3.

Layout algorithms use these constraints to determine node dimensions. Definite specifies a fixed pixel count, Min_content instructs the node to shrink-wrap to its minimum intrinsic size, and Max_content instructs the node to expand to its maximum intrinsic size.

Constraint Propagation

Operations on available space follow consistent semantics for constraint propagation:

  • Arithmetic operations (add, sub) apply only to Definite values; constraints propagate unchanged.
  • min operations convert constraints to Definite when combined with concrete values, as constraints represent unbounded space.
  • max operations preserve constraints, as they remain unbounded after comparison.
  • Optional variants (min_or_self, add_or_zero) treat None as a no-op.
Sourcetype t =
  1. | Definite of float
    (*

    Definite space of a specified number of pixels.

    *)
  2. | Min_content
    (*

    Indefinite space under min-content constraint. The node shrinks to its minimum intrinsic size.

    *)
  3. | Max_content
    (*

    Indefinite space under max-content constraint. The node expands to its maximum intrinsic size.

    *)

Constants

Sourceval zero : t

zero is Definite 0.0.

Sourceval max_content : t

max_content is Max_content.

Sourceval min_content : t

min_content is Min_content.

Construction

Sourceval of_length : float -> t

of_length value creates Definite value.

Sourceval of_float : float -> t

of_float value creates Definite value. Alias for of_length.

Sourceval of_option : float option -> t

of_option opt converts an optional float to available space. Some value becomes Definite value; None becomes Max_content.

Predicates

Sourceval is_definite : t -> bool

is_definite t returns true if t is Definite, else false.

Conversion

Sourceval to_option : t -> float option

to_option t converts to an option. Definite value becomes Some value; constraints become None.

Sourceval unwrap_or : t -> float -> float

unwrap_or t default returns the definite value or default if indefinite.

Sourceval unwrap : t -> float

unwrap t returns the definite value.

Raises Invalid_argument if t is not Definite.

Sourceval unwrap_or_else : t -> (unit -> float) -> float

unwrap_or_else t default_cb returns the definite value or the result of default_cb () if indefinite.

Sourceval to_string : t -> string

to_string t converts to a string representation.

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

pp fmt t formats t for pretty-printing.

Combination

Sourceval or_ : t -> t -> t

or_ t default returns t if Definite, else default.

Sourceval or_else : t -> (unit -> t) -> t

or_else t default_cb returns t if Definite, else default_cb ().

Sourceval set_or_self : t -> float option -> t

set_or_self t value returns Definite v if value is Some v, else t.

Sourceval maybe_set : t -> float option -> t

maybe_set t value is an alias for set_or_self.

Transformation

Sourceval map_definite_value : t -> (float -> float) -> t

map_definite_value t f applies f to the value if Definite, else returns t unchanged.

Layout Computation

Sourceval compute_free_space : t -> float -> float

compute_free_space t used_space computes remaining free space after allocating used_space.

Returns Float.infinity for Max_content (unbounded expansion), 0.0 for Min_content (no free space for expansion), and available -. used_space for Definite available.

Comparison

Sourceval equal : t -> t -> bool

equal a b tests equality. Definite values are equal if their absolute difference is less than Float.epsilon. Constraints match only their own variant.

Sourceval compare : t -> t -> int

compare a b orders values. Definite values sort before constraints; Min_content sorts before Max_content.

Sourceval is_roughly_equal : t -> t -> bool

is_roughly_equal t other tests approximate equality. Equivalent to equal.

Arithmetic Operations with Concrete Values

These operations combine available space with concrete float values. Operations on Definite values apply standard arithmetic. Constraint handling varies by operation as documented.

Sourceval min : t -> float -> t

min t rhs returns the minimum of t and rhs. Definite values use Float.min. Constraints become Definite rhs, as unbounded space is greater than any finite value.

Sourceval max : t -> float -> t

max t rhs returns the maximum of t and rhs. Definite values use Float.max. Constraints remain unchanged, as they represent unbounded space greater than any finite value.

Sourceval clamp : t -> float -> float -> t

clamp t min_val max_val clamps t to the range [min_val, max_val]. Definite values are clamped. Constraints remain unchanged.

Sourceval add : t -> float -> t

add t rhs adds rhs to t. Definite values are incremented. Constraints remain unchanged.

Sourceval sub : t -> float -> t

sub t rhs subtracts rhs from t. Definite values are decremented. Constraints remain unchanged.

Arithmetic Operations with Optional Values

These operations combine available space with optional float values. When the optional value is None, the operation returns t unchanged.

Sourceval min_or_self : t -> float option -> t

min_or_self t rhs returns the minimum of t and rhs. Returns t unchanged if rhs is None. Constraints become Definite when combined with Some value.

Sourceval max_or_self : t -> float option -> t

max_or_self t rhs returns the maximum of t and rhs. Returns t unchanged if rhs is None. Constraints remain unchanged when combined with Some value.

Sourceval clamp_or_self : t -> float option -> float option -> t

clamp_or_self t min_val max_val clamps t to the optional bounds. None bounds are ignored. Definite values are clamped; constraints remain unchanged.

Sourceval add_or_zero : t -> float option -> t

add_or_zero t rhs adds rhs to t if Some, else returns t unchanged. Definite values are incremented; constraints remain unchanged.

Sourceval sub_or_zero : t -> float option -> t

sub_or_zero t rhs subtracts rhs from t if Some, else returns t unchanged. Definite values are decremented; constraints remain unchanged.

Size Operations

Operations on pairs of available space values for width and height.

Sourcetype size = {
  1. width : t;
  2. height : t;
}

A size with width and height constraints.

Sourceval size_to_options : size -> float option Geometry.size

size_to_options t converts to a size with optional components. Definite values become Some; constraints become None.

Sourceval size_maybe_set : size -> float option Geometry.size -> size

size_maybe_set t value updates dimensions where value has Some. None values leave the corresponding dimension unchanged.