Plushie.Type.LineHeight (Plushie v0.7.2)

Copy Markdown View Source

Line height for text widgets.

Accepts three forms:

  • A number (relative multiplier, e.g. 1.5)
  • %{relative: n} for explicit relative line height
  • %{absolute: n} for absolute pixel line height

Numbers are passed through as-is (the renderer interprets plain numbers as relative multipliers). Maps are passed through unchanged so the renderer can distinguish the two explicit forms.

Examples

iex> Plushie.Type.LineHeight.cast(1.5)
{:ok, 1.5}

iex> Plushie.Type.LineHeight.cast(%{relative: 1.5})
{:ok, %{relative: 1.5}}

iex> Plushie.Type.LineHeight.cast(%{absolute: 20})
{:ok, %{absolute: 20}}

iex> Plushie.Type.LineHeight.cast(:bogus)
:error

Summary

Functions

Validates a line height value.

Encodes a line height for the wire format.

Types

t()

@type t() :: number() | %{relative: number()} | %{absolute: number()}

Functions

cast(n)

@spec cast(term()) :: {:ok, t()} | :error

Validates a line height value.

Examples

iex> Plushie.Type.LineHeight.cast(1.0)
{:ok, 1.0}

iex> Plushie.Type.LineHeight.cast(2)
{:ok, 2}

iex> Plushie.Type.LineHeight.cast(%{relative: 1.2})
{:ok, %{relative: 1.2}}

iex> Plushie.Type.LineHeight.cast(%{absolute: 24})
{:ok, %{absolute: 24}}

iex> Plushie.Type.LineHeight.cast("bad")
:error

encode(n)

@spec encode(line_height :: t()) :: t()

Encodes a line height for the wire format.

Numbers and maps pass through unchanged.

Examples

iex> Plushie.Type.LineHeight.encode(1.5)
1.5

iex> Plushie.Type.LineHeight.encode(%{relative: 1.2})
%{relative: 1.2}

iex> Plushie.Type.LineHeight.encode(%{absolute: 20})
%{absolute: 20}