Plushie.Type.Length (Plushie v0.7.0)

Copy Markdown View Source

Size value for the width and height props on most widgets.

Maps to iced's Length enum. Accepts :fill, :shrink, {:fill_portion, n}, or a numeric pixel value.

Summary

Functions

Validates a length value.

Encodes a length value to the wire format expected by the renderer.

Types

t()

@type t() :: :fill | :shrink | {:fill_portion, pos_integer()} | number()

Functions

cast(n)

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

Validates a length value.

Examples

iex> Plushie.Type.Length.cast(:fill)
{:ok, :fill}

iex> Plushie.Type.Length.cast(:shrink)
{:ok, :shrink}

iex> Plushie.Type.Length.cast({:fill_portion, 3})
{:ok, {:fill_portion, 3}}

iex> Plushie.Type.Length.cast(200)
{:ok, 200}

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

encode(n)

@spec encode(length :: t()) :: String.t() | number() | map()

Encodes a length value to the wire format expected by the renderer.

Examples

iex> Plushie.Type.Length.encode(:fill)
"fill"

iex> Plushie.Type.Length.encode(:shrink)
"shrink"

iex> Plushie.Type.Length.encode({:fill_portion, 3})
%{fill_portion: 3}

iex> Plushie.Type.Length.encode(200)
200