Class: Plushie::Event::Widget

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/event.rb

Overview

All widget interaction events.

Covers standard widget events (:click, :input, :submit, etc.), unified pointer events (:press, :release, :move, :scroll, :enter, :exit, :double_click, :resize), generic element events (:focused, :blurred, :drag, :drag_end, :key_press, :key_release), pane events (:pane_resized, :pane_dragged, :pane_clicked), animation events (:transition_complete), and subscription pointer events.

The +value+ field carries the event payload. For single-value events (input text, slider position, toggle state) it holds the scalar. For multi-field events (pointer coordinates, pane operations, key data) it holds a symbol-keyed Hash.

No-payload events (click, open, close) always have +value: nil+. Pattern-match without binding +value+ for these:

in Event::Widget[type: :click, id: "save"]

The +scope+ array lists ancestor container IDs from immediate parent to outermost. The window_id is appended as the last element (outermost ancestor). Use Event.target to reconstruct the forward-order path (window_id is stripped).

Examples:

Click

in Event::Widget[type: :click, id: "save"]

Input with value

in Event::Widget[type: :input, id: "search", value:]

Pointer press

in Event::Widget[type: :press, id: "canvas", value: {x:, y:, button: :left}]

Enter (cursor hover or touch enter)

in Event::Widget[type: :enter, id: "hover_zone"]

Resize (sensor)

in Event::Widget[type: :resize, id: "content", value: {width:, height:}]

Pane resized

in Event::Widget[type: :pane_resized, id: "editor", value: {ratio:}]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, id:, value: nil, window_id: nil, scope: []) ⇒ Widget

Returns a new instance of Widget.



63
64
65
# File 'lib/plushie/event.rb', line 63

def initialize(type:, id:, value: nil, window_id: nil, scope: [])
  super
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



62
63
64
# File 'lib/plushie/event.rb', line 62

def id
  @id
end

#id [String] widget ID that produced the event([String]) ⇒ Object (readonly)

All widget interaction events.

Covers standard widget events (:click, :input, :submit, etc.), unified pointer events (:press, :release, :move, :scroll, :enter, :exit, :double_click, :resize), generic element events (:focused, :blurred, :drag, :drag_end, :key_press, :key_release), pane events (:pane_resized, :pane_dragged, :pane_clicked), animation events (:transition_complete), and subscription pointer events.

The +value+ field carries the event payload. For single-value events (input text, slider position, toggle state) it holds the scalar. For multi-field events (pointer coordinates, pane operations, key data) it holds a symbol-keyed Hash.

No-payload events (click, open, close) always have +value: nil+. Pattern-match without binding +value+ for these:

in Event::Widget[type: :click, id: "save"]

The +scope+ array lists ancestor container IDs from immediate parent to outermost. The window_id is appended as the last element (outermost ancestor). Use Event.target to reconstruct the forward-order path (window_id is stripped).

Examples:

Click

in Event::Widget[type: :click, id: "save"]

Input with value

in Event::Widget[type: :input, id: "search", value:]

Pointer press

in Event::Widget[type: :press, id: "canvas", value: {x:, y:, button: :left}]

Enter (cursor hover or touch enter)

in Event::Widget[type: :enter, id: "hover_zone"]

Resize (sensor)

in Event::Widget[type: :resize, id: "content", value: {width:, height:}]

Pane resized

in Event::Widget[type: :pane_resized, id: "editor", value: {ratio:}]


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/plushie/event.rb', line 62

Widget = Data.define(:type, :id, :value, :window_id, :scope) do
  def initialize(type:, id:, value: nil, window_id: nil, scope: [])
    super
  end

  # Category predicates for event type families.

  # Pointer events (press, release, move, scroll, enter, exit, double_click).
  def pointer? = Specs::POINTER_TYPES.include?(type)

  # Widget-scoped keyboard events (key_press, key_release).
  def keyboard? = Specs::KEYBOARD_TYPES.include?(type)

  # Pane grid events (pane_resized, pane_dragged, pane_clicked, pane_focus_cycle).
  def pane? = Specs::PANE_TYPES.include?(type)

  # Focus lifecycle events (focused, blurred).
  def focus? = Specs::FOCUS_TYPES.include?(type)

  # Drag events (drag, drag_end).
  def drag? = Specs::DRAG_TYPES.include?(type)

  # Look up the spec for this event's type.
  # @return [Hash, nil]
  def spec = Specs.for(type)
