# `Macaw.Layers.Text.Metrics`
[🔗](https://github.com/dcoai/macaw_layers/blob/v0.6.0/lib/macaw/layers/text/metrics.ex#L1)

The text-measurement seam (spec/05): how wide a text is at a font and a size, and the
lines it wraps to within a width. Every layer above macaw_layers that lays text out (a
box's size, a legend's wrapping, a label's fit, a margin, a table's column) measures
through it, so one measurer decides where every text goes.

    defmodule MyApp.Mono do
      @behaviour Macaw.Layers.Text.Metrics
      def width(text, _font, size), do: 0.5 * size * String.length(text)
      def lines(text, _font, _size, _max_width), do: String.split(text, "\n")
    end

    Macaw.Layers.Text.width("Wednesday", "monospace", 11, metrics: MyApp.Mono)

A measurer is passed in, never configured: a library reads no application environment
(macaw_compose spec/00 §4.4, rule 3). `Macaw.Layers.Text` takes one as `metrics:` and
defaults to `Macaw.Layers.Text.Estimate`, the estimate of 0.6 em per grapheme. A font
library implements this behavior to measure glyphs, and nothing above the seam changes.

`Macaw.Layers.Text` calls a measurer with arguments it has judged: `text` a string,
`font` a CSS font-family string (a theme's `font_family`, `Macaw.Layers.Text.font/2`),
`size` and `max_width` numbers in pixels. A measurer answers its value bare; one that
raises is the adopter's, and nothing catches it (spec/00 §3).

# `font`

```elixir
@type font() :: String.t()
```

A CSS font-family string: the font measured.

# `lines`

```elixir
@callback lines(text :: String.t(), font(), size :: number(), max_width :: number()) :: [
  String.t()
]
```

The lines `text` wraps to set in `font` at `size` pixels within `max_width` pixels,
broken at word boundaries, in order.

# `width`

```elixir
@callback width(text :: String.t(), font(), size :: number()) :: number()
```

The width of `text` set in `font` at `size` pixels, in pixels.

---

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