Class: Charming::Layout::PaneGeometry
- Inherits:
-
Object
- Object
- Charming::Layout::PaneGeometry
- Defined in:
- lib/charming/presentation/layout/pane_geometry.rb
Overview
PaneGeometry holds a Pane’s sizing (width, height, grow) 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
-
#border ⇒ Object
readonly
Returns the value of attribute border.
-
#grow ⇒ Object
readonly
Returns the value of attribute grow.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#padding_values ⇒ Object
readonly
Returns the value of attribute padding_values.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #border_bottom ⇒ Object
- #border_left ⇒ Object
- #border_right ⇒ Object
- #border_style ⇒ Object
- #border_top ⇒ Object
- #hash ⇒ Object
-
#initialize(width:, height:, grow:, border:, padding:) ⇒ PaneGeometry
constructor
A new instance of PaneGeometry.
- #inset(rect) ⇒ Object
- #padding_bottom ⇒ Object
- #padding_left ⇒ Object
- #padding_right ⇒ Object
- #padding_top ⇒ Object
Constructor Details
#initialize(width:, height:, grow:, border:, padding:) ⇒ PaneGeometry
Returns a new instance of PaneGeometry.
16 17 18 19 20 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 16 def initialize(width:, height:, grow:, border:, padding:) @width, @height, @grow, @border, @padding = width, height, grow, border, padding @padding_values = padding ? (Array(padding)) : [0, 0, 0, 0] freeze end |
Instance Attribute Details
#border ⇒ Object (readonly)
Returns the value of attribute border.
9 10 11 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 9 def border @border end |
#grow ⇒ Object (readonly)
Returns the value of attribute grow.
9 10 11 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 9 def grow @grow end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
9 10 11 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 9 def height @height end |
#padding ⇒ Object (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_values ⇒ Object (readonly)
Returns the value of attribute padding_values.
38 39 40 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 38 def padding_values @padding_values end |
#width ⇒ Object (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) ⇒ Object
11 12 13 14 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 11 def self.build(width: nil, height: nil, grow: nil, border: nil, padding: nil) new(width: width, height: height, grow: grow, border: (border == true) ? :normal : border, padding: padding) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
22 23 24 25 26 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 22 def ==(other) other.is_a?(PaneGeometry) && width == other.width && height == other.height && grow == other.grow && border == other.border && padding == other.padding end |
#border_bottom ⇒ Object
35 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 35 def border_bottom = border ? 1 : 0 |
#border_left ⇒ Object
36 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 36 def border_left = border ? 1 : 0 |
#border_right ⇒ Object
34 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 34 def border_right = border ? 1 : 0 |
#border_style ⇒ Object
54 55 56 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 54 def border_style (border == true) ? :normal : border end |
#border_top ⇒ Object
33 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 33 def border_top = border ? 1 : 0 |
#hash ⇒ Object
29 30 31 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 29 def hash [width, height, grow, border, padding].hash end |
#inset(rect) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 45 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_bottom ⇒ Object
42 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 42 def padding_bottom = padding ? @padding_values[2] : 0 |
#padding_left ⇒ Object
43 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 43 def padding_left = padding ? @padding_values[3] : 0 |
#padding_right ⇒ Object
41 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 41 def padding_right = padding ? @padding_values[1] : 0 |
#padding_top ⇒ Object
40 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 40 def padding_top = padding ? @padding_values[0] : 0 |