Plushie.Type.StyleMap (Plushie v0.6.0)

Copy Markdown View Source

Per-instance widget styling that crosses the IPC boundary as a plain map.

A StyleMap lets you override visual properties (background, text color, border, shadow) on individual widget instances without defining a named style. Status overrides (hovered, pressed, disabled, focused) apply partial style changes for those interaction states.

The background field accepts either a solid color (hex string or named atom) or a Plushie.Type.Gradient for gradient fills.

Wire format

%{
  background: "#ff0000",
  text_color: "#ffffff",
  border: %{color: "#000000", width: 1, radius: 4},
  hovered: %{background: "#cc0000"},
  pressed: %{background: "#990000"}
}

Example

style = Plushie.Type.StyleMap.new()
        |> Plushie.Type.StyleMap.background("#3366ff")
        |> Plushie.Type.StyleMap.text_color(:white)
        |> Plushie.Type.StyleMap.hovered(%{background: "#5588ff"})

Button.new("btn", "Click me", style: style)

Gradient backgrounds work the same way:

gradient = Plushie.Type.Gradient.linear(90, [{0.0, "#ff0000"}, {1.0, "#0000ff"}])

style = Plushie.Type.StyleMap.new()
        |> Plushie.Type.StyleMap.background(gradient)

Container.new("ctr", [], style: style)

Summary

Types

Partial style override for an interaction state.

t()

Functions

Sets the background. Accepts a color (any form Color.cast/1 supports) or a Gradient.

Sets the base preset to extend from instead of starting from the widget default.

Sets the border specification.

Sets the disabled status override. Accepts a map or keyword list.

Sets the focused status override. Accepts a map or keyword list.

Constructs a StyleMap from a keyword list.

Sets the hovered status override. Accepts a map or keyword list.

Creates an empty style map.

Sets the pressed status override. Accepts a map or keyword list.

Sets the shadow specification.

Sets the text color. Accepts a hex string or named color atom.

Types

status_override()

@type status_override() :: %{
  optional(:background) => Plushie.Type.Color.t() | Plushie.Type.Gradient.t(),
  optional(:text_color) => Plushie.Type.Color.t(),
  optional(:border) => Plushie.Type.Border.t(),
  optional(:shadow) => Plushie.Type.Shadow.t()
}

Partial style override for an interaction state.

t()

@type t() :: %Plushie.Type.StyleMap{
  background: Plushie.Type.Color.t() | Plushie.Type.Gradient.t() | nil,
  base: atom() | nil,
  border: Plushie.Type.Border.t() | nil,
  disabled: status_override() | nil,
  focused: status_override() | nil,
  hovered: status_override() | nil,
  pressed: status_override() | nil,
  shadow: Plushie.Type.Shadow.t() | nil,
  text_color: Plushie.Type.Color.t() | nil
}

Functions

background(style_map, gradient)

@spec background(
  style_map :: t(),
  background :: Plushie.Type.Color.input() | Plushie.Type.Gradient.t()
) ::
  t()

Sets the background. Accepts a color (any form Color.cast/1 supports) or a Gradient.

base(style_map, preset)

@spec base(style_map :: t(), preset :: atom()) :: t()

Sets the base preset to extend from instead of starting from the widget default.

border(style_map, border)

@spec border(style_map :: t(), border :: Plushie.Type.Border.t()) :: t()

Sets the border specification.

disabled(style_map, disabled)

@spec disabled(style_map :: t(), disabled :: status_override() | keyword()) :: t()

Sets the disabled status override. Accepts a map or keyword list.

focused(style_map, focused)

@spec focused(style_map :: t(), focused :: status_override() | keyword()) :: t()

Sets the focused status override. Accepts a map or keyword list.

from_opts(opts)

@spec from_opts(opts :: keyword()) :: t()

Constructs a StyleMap from a keyword list.

hovered(style_map, hovered)

@spec hovered(style_map :: t(), hovered :: status_override() | keyword()) :: t()

Sets the hovered status override. Accepts a map or keyword list.

new()

@spec new() :: t()

Creates an empty style map.

pressed(style_map, pressed)

@spec pressed(style_map :: t(), pressed :: status_override() | keyword()) :: t()

Sets the pressed status override. Accepts a map or keyword list.

shadow(style_map, shadow)

@spec shadow(style_map :: t(), shadow :: Plushie.Type.Shadow.t()) :: t()

Sets the shadow specification.

text_color(style_map, text_color)

@spec text_color(style_map :: t(), text_color :: Plushie.Type.Color.input()) :: t()

Sets the text color. Accepts a hex string or named color atom.