Search documentation of Plushie

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

Copy Markdown View Source

Pointer area, captures mouse events on child content.

Wraps child content and emits click events for various mouse buttons, hover enter/exit, cursor movement, scroll, and double-click events. Optionally sets the mouse cursor when hovering the area.

## Props

Name | Type | Default | Description
--- | --- | --- | ---
`cursor` | `atom()` | `nil` | Mouse cursor to show on hover (e.g. `:pointer`, `:grab`).
`on_press` | `String.t() | atom()` | `nil` | Event tag for left mouse press events.
`on_release` | `String.t() | atom()` | `nil` | Event tag for left mouse release events.
`on_right_press` | `boolean()` | `nil` | Enable right mouse press events.
`on_right_release` | `boolean()` | `nil` | Enable right mouse release events.
`on_middle_press` | `boolean()` | `nil` | Enable middle mouse press events.
`on_middle_release` | `boolean()` | `nil` | Enable middle mouse release events.
`on_double_click` | `boolean()` | `nil` | Enable double-click events.
`on_enter` | `boolean()` | `nil` | Enable cursor enter events.
`on_exit` | `boolean()` | `nil` | Enable cursor exit events.
`on_move` | `boolean()` | `nil` | Enable cursor move events.
`on_scroll` | `boolean()` | `nil` | Enable scroll wheel events.
`event_rate` | `integer()` | `nil` | Max events per second for coalescable events.
`a11y` | `%Plushie.Type.A11y{} | map() | keyword()` | `nil` | Accessibility annotations.

## Summary

### Types

option()
t()

### Functions

a11y(widget, descriptor)

Accessibility annotations.

build(widget)

Converts this widget struct to a `ui_node()` map. Validates at most one child.

cursor(widget, descriptor)

Mouse cursor to show on hover (e.g. `:pointer`, `:grab`).

event_rate(widget, descriptor)

Max events per second for coalescable events.

extend(widget, children)

Appends multiple children to the widget.

new(id, opts \\ [])

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

on_double_click(widget, descriptor)

Enable double-click events.

on_enter(widget, descriptor)

Enable cursor enter events.

on_exit(widget, descriptor)

Enable cursor exit events.

on_middle_press(widget, descriptor)

Enable middle mouse press events.

on_middle_release(widget, descriptor)

Enable middle mouse release events.

on_move(widget, descriptor)

Enable cursor move events.

on_press(widget, descriptor)

Event tag for left mouse press events.

on_release(widget, descriptor)

Event tag for left mouse release events.

on_right_press(widget, descriptor)

Enable right mouse press events.

on_right_release(widget, descriptor)

Enable right mouse release events.

on_scroll(widget, descriptor)

Enable scroll wheel events.

pointer_area(id, opts \\ [])

Creates a `:pointer_area` widget.

push(widget, child)

Appends a child to the widget.

with_options(widget, opts)

Applies keyword options to an existing widget struct.

## Types

# option()

    @type option() ::
      (((((((((((({:cursor, atom()} | {:on_press, String.t() | atom()})
                 | {:on_release, String.t() | atom()})
                | {:on_right_press, boolean()})
               | {:on_right_release, boolean()})
              | {:on_middle_press, boolean()})
             | {:on_middle_release, boolean()})
            | {:on_double_click, boolean()})
           | {:on_enter, boolean()})
          | {:on_exit, boolean()})
         | {:on_move, boolean()})
        | {:on_scroll, boolean()})
       | {: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.PointerArea{
      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,
      children: [Plushie.Widget.ui_node()],
      cursor:
        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,
      id: String.t(),
      on_double_click:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_enter:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_exit:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_middle_press:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_middle_release:
        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:
        (String.t() | atom())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_release:
        (String.t() | atom())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_right_press:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_right_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
    }

## 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()`.

# build(widget)

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

Converts this widget struct to a `ui_node()` map. Validates at most one child.

# cursor(widget, descriptor)

    @spec cursor(widget :: t(), value :: atom() | nil) :: t()

Mouse cursor to show on hover (e.g. `:pointer`, `:grab`).

Accepts `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.

# new(id, opts \\ [])

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

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

# on_double_click(widget, descriptor)

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

Enable double-click events.

Accepts `boolean()`.

# on_enter(widget, descriptor)

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

Enable cursor enter events.

Accepts `boolean()`.

# on_exit(widget, descriptor)

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

Enable cursor exit events.

Accepts `boolean()`.

# on_middle_press(widget, descriptor)

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

Enable middle mouse press events.

Accepts `boolean()`.

# on_middle_release(widget, descriptor)

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

Enable middle mouse release events.

Accepts `boolean()`.

# on_move(widget, descriptor)

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

Enable cursor move events.

Accepts `boolean()`.

# on_press(widget, descriptor)

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

Event tag for left mouse press events.

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

# on_release(widget, descriptor)

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

Event tag for left mouse release events.

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

# on_right_press(widget, descriptor)

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

Enable right mouse press events.

Accepts `boolean()`.

# on_right_release(widget, descriptor)

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

Enable right mouse release events.

Accepts `boolean()`.

# on_scroll(widget, descriptor)

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

Enable scroll wheel events.

Accepts `boolean()`.

# pointer_area(id, opts \\ [])

(macro)

Creates a `:pointer_area` widget.

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

    import Plushie.Widget.PointerArea, only: [pointer_area: 2]

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

# push(widget, child)

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

Appends a child to the widget.

# with_options(widget, opts)

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

Applies keyword options to an existing widget struct.