Plushie.Type.Font (Plushie v0.6.0)

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

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

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.