# `Macaw.Layout`
[🔗](https://github.com/dcoai/macaw/blob/v0.6.0/lib/macaw/layout.ex#L1)

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.

# `cells`

```elixir
@type cells() :: %{required(String.t()) =&gt; %{place: term()}}
```

A cell as a layout reads it: anything with a `place`.

# `spec`

```elixir
@type spec() :: atom() | String.t() | {atom() | String.t(), keyword() | map()}
```

A layout as a surface names it: its name, or its name and options.

# `classes`

```elixir
@callback classes(place :: term(), options :: term()) :: String.t()
```

A cell's classes, the only way it is placed.

# `container`

```elixir
@callback container(options :: term()) :: String.t()
```

The classes of the element holding the cells, which the layout's stylesheet styles.

# `faults`

```elixir
@callback faults(cells(), options :: term()) :: [Macaw.Base.Fault.t()]
```

The placement faults of the cells, by path from the surface, all at once.

# `name`

```elixir
@callback name() :: String.t()
```

The layout's name, as a surface spells it (`"grid"`).

# `options`

```elixir
@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.

# `order`

```elixir
@callback order(cells(), options :: term()) :: [String.t()]
```

The cells' names in reading order, which is the visual order and the DOM's.

# `place`

```elixir
@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.

# `size`

```elixir
@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.

# `stylesheet`

```elixir
@callback stylesheet(options :: term()) :: String.t()
```

The layout's static stylesheet for these options.

# `builtin`

```elixir
@spec builtin(term()) :: module() | nil
```

The built-in layout of a name, by spelling, or `nil`.

# `builtins`

```elixir
@spec builtins() :: [module(), ...]
```

The built-in layouts, which every registry holds.

# `callbacks`

```elixir
@spec callbacks() :: keyword(non_neg_integer())
```

The callbacks a layout exports, each `{name, arity}`.

# `default`

```elixir
@spec default() :: module()
```

The layout a surface has when it names none, the grid.

# `judge`

```elixir
@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.

# `places`

```elixir
@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.

# `split`

```elixir
@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}}}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
