How a surface lays out its cells (spec/06 §3.3): a behavior, the way a component is one. A layout checks its options and each cell's place, gives the placement faults, the reading order, each cell's classes and declared size, and its one stylesheet.
A surface names its layout by layout, a name or {name, options} (:grid). The
built-in layouts are builtins/0; a host's registry holds them and the layouts it adds
(Macaw.Registry.new/2), and nothing else, so a layout no registry holds is
{:unknown, :layout} at [:layout] (spec/12 §1.1).
Every rule a layout keeps is the web's (spec/10): the reading order is the visual order, and placement is by classes from a static stylesheet served by its content address, never inline style.
Summary
Types
A cell as a layout reads it: anything with a place.
A layout as a surface names it: its name, or its name and options.
Callbacks
A cell's classes, the only way it is placed.
The classes of the element holding the cells, which the layout's stylesheet styles.
The placement faults of the cells, by path from the surface, all at once.
The layout's name, as a surface spells it ("grid").
The layout's options, checked: {:ok, options} or the faults, by path from the options.
A layout taking no options answers {:ok, %{}} for none given.
The cells' names in reading order, which is the visual order and the DOM's.
A cell's place under this layout, checked: {:ok, place} or the faults, by path from
the place. nil is a cell with no place. It judges the place's shape alone, never by
the options, so a place is judged even when the options fail (#236); a rule that needs
the options (the grid's bounds) is faults/2's.
A cell's declared size in CSS pixels, {width, height}, from the surface's width and
row height: what its component lays out at before any measurement.
The layout's static stylesheet for these options.
Functions
The built-in layout of a name, by spelling, or nil.
The built-in layouts, which every registry holds.
The callbacks a layout exports, each {name, arity}.
The layout a surface has when it names none, the grid.
The cells' places judged by a layout, and its placement faults: every fault by path from
the surface, [:cells, name, :place | path] for a place and the layout's own for the
placement. Each place is checked whether or not another fails.
The cells' places judged by a layout's place/1 alone, which needs no options: the
cells whose places are well formed, and every other's faults by path from the surface.
A surface's layout split into its name, spelled, and its options as given:
{:ok, {name, options}}, or {:error, faults} at [:layout] for a value that is
neither a name nor {name, options}.
Types
Callbacks
A cell's classes, the only way it is placed.
The classes of the element holding the cells, which the layout's stylesheet styles.
@callback faults(cells(), options :: term()) :: [Macaw.Base.Fault.t()]
The placement faults of the cells, by path from the surface, all at once.
@callback name() :: String.t()
The layout's name, as a surface spells it ("grid").
@callback options(given :: keyword() | map()) :: {:ok, term()} | {:error, [Macaw.Base.Fault.t(), ...]}
The layout's options, checked: {:ok, options} or the faults, by path from the options.
A layout taking no options answers {:ok, %{}} for none given.
The cells' names in reading order, which is the visual order and the DOM's.
@callback place(given :: term()) :: {:ok, term()} | {:error, [Macaw.Base.Fault.t(), ...]}
A cell's place under this layout, checked: {:ok, place} or the faults, by path from
the place. nil is a cell with no place. It judges the place's shape alone, never by
the options, so a place is judged even when the options fail (#236); a rule that needs
the options (the grid's bounds) is faults/2's.
@callback size( place :: term(), options :: term(), width :: number(), row_height :: number() ) :: {number(), number()}
A cell's declared size in CSS pixels, {width, height}, from the surface's width and
row height: what its component lays out at before any measurement.
The layout's static stylesheet for these options.
Functions
The built-in layout of a name, by spelling, or nil.
@spec builtins() :: [module(), ...]
The built-in layouts, which every registry holds.
@spec callbacks() :: keyword(non_neg_integer())
The callbacks a layout exports, each {name, arity}.
@spec default() :: module()
The layout a surface has when it names none, the grid.
@spec judge(module(), term(), cells()) :: [Macaw.Base.Fault.t()]
The cells' places judged by a layout, and its placement faults: every fault by path from
the surface, [:cells, name, :place | path] for a place and the layout's own for the
placement. Each place is checked whether or not another fails.
@spec places(module(), cells()) :: {cells(), [Macaw.Base.Fault.t()]}
The cells' places judged by a layout's place/1 alone, which needs no options: the
cells whose places are well formed, and every other's faults by path from the surface.
@spec split(term()) :: {:ok, {String.t(), map()}} | {:error, [Macaw.Base.Fault.t(), ...]}
A surface's layout split into its name, spelled, and its options as given:
{:ok, {name, options}}, or {:error, faults} at [:layout] for a value that is
neither a name nor {name, options}.
iex> Macaw.Layout.split(:grid)
{:ok, {"grid", %{}}}
iex> Macaw.Layout.split({"grid", columns: 24})
{:ok, {"grid", %{columns: 24}}}