Class: Charming::Presentation::Layout::Rect
- Inherits:
-
Data
- Object
- Data
- Charming::Presentation::Layout::Rect
- Defined in:
- lib/charming/presentation/layout/rect.rb
Overview
Rect is an immutable rectangle with a top-left position (x, y) and dimensions (width, height). Layout operations produce new Rect instances rather than mutating existing ones.
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#inset(top: 0, right: 0, bottom: 0, left: 0) ⇒ Object
Returns a new Rect inset by top/right/bottom/left cells.
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height
9 10 11 |
# File 'lib/charming/presentation/layout/rect.rb', line 9 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width
9 10 11 |
# File 'lib/charming/presentation/layout/rect.rb', line 9 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x
9 10 11 |
# File 'lib/charming/presentation/layout/rect.rb', line 9 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y
9 10 11 |
# File 'lib/charming/presentation/layout/rect.rb', line 9 def y @y end |
Instance Method Details
#inset(top: 0, right: 0, bottom: 0, left: 0) ⇒ Object
Returns a new Rect inset by top/right/bottom/left cells. The result is clamped to a minimum width/height of 0.
12 13 14 15 16 17 18 19 |
# File 'lib/charming/presentation/layout/rect.rb', line 12 def inset(top: 0, right: 0, bottom: 0, left: 0) Rect.new( x: x + left, y: y + top, width: [width - left - right, 0].max, height: [height - top - bottom, 0].max ) end |