Class: Charming::Presentation::Layout::Rect

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



9
10
11
# File 'lib/charming/presentation/layout/rect.rb', line 9

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



9
10
11
# File 'lib/charming/presentation/layout/rect.rb', line 9

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



9
10
11
# File 'lib/charming/presentation/layout/rect.rb', line 9

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y

Returns:

  • (Object)

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