Class: Plushie::Canvas::Shape::Rect
- Inherits:
-
Data
- Object
- Data
- Plushie::Canvas::Shape::Rect
- Defined in:
- lib/plushie/canvas/shape/rect.rb
Overview
Rectangle shape.
The +radius+ field accepts either a uniform number or a Hash with per-corner values (+top_left+, +top_right+, +bottom_right+, +bottom_left+).
Instance Attribute Summary collapse
-
#fill ⇒ Object
readonly
Returns the value of attribute fill.
-
#h ⇒ Object
readonly
Returns the value of attribute h.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
-
#radius ⇒ Object
readonly
Returns the value of attribute radius.
-
#stroke ⇒ Object
readonly
Returns the value of attribute stroke.
-
#stroke_width ⇒ Object
readonly
Returns the value of attribute stroke_width.
-
#w ⇒ Object
readonly
Returns the value of attribute w.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access shape properties by key.
-
#initialize(x:, y:, w:, h:, fill: nil, stroke: nil, stroke_width: nil, opacity: nil, radius: nil) ⇒ Rect
constructor
A new instance of Rect.
-
#to_wire ⇒ Object
private
Encode shape for the wire protocol.
Constructor Details
#initialize(x:, y:, w:, h:, fill: nil, stroke: nil, stroke_width: nil, opacity: nil, radius: nil) ⇒ Rect
Returns a new instance of Rect.
12 13 14 |
# File 'lib/plushie/canvas/shape/rect.rb', line 12 def initialize(x:, y:, w:, h:, fill: nil, stroke: nil, stroke_width: nil, opacity: nil, radius: nil) super end |
Instance Attribute Details
#fill ⇒ Object (readonly)
Returns the value of attribute fill
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def fill @fill end |
#h ⇒ Object (readonly)
Returns the value of attribute h
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def h @h end |
#opacity ⇒ Object (readonly)
Returns the value of attribute opacity
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def opacity @opacity end |
#radius ⇒ Object (readonly)
Returns the value of attribute radius
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def radius @radius end |
#stroke ⇒ Object (readonly)
Returns the value of attribute stroke
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def stroke @stroke end |
#stroke_width ⇒ Object (readonly)
Returns the value of attribute stroke_width
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def stroke_width @stroke_width end |
#w ⇒ Object (readonly)
Returns the value of attribute w
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def w @w end |
#x ⇒ Object (readonly)
Returns the value of attribute x
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y
11 12 13 |
# File 'lib/plushie/canvas/shape/rect.rb', line 11 def y @y end |
Instance Method Details
#[](key) ⇒ Object
Access shape properties by key.
20 |
# File 'lib/plushie/canvas/shape/rect.rb', line 20 def [](key) = to_wire[key] |
#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.
24 25 26 27 28 29 30 31 32 |
# File 'lib/plushie/canvas/shape/rect.rb', line 24 def to_wire h = {type: "rect", x: x, y: y, w: w, h: self.h} h[:fill] = fill if fill h[:stroke] = stroke if stroke h[:stroke_width] = stroke_width if stroke_width h[:opacity] = opacity if opacity h[:radius] = radius if radius h end |