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/Grid/index.html

Module Style.GridSource

Grid coordinate systems and track utilities with submodules.

include module type of Grid

Coordinate Systems

Two coordinate systems reference grid lines (gaps between rows/columns):

  • CSS Grid Line coordinates: Used in grid-row/grid-column CSS properties. Line 1 is at the left/top edge of the explicit grid. Line -1 is at the right/bottom edge. Line 0 is invalid and treated as Auto.
  • Origin-zero coordinates: Normalized internal form where line 0 is at the left/top edge of the explicit grid. Lines increment rightward/downward (1, 2, 3, ...) and decrement leftward/upward (-1, -2, -3, ...).

All functions in this module operate on these coordinate systems to support grid placement and track resolution.

Sourcetype origin_zero_line = int

origin_zero_line is a 0-indexed grid line coordinate used internally during grid layout computation.

Origin-zero coordinates normalize CSS grid lines: line 0 is at the left/top edge of the explicit grid, positive values extend right/down, and negative values extend left/up.

Sourcemodule Origin_zero_placement : sig ... end

Grid placement specification in origin-zero coordinates.

Sourcetype track_counts = {
  1. negative_implicit : int;
    (*

    Number of implicit tracks before the explicit grid.

    *)
  2. explicit : int;
    (*

    Number of explicit tracks.

    *)
  3. positive_implicit : int;
    (*

    Number of implicit tracks after the explicit grid.

    *)
}

track_counts represents the distribution of tracks across the implicit and explicit grids in a single axis.

The implicit grid extends the explicit grid to accommodate items placed outside it. Tracks are divided into three regions: negative implicit tracks (before the explicit grid), explicit tracks (defined by grid-template-rows/grid-template-columns), and positive implicit tracks (after the explicit grid).

Sourcetype grid_line = int

grid_line is a CSS grid line coordinate (1-indexed, negative allowed).

Positive values count from the start of the explicit grid (1, 2, 3, ...). Negative values count from the end (-1, -2, -3, ...). Line 0 is invalid per the CSS Grid specification and is treated as Auto.

Coordinate Conversion

Sourceval grid_line_to_origin_zero_line : grid_line -> int -> origin_zero_line

grid_line_to_origin_zero_line line explicit_track_count converts a CSS grid line to an origin-zero line coordinate.

Positive lines are adjusted by subtracting 1 to convert from 1-indexed to 0-indexed. Negative lines count backward from the end of the explicit grid. Line 0 is invalid and converted to 0.

  • parameter line

    The CSS grid line coordinate.

  • parameter explicit_track_count

    The number of explicit tracks in the axis.

Track Count Operations

Sourceval make_track_counts : negative_implicit:int -> explicit:int -> positive_implicit:int -> track_counts

make_track_counts ~negative_implicit ~explicit ~positive_implicit creates a track count record.

Sourceval total_track_count : track_counts -> int

total_track_count counts returns the total number of tracks across implicit and explicit grids.

Sourceval oz_line_to_track : origin_zero_line -> track_counts -> int option

oz_line_to_track line counts converts an origin-zero line to a track index for the track immediately following the line.

Returns None if line lies outside the implicit grid bounds or refers to the final grid line. Track indices are 0-based relative to the start of the implicit grid and include negative implicit tracks.

Sourceval oz_line_to_next_track : origin_zero_line -> int

oz_line_to_next_track line returns the index of the track immediately following the given origin-zero line.

Negative lines are clamped to 0. This function is used when resolving grid item placement.

Sourceval oz_line_range_to_track_range : origin_zero_line -> origin_zero_line -> int * int

oz_line_range_to_track_range start_line end_line converts an origin-zero line range to a track range (inclusive start, exclusive end).

The returned pair represents start_track, end_track indices suitable for iterating over tracks in the range.

Sourcemodule Auto_flow = Grid_auto_flow
Sourcemodule Placement = Grid_placement
Sourcemodule Track_sizing_function = Track_sizing_function
Sourcemodule Repetition_count = Repetition_count
Sourcemodule Repetition = Grid_repetition
Sourcemodule Template_component = Grid_template_component
Sourcemodule Template_area = Grid_template_area