end

#scopeObject (readonly)

Returns the value of attribute scope

Returns:

  • (Object)

    the current value of scope



62
63
64
# File 'lib/plushie/event.rb', line 62

def scope
  @scope
end

#scope [Array<String>] reversed ancestor scope chain (immediate parent first, window_id last)([Array<String>](immediate parent first, window_id last)) ⇒ Object (readonly)

All widget interaction events.

Covers standard widget events (:click, :input, :submit, etc.), unified pointer events (:press, :release, :move, :scroll, :enter, :exit, :double_click, :resize), generic element events (:focused, :blurred, :drag, :drag_end, :key_press, :key_release), pane events (:pane_resized, :pane_dragged, :pane_clicked), animation events (:transition_complete), and subscription pointer events.

The +value+ field carries the event payload. For single-value events (input text, slider position, toggle state) it holds the scalar. For multi-field events (pointer coordinates, pane operations, key data) it holds a symbol-keyed Hash.

No-payload events (click, open, close) always have +value: nil+. Pattern-match without binding +value+ for these:

in Event::Widget[type: :click, id: "save"]

The +scope+ array lists ancestor container IDs from immediate parent to outermost. The window_id is appended as the last element (outermost ancestor). Use Event.target to reconstruct the forward-order path (window_id is stripped).

Examples:

Click

in Event::Widget[type: :click, id: "save"]

Input with value

in Event::Widget[type: :input, id: "search", value:]

Pointer press

in Event::Widget[type: :press, id: "canvas", value: {x:, y:, button: :left}]

Enter (cursor hover or touch enter)

in Event::Widget[type: :enter, id: "hover_zone"]

Resize (sensor)

in Event::Widget[type: :resize, id: "content", value: {width:, height:}]

Pane resized

in Event::Widget[type: :pane_resized, id: "editor", value: {ratio:}]


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/plushie/event.rb', line 62

Widget = Data.define(:type, :id, :value, :window_id, :scope) do
  def initialize(type:, id:, value: nil, window_id: nil, scope: [])
    super
  end

  # Category predicates for event type families.

  # Pointer events (press, release, move, scroll, enter, exit, double_click).
  def pointer? = Specs::POINTER_TYPES.include?(type)

  # Widget-scoped keyboard events (key_press, key_release).
  def keyboard? = Specs::KEYBOARD_TYPES.include?(type)

  # Pane grid events (pane_resized, pane_dragged, pane_clicked, pane_focus_cycle).
  def pane? = Specs::PANE_TYPES.include?(type)

  # Focus lifecycle events (focused, blurred).
  def focus? = Specs::FOCUS_TYPES.include?(type)

  # Drag events (drag, drag_end).
  def drag? = Specs::DRAG_TYPES.include?(type)

  # Look up the spec for this event's type.
  # @return [Hash, nil]
  def spec = Specs.for(type)
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



62
63
64
# File 'lib/plushie/event.rb', line 62

def type
  @type
end

#type [Symbol] event kind([Symbol]) ⇒ Object (readonly)

All widget interaction events.

Covers standard widget events (:click, :input, :submit, etc.), unified pointer events (:press, :release, :move, :scroll, :enter, :exit, :double_click, :resize), generic element events (:focused, :blurred, :drag, :drag_end, :key_press, :key_release), pane events (:pane_resized, :pane_dragged, :pane_clicked), animation events (:transition_complete), and subscription pointer events.

The +value+ field carries the event payload. For single-value events (input text, slider position, toggle state) it holds the scalar. For multi-field events (pointer coordinates, pane operations, key data) it holds a symbol-keyed Hash.

No-payload events (click, open, close) always have +value: nil+. Pattern-match without binding +value+ for these:

in Event::Widget[type: :click, id: "save"]

The +scope+ array lists ancestor container IDs from immediate parent to outermost. The window_id is appended as the last element (outermost ancestor). Use Event.target to reconstruct the forward-order path (window_id is stripped).

Examples:

Click

