Class: Plushie::Canvas::Shape::Rect

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/canvas/shape/rect.rb,
sig/plushie/canvas/shape.rbs

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

Instance Method Summary collapse

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.

Parameters:

  • x: (Numeric)
  • y: (Numeric)
  • w: (Numeric)
  • h: (Numeric)
  • fill: (Object) (defaults to: nil)
  • stroke: (Object) (defaults to: nil)
  • stroke_width: (Numeric, nil) (defaults to: nil)
  • opacity: (Numeric, nil) (defaults to: nil)
  • radius: (Numeric, Hash[Symbol, Numeric], nil) (defaults to: nil)


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

#fillObject (readonly)

Returns the value of attribute fill

Returns:

  • (Object)

    the current value of fill



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

def fill
  @fill
end

#hObject (readonly)

Returns the value of attribute h

Returns:

  • (Object)

    the current value of h



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

def h
  @h
end

#opacityObject (readonly)

Returns the value of attribute opacity

Returns:

  • (Object)

    the current value of opacity



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

def opacity
  @opacity
end

#radiusObject (readonly)

Returns the value of attribute radius

Returns:

  • (Object)

    the current value of radius



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

def radius
  @radius
end

#strokeObject (readonly)

Returns the value of attribute stroke

Returns:

  • (Object)

    the current value of stroke



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

def stroke
  @stroke
end

#stroke_widthObject (readonly)

Returns the value of attribute stroke_width

Returns:

  • (Object)

    the current value of stroke_width



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

def stroke_width
  @stroke_width
end

#wObject (readonly)

Returns the value of attribute w

Returns:

  • (Object)

    the current value of w



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

def w
  @w
end

#xObject (readonly)

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y

Returns:

  • (Object)

    the current value of 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.

Parameters:

  • key (Symbol)

Returns:

  • (Object)


20
# File 'lib/plushie/canvas/shape/rect.rb', line 20

def [](key) = to_wire[key]

#to_wireHash[Symbol, untyped]

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.

Returns:

  • (Hash[Symbol, untyped])


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