Plushie.Type.Padding (Plushie v0.7.2)

Copy Markdown View Source

Padding specification with per-side values.

Maps to iced's Padding struct. Accepts a uniform number, a {vertical, horizontal} tuple, an explicit four-side map, or a %Padding{} struct with per-side overrides.

cast/1 always normalises to the full four-side map.

Struct form

The struct supports per-side padding via keyword construction:

Padding.from_opts(top: 4, bottom: 8)

nil fields are stripped during encoding.

Summary

Functions

Validates a padding value, returning it in its canonical stored form.

Constructs padding from a keyword list.

Types

t()

@type t() ::
  number()
  | {number(), number()}
  | %Plushie.Type.Padding{
      bottom: number() | nil,
      left: number() | nil,
      right: number() | nil,
      top: number() | nil
    }

Functions

cast(n)

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

Validates a padding value, returning it in its canonical stored form.

Numbers and tuples are validated and returned as-is (expansion to the four-side map happens during encoding). Structs and maps are validated and returned as four-side maps.

Examples

iex> Plushie.Type.Padding.cast(8)
{:ok, 8}

iex> Plushie.Type.Padding.cast({4, 12})
{:ok, {4, 12}}

iex> Plushie.Type.Padding.cast(%{top: 1, right: 2, bottom: 3, left: 4})
{:ok, %{top: 1, right: 2, bottom: 3, left: 4}}

from_opts(opts)

@spec from_opts(Keyword.t()) :: %Plushie.Type.Padding{
  bottom: term(),
  left: term(),
  right: term(),
  top: term()
}

Constructs padding from a keyword list.

Raises ArgumentError if any key is not a valid padding field.