Class: Plushie::Canvas::Shape::Group
- Inherits:
-
Data
- Object
- Data
- Plushie::Canvas::Shape::Group
- 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
-
#a11y ⇒ Object
readonly
Returns the value of attribute a11y.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#clip ⇒ Object
readonly
Returns the value of attribute clip.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#drag_axis ⇒ Object
readonly
Returns the value of attribute drag_axis.
-
#drag_bounds ⇒ Object
readonly
Returns the value of attribute drag_bounds.
-
#draggable ⇒ Object
readonly
Returns the value of attribute draggable.
-
#focus_ring_radius ⇒ Object
readonly
Returns the value of attribute focus_ring_radius.
-
#focus_style ⇒ Object
readonly
Returns the value of attribute focus_style.
-
#focusable ⇒ Object
readonly
Returns the value of attribute focusable.
-
#hit_rect ⇒ Object
readonly
Returns the value of attribute hit_rect.
-
#hover_style ⇒ Object
readonly
Returns the value of attribute hover_style.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#on_click ⇒ Object
readonly
Returns the value of attribute on_click.
-
#on_hover ⇒ Object
readonly
Returns the value of attribute on_hover.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
-
#pressed_style ⇒ Object
readonly
Returns the value of attribute pressed_style.
-
#show_focus_ring ⇒ Object
readonly
Returns the value of attribute show_focus_ring.
-
#tooltip ⇒ Object
readonly
Returns the value of attribute tooltip.
-
#transforms ⇒ Object
readonly
Returns the value of attribute transforms.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access shape properties by key.
-
#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
constructor
A new instance of Group.
-
#resolve_a11y ⇒ Object
Resolve a11y: explicit overrides take priority, otherwise infer defaults from interactive fields so canvas elements are visible to assistive technology.
-
#to_wire ⇒ Object
private
Encode shape for the wire protocol.
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
#a11y ⇒ Object (readonly)
Returns the value of attribute a11y
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def a11y @a11y end |
#children ⇒ Object (readonly)
Returns the value of attribute children
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def children @children end |
#clip ⇒ Object (readonly)
Returns the value of attribute clip
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def clip @clip end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def cursor @cursor end |
#drag_axis ⇒ Object (readonly)
Returns the value of attribute drag_axis
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def drag_axis @drag_axis end |
#drag_bounds ⇒ Object (readonly)
Returns the value of attribute drag_bounds
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def drag_bounds @drag_bounds end |
#draggable ⇒ Object (readonly)
Returns the value of attribute draggable
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def draggable @draggable end |
#focus_ring_radius ⇒ Object (readonly)
Returns the value of attribute focus_ring_radius
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def focus_ring_radius @focus_ring_radius end |
#focus_style ⇒ Object (readonly)
Returns the value of attribute focus_style
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def focus_style @focus_style end |
#focusable ⇒ Object (readonly)
Returns the value of attribute focusable
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def focusable @focusable end |
#hit_rect ⇒ Object (readonly)
Returns the value of attribute hit_rect
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def hit_rect @hit_rect end |
#hover_style ⇒ Object (readonly)
Returns the value of attribute hover_style
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def hover_style @hover_style end |
#id ⇒ Object (readonly)
Returns the value of attribute id
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def id @id end |
#on_click ⇒ Object (readonly)
Returns the value of attribute on_click
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def on_click @on_click end |
#on_hover ⇒ Object (readonly)
Returns the value of attribute on_hover
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def on_hover @on_hover end |
#opacity ⇒ Object (readonly)
Returns the value of attribute opacity
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def opacity @opacity end |
#pressed_style ⇒ Object (readonly)
Returns the value of attribute pressed_style
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def pressed_style @pressed_style end |
#show_focus_ring ⇒ Object (readonly)
Returns the value of attribute show_focus_ring
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def show_focus_ring @show_focus_ring end |
#tooltip ⇒ Object (readonly)
Returns the value of attribute tooltip
11 12 13 |
# File 'lib/plushie/canvas/shape/group.rb', line 11 def tooltip @tooltip end |
#transforms ⇒ Object (readonly)
Returns the value of attribute 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.
31 |
# File 'lib/plushie/canvas/shape/group.rb', line 31 def [](key) = to_wire[key] |
#resolve_a11y ⇒ Object
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_wire ⇒ Object
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 |