Class: Charming::Layout::PaneGeometry

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/layout/pane_geometry.rb

Overview

PaneGeometry holds a Pane’s sizing (width, height, grow, min/max constraints) and inset configuration (border + padding). It knows how to inset a Rect for the content area and how to expand CSS-style 1/2/4-value padding.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width:, height:, grow:, border:, padding:, min_width: nil, max_width: nil, min_height: nil, max_height: nil) ⇒ PaneGeometry

Returns a new instance of PaneGeometry.



20
21
22
23
24
25
26
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 20

def initialize(width:, height:, grow:, border:, padding:,
  min_width: nil, max_width: nil, min_height: nil, max_height: nil)
  @width, @height, @grow, @border, @padding = width, height, grow, border, padding
  @min_width, @max_width, @min_height, @max_height = min_width, max_width, min_height, max_height
  @padding_values = padding ? expand_padding(Array(padding)) : [0, 0, 0, 0]
  freeze
end

Instance Attribute Details

#borderObject (readonly)

Returns the value of attribute border.



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

def border
  @border
end

#growObject (readonly)

Returns the value of attribute grow.



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

def grow
  @grow
end

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#max_heightObject (readonly)

Returns the value of attribute max_height.



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

def max_height
  @max_height
end

#max_widthObject (readonly)

Returns the value of attribute max_width.



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

def max_width
  @max_width
end

#min_heightObject (readonly)

Returns the value of attribute min_height.



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

def min_height
  @min_height
end

#min_widthObject (readonly)

Returns the value of attribute min_width.



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

def min_width
  @min_width
end

#paddingObject (readonly)

Returns the value of attribute padding.



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

def padding
  @padding
end

#padding_valuesObject (readonly)

Returns the value of attribute padding_values.



46
47
48
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 46

def padding_values
  @padding_values
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Class Method Details

.build(width: nil, height: nil, grow: nil, border: nil, padding: nil, min_width: nil, max_width: nil, min_height: nil, max_height: nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 12

def self.build(width: nil, height: nil, grow: nil, border: nil, padding: nil,
  min_width: nil, max_width: nil, min_height: nil, max_height: nil)
  new(width: width, height: height, grow: grow,
    border: (border == true) ? :normal : border, padding: padding,
    min_width: min_width, max_width: max_width,
    min_height: min_height, max_height: max_height)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



28
29
30
31
32
33
34
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 28

def ==(other)
  other.is_a?(PaneGeometry) &&
    width == other.width && height == other.height && grow == other.grow &&
    border == other.border && padding == other.padding &&
    min_width == other.min_width && max_width == other.max_width &&
    min_height == other.min_height && max_height == other.max_height
end

#border_bottomObject



43
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 43

def border_bottom = border ? 1 : 0

#border_leftObject



44
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 44

def border_left = border ? 1 : 0

#border_rightObject



42
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 42

def border_right = border ? 1 : 0

#border_styleObject



62
63
64
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 62

def border_style
  (border == true) ? :normal : border
end

#border_topObject



41
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 41

def border_top = border ? 1 : 0

#hashObject



37
38
39
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 37

def hash
  [width, height, grow, border, padding, min_width, max_width, min_height, max_height].hash
end

#inset(rect) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 53

def inset(rect)
  rect.inset(
    top: border_top + padding_top,
    right: border_right + padding_right,
    bottom: border_bottom + padding_bottom,
    left: border_left + padding_left
  )
end

#padding_bottomObject



50
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 50

def padding_bottom = padding ? @padding_values[2] : 0

#padding_leftObject



51
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 51

def padding_left = padding ? @padding_values[3] : 0

#padding_rightObject



49
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 49

def padding_right = padding ? @padding_values[1] : 0

#padding_topObject



48
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 48

def padding_top = padding ? @padding_values[0] : 0