Search documentation of Plushie

# Plushie.Widget.Canvas (Plushie v0.7.2)

Copy Markdown View Source

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.

## Summary

### Types

option()
t()

### Functions

a11y(widget, descriptor)

Accessibility annotations.

alt(widget, descriptor)

Accessible label for the canvas.

arrow_mode(widget, descriptor)

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

background(widget, descriptor)

Canvas background color.

build(widget)

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

canvas(id, opts \\ [])

Creates a `:canvas` widget.

description(widget, descriptor)

Extended accessible description.

event_rate(widget, descriptor)

Max events per second for coalescable events.

extend(widget, children)

Appends multiple children to the widget.

height(widget, descriptor)

Canvas height. Default: 200px.

interactive(widget, descriptor)

Enable all mouse event handlers. Default: false.

new(id, opts \\ [])

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

on_move(widget, descriptor)

Enable mouse move events. Default: false.

on_press(widget, descriptor)

Enable mouse press events. Default: false.

on_release(widget, descriptor)

Enable mouse release events. Default: false.

on_scroll(widget, descriptor)

Enable mouse scroll events. Default: false.

push(widget, child)

Appends a child to the widget.

role(widget, descriptor)

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

width(widget, descriptor)

Canvas width. Default: fill.

with_options(widget, opts)

Applies keyword options to an existing widget struct.

## Types

# option()

    @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()

    @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
    }

## Functions

# a11y(widget, descriptor)

    @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(widget, descriptor)

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

Accessible label for the canvas.

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

# arrow_mode(widget, descriptor)

    @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(widget, descriptor)

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

Canvas background color.

Accepts `String.t()`.

# build(widget)

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

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

# canvas(id, opts \\ [])

(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(widget, descriptor)

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

Extended accessible description.

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

# event_rate(widget, descriptor)

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

Max events per second for coalescable events.

Accepts `integer()`.

# extend(widget, children)

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

Appends multiple children to the widget.

# height(widget, descriptor)

    @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(widget, descriptor)

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

Enable all mouse event handlers. Default: false.

Accepts `boolean()`.

# new(id, opts \\ [])

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

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

# on_move(widget, descriptor)

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

Enable mouse move events. Default: false.

Accepts `boolean()`.

# on_press(widget, descriptor)

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

Enable mouse press events. Default: false.

Accepts `boolean()`.

# on_release(widget, descriptor)

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

Enable mouse release events. Default: false.

Accepts `boolean()`.

# on_scroll(widget, descriptor)

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

Enable mouse scroll events. Default: false.

Accepts `boolean()`.

# push(widget, child)

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

Appends a child to the widget.

# role(widget, descriptor)

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

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

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

# width(widget, descriptor)

    @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(widget, opts)

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

Applies keyword options to an existing widget struct.