in Event::Widget[type: :click, id: "save"]

Input with value

in Event::Widget[type: :input, id: "search", value:]

Pointer press

in Event::Widget[type: :press, id: "canvas", value: {x:, y:, button: :left}]

Enter (cursor hover or touch enter)

in Event::Widget[type: :enter, id: "hover_zone"]

Resize (sensor)

in Event::Widget[type: :resize, id: "content", value: {width:, height:}]

Pane resized

in Event::Widget[type: :pane_resized, id: "editor", value: {ratio:}]


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/plushie/event.rb', line 62

Widget = Data.define(:type, :id, :value, :window_id, :scope) do
  def initialize(type:, id:, value: nil, window_id: nil, scope: [])
    super
  end

  # Category predicates for event type families.

  # Pointer events (press, release, move, scroll, enter, exit, double_click).
  def pointer? = Specs::POINTER_TYPES.include?(type)

  # Widget-scoped keyboard events (key_press, key_release).
  def keyboard? = Specs::KEYBOARD_TYPES.include?(type)

  # Pane grid events (pane_resized, pane_dragged, pane_clicked, pane_focus_cycle).
  def pane? = Specs::PANE_TYPES.include?(type)

  # Focus lifecycle events (focused, blurred).
  def focus? = Specs::FOCUS_TYPES.include?(type)

  # Drag events (drag, drag_end).
  def drag? = Specs::DRAG_TYPES.include?(type)

  # Look up the spec for this event's type.
  # @return [Hash, nil]
  def spec = Specs.for(type)
end

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



62
63
64
# File 'lib/plushie/event.rb', line 62

def value
  @value
end

#value [Object, nil] event payload (scalar or symbol-keyed Hash)([Object, nil](scalar) ⇒ Object (readonly)

All widget interaction events.

Covers standard widget events (:click, :input, :submit, etc.), unified pointer events (:press, :release, :move, :scroll, :enter, :exit, :double_click, :resize), generic element events (:focused, :blurred, :drag, :drag_end, :key_press, :key_release), pane events (:pane_resized, :pane_dragged, :pane_clicked), animation events (:transition_complete), and subscription pointer events.

The +value+ field carries the event payload. For single-value events (input text, slider position, toggle state) it holds the scalar. For multi-field events (pointer coordinates, pane operations, key data) it holds a symbol-keyed Hash.

No-payload events (click, open, close) always have +value: nil+. Pattern-match without binding +value+ for these:

in Event::Widget[type: :click, id: "save"]

The +scope+ array lists ancestor container IDs from immediate parent to outermost. The window_id is appended as the last element (outermost ancestor). Use Event.target to reconstruct the forward-order path (window_id is stripped).

Examples:

Click

in Event::Widget[type: :click, id: "save"]

Input with value

in Event::Widget[type: :input, id: "search", value:]

Pointer press

in Event::Widget[type: :press, id: "canvas", value: {x:, y:, button: :left}]

Enter (cursor hover or touch enter)

in Event::Widget[type: :enter, id: "hover_zone"]

Resize (sensor)

in Event::Widget[type: :resize, id: "content", value: {width:, height:}]

Pane resized

in Event::Widget[type: :pane_resized, id: "editor", value: {ratio:}]


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/plushie/event.rb', line 62

Widget = Data.define(:type, :id, :value, :window_id, :scope) do
  def initialize(type:, id:, value: nil, window_id: nil, scope: [])
    super
  end

  # Category predicates for event type families.

  # Pointer events (press, release, move, scroll, enter, exit, double_click).
  def pointer? = Specs::POINTER_TYPES.include?(type)

  # Widget-scoped keyboard events (key_press, key_release).
  def keyboard? = Specs::KEYBOARD_TYPES.include?(type)

  # Pane grid events (pane_resized, pane_dragged, pane_clicked, pane_focus_cycle).
  def pane? = Specs::PANE_TYPES.include?(type)

  # Focus lifecycle events (focused, blurred).
  def focus? = Specs::FOCUS_TYPES.include?(type)

  # Drag events (drag, drag_end).
  def drag? = Specs::DRAG_TYPES.include?(type)

  # Look up the spec for this event's type.
  # @return [Hash, nil]
  def spec = Specs.for(type)
