# `Plushie.Widget.Canvas`
[🔗](https://github.com/plushie-ui/plushie-elixir/blob/v0.7.2/lib/plushie/widget/canvas.ex#L1)

Canvas for drawing shapes, organized into named layers.

Canvas is a container widget. Its children are `Plushie.Canvas.Layer`
elements, each holding shape children. Each layer maps to an iced
`Cache` on the Rust side; only changed layers are re-tessellated.

## Props

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `width` | `:fill \| :shrink \| {:fill_portion, pos_integer()} \| number()` | `nil` | Canvas width. Default: fill. |
| `height` | `:fill \| :shrink \| {:fill_portion, pos_integer()} \| number()` | `nil` | Canvas height. Default: 200px. |
| `background` | `String.t()` | `nil` | Canvas background color. |
| `interactive` | `boolean()` | `nil` | Enable all mouse event handlers. Default: false. |
| `on_press` | `boolean()` | `nil` | Enable mouse press events. Default: false. |
| `on_release` | `boolean()` | `nil` | Enable mouse release events. Default: false. |
| `on_move` | `boolean()` | `nil` | Enable mouse move events. Default: false. |
| `on_scroll` | `boolean()` | `nil` | Enable mouse scroll events. Default: false. |
| `alt` | `String.t() \| atom()` | `nil` | Accessible label for the canvas. |
| `description` | `String.t() \| atom()` | `nil` | Extended accessible description. |
| `role` | `String.t() \| atom()` | `nil` | Accessible role (e.g. "radiogroup", "toolbar"). |
| `arrow_mode` | `:wrap \| :clamp \| :linear \| :none` | `nil` | Arrow key navigation mode: `:wrap`, `:clamp`, `:linear`, `:none`. |
| `event_rate` | `integer()` | `nil` | Max events per second for coalescable events. |
| `a11y` | `%Plushie.Type.A11y{} \| map() \| keyword()` | `%{role: :canvas}` | Accessibility annotations. |

# `option`

```elixir
@type option() ::
  (((((((((((({:width,
               :fill | :shrink | {:fill_portion, pos_integer()} | number()}
              | {:height,
                 :fill | :shrink | {:fill_portion, pos_integer()} | number()})
             | {:background, atom() | String.t() | map()})
            | {:interactive, boolean()})
           | {:on_press, boolean()})
          | {:on_release, boolean()})
         | {:on_move, boolean()})
        | {:on_scroll, boolean()})
       | {:alt, String.t() | atom()})
      | {:description, String.t() | atom()})
     | {:role, String.t() | atom()})
    | {:arrow_mode, :wrap | :clamp | :linear | :none})
   | {:event_rate, integer()})
  | {:a11y,
     %Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword()}
```

# `t`

```elixir
@type t() :: %Plushie.Widget.Canvas{
  a11y:
    (%Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  alt:
    (String.t() | atom())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  arrow_mode:
    (:wrap | :clamp | :linear | :none)
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  background:
    String.t()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  children: [Plushie.Widget.ui_node()],
  description:
    (String.t() | atom())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  event_rate:
    integer()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  height:
    (:fill | :shrink | {:fill_portion, pos_integer()} | number())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  id: String.t(),
  interactive:
    boolean()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  on_move:
    boolean()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  on_press:
    boolean()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  on_release:
    boolean()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  on_scroll:
    boolean()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  role:
    (String.t() | atom())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  width:
    (:fill | :shrink | {:fill_portion, pos_integer()} | number())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil
}
```

# `a11y`

```elixir
@spec a11y(
  widget :: t(),
  value ::
    (%Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword())
    | nil
) :: t()
```

Accessibility annotations.

Accepts `%Plushie.Type.A11y{} | map() | keyword()`.

# `alt`

```elixir
@spec alt(widget :: t(), value :: (String.t() | atom()) | nil) :: t()
```

Accessible label for the canvas.

Accepts `String.t() | atom()`.

# `arrow_mode`

```elixir
@spec arrow_mode(widget :: t(), value :: (:wrap | :clamp | :linear | :none) | nil) ::
  t()
```

Arrow key navigation mode: `:wrap`, `:clamp`, `:linear`, `:none`.

Accepts `:wrap | :clamp | :linear | :none`.

# `background`

```elixir
@spec background(widget :: t(), value :: (atom() | String.t() | map()) | nil) :: t()
```

Canvas background color.

Accepts `String.t()`.

# `build`

```elixir
@spec build(widget :: t()) :: Plushie.Widget.ui_node()
```

Converts this widget struct to a `ui_node()` map.

# `canvas`
*macro* 

Creates a `:canvas` widget.

Shorthand for `new/2`. Import this macro to use the widget name
directly in view functions:

    import Plushie.Widget.Canvas, only: [canvas: 2]

    canvas("my-id", prop: value)

# `description`

```elixir
@spec description(widget :: t(), value :: (String.t() | atom()) | nil) :: t()
```

Extended accessible description.

Accepts `String.t() | atom()`.

# `event_rate`

```elixir
@spec event_rate(widget :: t(), value :: integer() | nil) :: t()
```

Max events per second for coalescable events.

Accepts `integer()`.

# `extend`

```elixir
@spec extend(widget :: t(), children :: [Plushie.Widget.child()]) :: t()
```

Appends multiple children to the widget.

# `height`

```elixir
@spec height(
  widget :: t(),
  value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
) :: t()
```

Canvas height. Default: 200px.

Accepts `:fill | :shrink | {:fill_portion, pos_integer()} | number()`.

# `interactive`

```elixir
@spec interactive(widget :: t(), value :: boolean() | nil) :: t()
```

Enable all mouse event handlers. Default: false.

Accepts `boolean()`.

# `new`

```elixir
@spec new(id :: String.t(), opts :: [option()]) :: t()
```

Creates a new widget struct with the given ID and keyword options.

# `on_move`

```elixir
@spec on_move(widget :: t(), value :: boolean() | nil) :: t()
```

Enable mouse move events. Default: false.

Accepts `boolean()`.

# `on_press`

```elixir
@spec on_press(widget :: t(), value :: boolean() | nil) :: t()
```

Enable mouse press events. Default: false.

Accepts `boolean()`.

# `on_release`

```elixir
@spec on_release(widget :: t(), value :: boolean() | nil) :: t()
```

Enable mouse release events. Default: false.

Accepts `boolean()`.

# `on_scroll`

```elixir
@spec on_scroll(widget :: t(), value :: boolean() | nil) :: t()
```

Enable mouse scroll events. Default: false.

Accepts `boolean()`.

# `push`

```elixir
@spec push(widget :: t(), child :: Plushie.Widget.child()) :: t()
```

Appends a child to the widget.

# `role`

```elixir
@spec role(widget :: t(), value :: (String.t() | atom()) | nil) :: t()
```

Accessible role (e.g. "radiogroup", "toolbar").

Accepts `String.t() | atom()`.

# `width`

```elixir
@spec width(
  widget :: t(),
  value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
) ::
  t()
```

Canvas width. Default: fill.

Accepts `:fill | :shrink | {:fill_portion, pos_integer()} | number()`.

# `with_options`

```elixir
@spec with_options(widget :: t(), opts :: [option()]) :: t()
```

Applies keyword options to an existing widget struct.

---

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