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
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
@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.
@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
@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.
Sets the base preset to extend from instead of starting from the widget default.
@spec border(style_map :: t(), border :: Plushie.Type.Border.t()) :: t()
Sets the border specification.
@spec disabled(style_map :: t(), disabled :: status_override() | keyword()) :: t()
Sets the disabled status override. Accepts a map or keyword list.
@spec focused(style_map :: t(), focused :: status_override() | keyword()) :: t()
Sets the focused status override. Accepts a map or keyword list.
Constructs a StyleMap from a keyword list.
@spec hovered(style_map :: t(), hovered :: status_override() | keyword()) :: t()
Sets the hovered status override. Accepts a map or keyword list.
@spec new() :: t()
Creates an empty style map.
@spec pressed(style_map :: t(), pressed :: status_override() | keyword()) :: t()
Sets the pressed status override. Accepts a map or keyword list.
@spec shadow(style_map :: t(), shadow :: Plushie.Type.Shadow.t()) :: t()
Sets the shadow specification.
@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.