Class: Plushie::Canvas::Shape::Group

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/canvas/shape/group.rb

Overview

Group of shapes with transforms, clipping, and interactive properties.

Children are drawn relative to any applied transforms. Interactive fields (previously nested under an Interactive struct) live at the top level of the group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(children:, transforms: nil, clip: nil, opacity: nil, id: nil, on_click: nil, on_hover: nil, draggable: nil, drag_axis: nil, drag_bounds: nil, cursor: nil, hit_rect: nil, tooltip: nil, hover_style: nil, pressed_style: nil, focus_style: nil, show_focus_ring: nil, focus_ring_radius: nil, focusable: nil, a11y: nil) ⇒ Group

Returns a new instance of Group.



17
18
19
20
21
22
23
24
25
# File 'lib/plushie/canvas/shape/group.rb', line 17

def initialize(
  children:, transforms: nil, clip: nil, opacity: nil,
  id: nil, on_click: nil, on_hover: nil, draggable: nil,
  drag_axis: nil, drag_bounds: nil, cursor: nil, hit_rect: nil,
  tooltip: nil, hover_style: nil, pressed_style: nil,
  focus_style: nil, show_focus_ring: nil, focus_ring_radius: nil, focusable: nil, a11y: nil
)
  super
end

Instance Attribute Details

#a11yObject (readonly)

Returns the value of attribute a11y

Returns:

  • (Object)

    the current value of a11y



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def a11y
  @a11y
end

#childrenObject (readonly)

Returns the value of attribute children

Returns:

  • (Object)

    the current value of children



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def children
  @children
end

#clipObject (readonly)

Returns the value of attribute clip

Returns:

  • (Object)

    the current value of clip



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def clip
  @clip
end

#cursorObject (readonly)

Returns the value of attribute cursor

Returns:

  • (Object)

    the current value of cursor



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def cursor
  @cursor
end

#drag_axisObject (readonly)

Returns the value of attribute drag_axis

Returns:

  • (Object)

    the current value of drag_axis



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def drag_axis
  @drag_axis
end

#drag_boundsObject (readonly)

Returns the value of attribute drag_bounds

Returns:

  • (Object)

    the current value of drag_bounds



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def drag_bounds
  @drag_bounds
end

#draggableObject (readonly)

Returns the value of attribute draggable

Returns:

  • (Object)

    the current value of draggable



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def draggable
  @draggable
end

#focus_ring_radiusObject (readonly)

Returns the value of attribute focus_ring_radius

Returns:

  • (Object)

    the current value of focus_ring_radius



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def focus_ring_radius
  @focus_ring_radius
end

#focus_styleObject (readonly)

Returns the value of attribute focus_style

Returns:

  • (Object)

    the current value of focus_style



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def focus_style
  @focus_style
end

#focusableObject (readonly)

Returns the value of attribute focusable

Returns:

  • (Object)

    the current value of focusable



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def focusable
  @focusable
end

#hit_rectObject (readonly)

Returns the value of attribute hit_rect

Returns:

  • (Object)

    the current value of hit_rect



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def hit_rect
  @hit_rect
end

#hover_styleObject (readonly)

Returns the value of attribute hover_style

Returns:

  • (Object)

    the current value of hover_style



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def hover_style
  @hover_style
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def id
  @id
end

#on_clickObject (readonly)

Returns the value of attribute on_click

Returns:

  • (Object)

    the current value of on_click



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def on_click
  @on_click
end

#on_hoverObject (readonly)

Returns the value of attribute on_hover

Returns:

  • (Object)

    the current value of on_hover



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def on_hover
  @on_hover
end

#opacityObject (readonly)

Returns the value of attribute opacity

Returns:

  • (Object)

    the current value of opacity



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def opacity
  @opacity
end

#pressed_styleObject (readonly)

Returns the value of attribute pressed_style

Returns:

  • (Object)

    the current value of pressed_style



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def pressed_style
  @pressed_style
end

#show_focus_ringObject (readonly)

Returns the value of attribute show_focus_ring

Returns:

  • (Object)

    the current value of show_focus_ring



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def show_focus_ring
  @show_focus_ring
end

#tooltipObject (readonly)

Returns the value of attribute tooltip

Returns:

  • (Object)

    the current value of tooltip



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def tooltip
  @tooltip
end

#transformsObject (readonly)

Returns the value of attribute transforms

Returns:

  • (Object)

    the current value of transforms



11
12
13
# File 'lib/plushie/canvas/shape/group.rb', line 11

def transforms
  @transforms
end

Instance Method Details

#[](key) ⇒ Object

Access shape properties by key.

Parameters:

  • key (Symbol)

Returns:

  • (Object)


31
# File 'lib/plushie/canvas/shape/group.rb', line 31

def [](key) = to_wire[key]

#resolve_a11yObject

Resolve a11y: explicit overrides take priority, otherwise infer defaults from interactive fields so canvas elements are visible to assistive technology.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/plushie/canvas/shape/group.rb', line 66

def resolve_a11y
  return a11y if a11y

  if focusable
    {role: "group", label: tooltip}
  elsif on_click
    {role: "button"}
  elsif draggable
    {role: "slider"}
  end
end

#to_wireObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Encode shape for the wire protocol.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/plushie/canvas/shape/group.rb', line 35

def to_wire
  h = {type: "group"}
  h[:children] = children.map { |s| s.respond_to?(:to_wire) ? s.to_wire : s }
  if transforms
    h[:transforms] = transforms.map { |t| t.respond_to?(:to_wire) ? t.to_wire : t }
  end
  h[:clip] = clip.respond_to?(:to_wire) ? clip.to_wire : clip if clip
  h[:opacity] = opacity if opacity
  h[:id] = id if id
  h[:on_click] = on_click unless on_click.nil?
  h[:on_hover] = on_hover unless on_hover.nil?
  h[:draggable] = draggable unless draggable.nil?
  h[:drag_axis] = drag_axis if drag_axis
  h[:drag_bounds] = drag_bounds.respond_to?(:to_wire) ? drag_bounds.to_wire : drag_bounds if drag_bounds
  h[:cursor] = cursor if cursor
  h[:hit_rect] = hit_rect.respond_to?(:to_wire) ? hit_rect.to_wire : hit_rect if hit_rect
  h[:tooltip] = tooltip if tooltip
  h[:hover_style] = hover_style.respond_to?(:to_wire) ? hover_style.to_wire : hover_style if hover_style
  h[:pressed_style] = pressed_style.respond_to?(:to_wire) ? pressed_style.to_wire : pressed_style if pressed_style
  h[:focus_style] = focus_style.respond_to?(:to_wire) ? focus_style.to_wire : focus_style if focus_style
  h[:show_focus_ring] = show_focus_ring unless show_focus_ring.nil?
  h[:focus_ring_radius] = focus_ring_radius unless focus_ring_radius.nil?
  h[:focusable] = focusable unless focusable.nil?
  resolved_a11y = resolve_a11y
  h[:a11y] = resolved_a11y if resolved_a11y
  h
end