end

#window_idObject (readonly)

Returns the value of attribute window_id

Returns:

  • (Object)

    the current value of window_id



62
63
64
# File 'lib/plushie/event.rb', line 62

def window_id
  @window_id
end

#window_id [String, nil] window that produced the event([String, nil]) ⇒ Object (readonly)

All widget interaction events.

Covers standard widget events (:click, :input, :submit, etc.), unified pointer events (:press, :release, :move, :scroll, :enter, :exit, :double_click, :resize), generic element events (:focused, :blurred, :drag, :drag_end, :key_press, :key_release), pane events (:pane_resized, :pane_dragged, :pane_clicked), animation events (:transition_complete), and subscription pointer events.

The +value+ field carries the event payload. For single-value events (input text, slider position, toggle state) it holds the scalar. For multi-field events (pointer coordinates, pane operations, key data) it holds a symbol-keyed Hash.

No-payload events (click, open, close) always have +value: nil+. Pattern-match without binding +value+ for these:

in Event::Widget[type: :click, id: "save"]

The +scope+ array lists ancestor container IDs from immediate parent to outermost. The window_id is appended as the last element (outermost ancestor). Use Event.target to reconstruct the forward-order path (window_id is stripped).

Examples:

Click

in Event::Widget[type: :click, id: "save"]

Input with value

in Event::Widget[type: :input, id: "search", value:]

Pointer press

in Event::Widget[type: :press, id: "canvas", value: {x:, y:, button: :left}]

Enter (cursor hover or touch enter)

in Event::Widget[type: :enter, id: "hover_zone"]

Resize (sensor)

in Event::Widget[type: :resize, id: "content", value: {width:, height:}]

Pane resized

in Event::Widget[type: :pane_resized, id: "editor", value: {ratio:}]


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/plushie/event.rb', line 62

Widget = Data.define(:type, :id, :value, :window_id, :scope) do
  def initialize(type:, id:, value: nil, window_id: nil, scope: [])
    super
  end

  # Category predicates for event type families.

  # Pointer events (press, release, move, scroll, enter, exit, double_click).
  def pointer? = Specs::POINTER_TYPES.include?(type)

  # Widget-scoped keyboard events (key_press, key_release).
  def keyboard? = Specs::KEYBOARD_TYPES.include?(type)

  # Pane grid events (pane_resized, pane_dragged, pane_clicked, pane_focus_cycle).
  def pane? = Specs::PANE_TYPES.include?(type)

  # Focus lifecycle events (focused, blurred).
  def focus? = Specs::FOCUS_TYPES.include?(type)

  # Drag events (drag, drag_end).
  def drag? = Specs::DRAG_TYPES.include?(type)

  # Look up the spec for this event's type.
  # @return [Hash, nil]
  def spec = Specs.for(type)
end

Instance Method Details

#drag?Boolean

Drag events (drag, drag_end).

Returns:

  • (Boolean)


82
# File 'lib/plushie/event.rb', line 82

def drag? = Specs::DRAG_TYPES.include?(type)

#focus?Boolean

Focus lifecycle events (focused, blurred).

Returns:

  • (Boolean)


79
# File 'lib/plushie/event.rb', line 79

def focus? = Specs::FOCUS_TYPES.include?(type)

#keyboard?Boolean

Widget-scoped keyboard events (key_press, key_release).

Returns:

  • (Boolean)


73
# File 'lib/plushie/event.rb', line 73

def keyboard? = Specs::KEYBOARD_TYPES.include?(type)

#pane?Boolean

Pane grid events (pane_resized, pane_dragged, pane_clicked, pane_focus_cycle).

Returns:

  • (Boolean)


76
# File 'lib/plushie/event.rb', line 76

def pane? = Specs::PANE_TYPES.include?(type)

#pointer?Boolean

Pointer events (press, release, move, scroll, enter, exit, double_click).

Returns:

  • (Boolean)


70
# File 'lib/plushie/event.rb', line 70

def pointer? = Specs::POINTER_TYPES.include?(type)

#specHash?

Look up the spec for this event's type.

Returns:

  • (Hash, nil)


86
# File 'lib/plushie/event.rb', line 86

def spec = Specs.for(type)