package toffee

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

Module Style.Grid_placementSource

CSS Grid item placement specification.

This module defines how grid items are positioned within a CSS Grid container using line-based placement. It supports CSS grid line coordinates, named grid lines, and span-based placement.

Grid lines use CSS coordinates where positive indices start from 1 at the grid's start edge and negative indices start from -1 at the grid's end edge. Line index 0 is invalid and treated as Auto.

See CSS Grid Line Placement.

Sourcetype grid_line = int

Grid line coordinate in CSS Grid coordinates.

Positive values start from 1 at the grid's start edge. Negative values start from -1 at the grid's end edge. The value 0 is invalid and treated as Auto.

Sourcetype t =
  1. | Auto
    (*

    Place item according to auto-placement algorithm.

    *)
  2. | Line of grid_line
    (*

    Place item at specified line index.

    *)
  3. | Named_line of string * int
    (*

    Place item at specified named line. The string is the line name and the int is the occurrence count (e.g., the 2nd line named "header").

    *)
  4. | Span of int
    (*

    Item spans specified number of tracks.

    *)
  5. | Named_span of string * int
    (*

    Item spans until the nth line named with the given string.

    *)

Grid placement specification for a single axis.

Defaults to Auto.

Construction

Sourceval auto : t

auto creates an automatic placement. Equivalent to Auto.

Sourceval line : int -> t

line index creates a line-based placement at index.

Line 0 is invalid and will be treated as Auto during layout.

Sourceval span : int -> t

span count creates a span-based placement spanning count tracks.

Sourceval named_line : string -> int -> t

named_line name index creates a placement at the indexth occurrence of the named line name.

Sourceval named_span : string -> int -> t

named_span name count creates a span until the countth occurrence of the named line name.

Sourceval default : t

default returns Auto.

Predicates

Sourceval is_definite : t -> bool

is_definite placement returns true if the placement is definite.

A placement is definite if it specifies a non-zero line index or a named line. Auto and Span values are indefinite. Line 0 is invalid and treated as Auto, thus indefinite.

Conversion

Sourceval into_origin_zero_placement_ignoring_named : t -> int -> Grid.Origin_zero_placement.t

into_origin_zero_placement_ignoring_named placement explicit_track_count converts placement to origin-zero coordinates, ignoring named lines.

Named lines and named spans are converted to Auto. Line 0 is converted to Auto. Other line placements are converted using explicit_track_count to translate CSS grid coordinates (1-indexed, negatives from end) to origin-zero coordinates (0-indexed from start).

Sourceval into_origin_zero_placement : t -> int -> Grid.Origin_zero_placement.t

into_origin_zero_placement placement explicit_track_count converts placement to origin-zero coordinates.

Line 0 is converted to Auto. Other line placements are converted using explicit_track_count to translate CSS grid coordinates to origin-zero coordinates.

Raises Failure if placement is Named_line or Named_span. Named lines must be resolved before calling this function.

Comparison and display

Sourceval equal : t -> t -> bool

equal a b tests structural equality of two placements.

Sourceval compare : t -> t -> int

compare a b provides a total ordering on placements.

Ordering: Auto < Line < Named_line < Span < Named_span. Within each variant, values are compared structurally.

Sourceval to_string : t -> string

to_string placement converts placement to a string representation.

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

pp fmt placement pretty-prints placement to fmt.

Line operations

Operations on Geometry.Line.t containing grid placements. These work on pairs of start and end placements along a single axis.

Sourcemodule Line : sig ... end