Class: Plushie::Canvas::Shape::ShapeStyle

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

Overview

Style overrides for interactive canvas shape states (hover, pressed).

Examples:

ShapeStyle.new(fill: "#ff0000", opacity: 0.8)
ShapeStyle.new(stroke: "#000", fill: "blue")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fill: nil, stroke: nil, opacity: nil) ⇒ ShapeStyle

Returns a new instance of ShapeStyle.



12
13
14
# File 'lib/plushie/canvas/shape/shape_style.rb', line 12

def initialize(fill: nil, stroke: nil, opacity: nil)
  super
end

Instance Attribute Details

#fillObject (readonly)

Returns the value of attribute fill

Returns:

  • (Object)

    the current value of fill



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

def fill
  @fill
end

#opacityObject (readonly)

Returns the value of attribute opacity

Returns:

  • (Object)

    the current value of opacity



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

def opacity
  @opacity
end

#strokeObject (readonly)

Returns the value of attribute stroke

Returns:

  • (Object)

    the current value of stroke



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

def stroke
  @stroke
end

Instance Method Details

#[](key) ⇒ Object

Backward-compatible hash-style access.



17
# File 'lib/plushie/canvas/shape/shape_style.rb', line 17

def [](key) = to_wire[key]

#to_wireHash

Returns wire-ready style map (nil fields stripped).

Returns:

  • (Hash)

    wire-ready style map (nil fields stripped)



20
21
22
23
24
25
26
# File 'lib/plushie/canvas/shape/shape_style.rb', line 20

def to_wire
  h = {}
  h[:fill] = fill if fill
  h[:stroke] = stroke if stroke
  h[:opacity] = opacity if opacity
  h
end