package toffee

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

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mosaic-0.3.0.tbz
sha256=a92cbbcbe016fb19fb0a749222da0e459a9567aef3f4c7340d9bd6b71c53ed6f
sha512=6a7ab054605538bb31a2b73a1a6d093981a2704c9f0af5852221c05735290d74aca7c7282298c4d0f91e86a800e2ccd94b4918af883cd963449c758eb6b272b3

doc/toffee.geometry/Toffee_geometry/Size/index.html

Module Toffee_geometry.SizeSource

2-dimensional size representation.

A generic container representing width and height extents. The type is polymorphic over the contained value type, enabling optional sizes (float option t) and dimension-typed sizes. Concrete sizes of floats are Sizef.t, which store their floats flat.

All operations preserve type safety and handle axis-specific transformations through abstract and absolute axis types.

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

'a t represents a 2-dimensional size with width and height of type 'a.

Constants

Sourceval none : 'a option t

none is a size with both width and height set to None.

Creation

Sourceval make : 'a -> 'a -> 'a t

make width height creates a size.

Sourceval square : 'a -> 'a t

square side creates a size with equal width and height.

Mapping Functions

Sourceval map : ('a -> 'b) -> 'a t -> 'b t

map f size applies f to both width and height, transforming 'a t into 'b t.

Sourceval map_width : ('a -> 'a) -> 'a t -> 'a t

map_width f size applies f to the width while preserving the height.

Sourceval map_height : ('a -> 'a) -> 'a t -> 'a t

map_height f size applies f to the height while preserving the width.

Sourceval zip_map : 'b t -> ('a -> 'b -> 'c) -> 'a t -> 'c t

zip_map other f size applies f pairwise to corresponding dimensions of size and other.

Sourceval map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

map2 f s1 s2 is zip_map s2 f s1.

Axis Accessors

Sourceval get : Abstract_axis.t -> 'a t -> 'a

get axis size retrieves the dimension corresponding to axis.

Returns width for Abstract_axis.Inline and height for Abstract_axis.Block.

Sourceval set : Abstract_axis.t -> 'a -> 'a t -> 'a t

set axis value size returns a new size with the dimension corresponding to axis set to value.

Sets width for Abstract_axis.Inline and height for Abstract_axis.Block.

Sourceval get_absolute : Absolute_axis.t -> 'a t -> 'a

get_absolute axis size retrieves the dimension corresponding to axis.

Returns width for Absolute_axis.Horizontal and height for Absolute_axis.Vertical.

Option-Specific Operations

Sourceval unwrap_or : 'a t -> 'a option t -> 'a t

unwrap_or alt size unwraps each dimension of size, using the corresponding dimension from alt when None.

Sourceval choose_first : 'a option t -> 'a option t -> 'a option t

choose_first size alt selects dimensions from size when Some, falling back to alt when None.

Sourceval both_axis_defined : 'a option t -> bool

both_axis_defined size returns true if both width and height are Some.

Sourceval apply_aspect_ratio : float option -> float option t -> float option t

apply_aspect_ratio aspect_ratio size applies aspect_ratio to compute the missing dimension.

If aspect_ratio is Some ratio:

  • When width is Some but height is None, computes height as width / ratio
  • When height is Some but width is None, computes width as height * ratio
  • Otherwise returns size unchanged

If aspect_ratio is None, returns size unchanged.

Comparison and Formatting

Sourceval compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int

compare cmp a b performs lexicographic comparison using cmp, comparing width first, then height.

Sourceval equal_with : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

equal_with eq a b tests equality using eq for both width and height.

Sourceval to_string : ('a -> string) -> 'a t -> string

to_string f size converts size to a string representation using f for each dimension.

Sourceval pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

pp f fmt size formats size using fmt and f for each dimension.

Option Operations

These operations implement Taffy's MaybeMath patterns for working with optional values. They follow specific semantics where None represents the absence of a constraint.

Option → Option Operations

Sourceval min_option : float option t -> float option t -> float option t

min_option a b computes the component-wise minimum of optional sizes.

For each dimension:

  • Some l, Some r produces Some (min l r)
  • Some _, None produces the left value
  • None, _ produces None
Sourceval max_option : float option t -> float option t -> float option t

max_option a b computes the component-wise maximum of optional sizes.

For each dimension:

  • Some l, Some r produces Some (max l r)
  • Some _, None produces the left value
  • None, _ produces None
Sourceval add_option : float option t -> float option t -> float option t

add_option a b adds optional sizes component-wise.

For each dimension:

  • Some l, Some r produces Some (l + r)
  • Some _, None produces the left value
  • None, Some _ produces None
Sourceval sub_option : float option t -> float option t -> float option t

sub_option a b subtracts optional sizes component-wise.

For each dimension:

  • Some l, Some r produces Some (l - r)
  • Some _, None produces the left value
  • None, _ produces None
Sourceval clamp_option : float option t -> float option t -> float option t -> float option t

clamp_option min max size clamps each dimension of size between optional bounds.

For each dimension, returns:

  • Some (clamp base min_val max_val) when all three are Some
  • Some (clamp base _ max_val) when only max is Some
  • Some (clamp base min_val _) when only min is Some
  • The original value when both bounds are None
  • None when size is None