# `Toddy.Iced.StyleMap`
[🔗](https://github.com/toddy-ui/toddy-elixir/blob/v0.3.0/lib/toddy/iced/style_map.ex#L1)

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 `Toddy.Iced.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 = Toddy.Iced.StyleMap.new()
            |> Toddy.Iced.StyleMap.background("#3366ff")
            |> Toddy.Iced.StyleMap.text_color(:white)
            |> Toddy.Iced.StyleMap.hovered(%{background: "#5588ff"})

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

Gradient backgrounds work the same way:

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

    style = Toddy.Iced.StyleMap.new()
            |> Toddy.Iced.StyleMap.background(gradient)

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

# `status_override`

```elixir
@type status_override() :: %{
  optional(:background) =&gt; Toddy.Iced.Color.t() | Toddy.Iced.Gradient.t(),
  optional(:text_color) =&gt; Toddy.Iced.Color.t(),
  optional(:border) =&gt; Toddy.Iced.Border.t(),
  optional(:shadow) =&gt; Toddy.Iced.Shadow.t()
}
```

Partial style override for an interaction state.

# `t`

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

# `background`

```elixir
@spec background(
  style_map :: t(),
  background :: Toddy.Iced.Color.input() | Toddy.Iced.Gradient.t()
) ::
  t()
```

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

# `base`

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

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

# `border`

```elixir
@spec border(style_map :: t(), border :: Toddy.Iced.Border.t()) :: t()
```

Sets the border specification.

# `disabled`

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

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

# `focused`

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

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

# `hovered`

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

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

# `new`

```elixir
@spec new() :: t()
```

Creates an empty style map.

# `pressed`

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

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

# `shadow`

```elixir
@spec shadow(style_map :: t(), shadow :: Toddy.Iced.Shadow.t()) :: t()
```

Sets the shadow specification.

# `text_color`

```elixir
@spec text_color(style_map :: t(), text_color :: Toddy.Iced.Color.input()) :: t()
```

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
