Plushie.Type.Font (Plushie v0.7.1)

Copy Markdown View Source

Font specification with family, weight, style, and stretch.

Maps to iced's Font struct. Accepts :default, :monospace, a family name string, or a %Font{} struct with detailed font properties.

Summary

Functions

Validates a font value.

Encodes a font value to the wire format.

Constructs a font from a keyword list.

Types

stretch()

@type stretch() ::
  :ultra_expanded
  | :extra_expanded
  | :expanded
  | :semi_expanded
  | :normal
  | :semi_condensed
  | :condensed
  | :extra_condensed
  | :ultra_condensed

style()

@type style() :: :oblique | :italic | :normal

t()

@type t() ::
  :default
  | :monospace
  | String.t()
  | %Plushie.Type.Font{
      family: String.t() | nil,
      stretch: stretch() | nil,
      style: style() | nil,
      weight: weight() | nil
    }

weight()

@type weight() ::
  :black
  | :extra_bold
  | :bold
  | :semi_bold
  | :medium
  | :normal
  | :light
  | :extra_light
  | :thin

Functions

cast(name)

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

Validates a font value.

Accepts :default, :monospace, a family name string, or a %Font{} struct.

Examples

iex> Plushie.Type.Font.cast(:default)
{:ok, :default}

iex> Plushie.Type.Font.cast(:monospace)
{:ok, :monospace}

iex> Plushie.Type.Font.cast("Fira Code")
{:ok, "Fira Code"}

iex> Plushie.Type.Font.cast(%Plushie.Type.Font{family: "Inter"})
{:ok, %Plushie.Type.Font{family: "Inter"}}

iex> Plushie.Type.Font.cast(42)
:error

encode(name)

@spec encode(font :: t()) :: String.t() | map()

Encodes a font value to the wire format.

Examples

iex> Plushie.Type.Font.encode(:default)
"default"

iex> Plushie.Type.Font.encode(:monospace)
"monospace"

iex> Plushie.Type.Font.encode("Fira Code")
%{family: "Fira Code"}

iex> Plushie.Type.Font.encode(%{family: "Inter", weight: :bold, style: :italic})
%{family: "Inter", weight: "bold", style: "italic"}

from_opts(opts)

@spec from_opts(Keyword.t()) :: %Plushie.Type.Font{
  family: term(),
  stretch: term(),
  style: term(),
  weight: term()
}

Constructs a font from a keyword list.

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