package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/toffee.tree/Tree/Available_space/index.html
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 toDefinitevalues; constraints propagate unchanged. minoperations convert constraints toDefinitewhen combined with concrete values, as constraints represent unbounded space.maxoperations preserve constraints, as they remain unbounded after comparison.- Optional variants (
min_or_self,add_or_zero) treatNoneas a no-op.
Constants
Construction
of_option opt converts an optional float to available space. Some value becomes Definite value; None becomes Max_content.
Predicates
Conversion
to_option t converts to an option. Definite value becomes Some value; constraints become None.
unwrap_or t default returns the definite value or default if indefinite.
unwrap t returns the definite value.
Raises Invalid_argument if t is not Definite.
unwrap_or_else t default_cb returns the definite value or the result of default_cb () if indefinite.
pp fmt t formats t for pretty-printing.
Combination
or_else t default_cb returns t if Definite, else default_cb ().
set_or_self t value returns Definite v if value is Some v, else t.
maybe_set t value is an alias for set_or_self.
Transformation
map_definite_value t f applies f to the value if Definite, else returns t unchanged.
Layout Computation
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
equal a b tests equality. Definite values are equal if their absolute difference is less than Float.epsilon. Constraints match only their own variant.
compare a b orders values. Definite values sort before constraints; Min_content sorts before Max_content.
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.
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.
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.
clamp t min_val max_val clamps t to the range [min_val, max_val]. Definite values are clamped. Constraints remain unchanged.
add t rhs adds rhs to t. Definite values are incremented. Constraints remain unchanged.
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.
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.
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.
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.
add_or_zero t rhs adds rhs to t if Some, else returns t unchanged. Definite values are incremented; constraints remain unchanged.
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.
size_to_options t converts to a size with optional components. Definite values become Some; constraints become None.
size_maybe_set t value updates dimensions where value has Some. None values leave the corresponding dimension unchanged.