Macaw.Grid (macaw v0.6.0)

Copy Markdown View Source

The grid a surface places its cells on (spec/06 §3.3), the built-in layout :grid (Macaw.Layout): 12 columns, or 6 or 24 by {:grid, columns: n}.

Places are %{x, y, w, h} in integer units: x from 0 to one less than the columns, w from 1 with x + w at most the columns, y from 0, h from 1, and y + h at most rows/0. Reading order is by y, then x, then name, and is the DOM order. Placement is by classes from one static stylesheet, never inline style:

iex> Macaw.Grid.classes(%{x: 0, y: 2, w: 6, h: 3})
"mw-cell mw-col-1 mw-span-6 mw-row-3 mw-rows-3"

Summary

Functions

A place's classes: the cell, its column and span, its row and rows, the same on every width; the container's class sets the width (container/1).

The grid's columns when a surface chooses none, 12.

The faults of the cells' places on 12 columns, each at [:cells, name, :place]: a bound broken is {:out_of_bounds, what, value} (what one of :x, :w, :x_plus_w, :y, :h, :y_plus_h); two cells overlapping is {:overlap, other} at the later one in reading order. cells maps names to anything with a place. faults/2 takes the grid's options, its columns among them.

faults/1 on the options' columns.

The cells' names in reading order: by y, then x, then name.

The most rows a grid places a cell in, 64, so every placement has a class.

A place's declared size in CSS pixels on 12 columns: its share of the surface's width and its rows' height, {w * width / 12, h * row_height}. size/4 takes the grid's options, its columns among them.

A place's declared size on the options' columns: {w * width / columns, h * row_height}.

The grid's one static stylesheet, for every width: the grid (12 columns, and .mw-grid-6 and .mw-grid-24 for the others), a rule per column start and column span up to the widest, per row start and row span, and the container query that stacks every cell into reading order when the surface is narrower than 40rem.

The stylesheet's path, its content address (Macaw.Component.Stylesheet.path/1).

The widths a grid may have, in columns: 6, 12 and 24, so its stylesheet is static.

Types

place()

@type place() :: %{
  x: non_neg_integer(),
  y: non_neg_integer(),
  w: pos_integer(),
  h: pos_integer()
}

Functions

classes(map)

@spec classes(place()) :: String.t()

A place's classes: the cell, its column and span, its row and rows, the same on every width; the container's class sets the width (container/1).

columns()

@spec columns() :: pos_integer()

The grid's columns when a surface chooses none, 12.

faults(cells)

@spec faults(%{required(String.t()) => %{place: place()}}) :: [Macaw.Base.Fault.t()]

The faults of the cells' places on 12 columns, each at [:cells, name, :place]: a bound broken is {:out_of_bounds, what, value} (what one of :x, :w, :x_plus_w, :y, :h, :y_plus_h); two cells overlapping is {:overlap, other} at the later one in reading order. cells maps names to anything with a place. faults/2 takes the grid's options, its columns among them.

faults(cells, options)

@spec faults(%{required(String.t()) => %{place: place()}}, map()) :: [
  Macaw.Base.Fault.t()
]

faults/1 on the options' columns.

order(cells)

@spec order(%{required(String.t()) => %{place: place()}}) :: [String.t()]

The cells' names in reading order: by y, then x, then name.

rows()

@spec rows() :: pos_integer()

The most rows a grid places a cell in, 64, so every placement has a class.

size(place, width, row_height)

@spec size(place(), number(), number()) :: {number(), number()}

A place's declared size in CSS pixels on 12 columns: its share of the surface's width and its rows' height, {w * width / 12, h * row_height}. size/4 takes the grid's options, its columns among them.

size(map, options, width, row_height)

@spec size(place(), map(), number(), number()) :: {number(), number()}

A place's declared size on the options' columns: {w * width / columns, h * row_height}.

stylesheet()

@spec stylesheet() :: String.t()

The grid's one static stylesheet, for every width: the grid (12 columns, and .mw-grid-6 and .mw-grid-24 for the others), a rule per column start and column span up to the widest, per row start and row span, and the container query that stacks every cell into reading order when the surface is narrower than 40rem.

stylesheet_path()

@spec stylesheet_path() :: String.t()

The stylesheet's path, its content address (Macaw.Component.Stylesheet.path/1).

widths()

@spec widths() :: [pos_integer(), ...]

The widths a grid may have, in columns: 6, 12 and 24, so its stylesheet is static.