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, 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
-
#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.
-
#max_height ⇒ Object
readonly
Returns the value of attribute max_height.
-
#max_width ⇒ Object
readonly
Returns the value of attribute max_width.
-
#min_height ⇒ Object
readonly
Returns the value of attribute min_height.
-
#min_width ⇒ Object
readonly
Returns the value of attribute min_width.
-
#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:, min_width: nil, max_width: nil, min_height: nil, max_height: nil) ⇒ 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:, 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 ? (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 |
#max_height ⇒ Object (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_width ⇒ Object (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_height ⇒ Object (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_width ⇒ Object (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 |
#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.
46 47 48 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 46 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, 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_bottom ⇒ Object
43 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 43 def border_bottom = border ? 1 : 0 |
#border_left ⇒ Object
44 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 44 def border_left = border ? 1 : 0 |
#border_right ⇒ Object
42 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 42 def border_right = border ? 1 : 0 |
#border_style ⇒ Object
62 63 64 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 62 def border_style (border == true) ? :normal : border end |
#border_top ⇒ Object
41 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 41 def border_top = border ? 1 : 0 |
#hash ⇒ Object
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_bottom ⇒ Object
50 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 50 def padding_bottom = padding ? @padding_values[2] : 0 |
#padding_left ⇒ Object
51 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 51 def padding_left = padding ? @padding_values[3] : 0 |
#padding_right ⇒ Object
49 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 49 def padding_right = padding ? @padding_values[1] : 0 |
#padding_top ⇒ Object
48 |
# File 'lib/charming/presentation/layout/pane_geometry.rb', line 48 def padding_top = padding ? @padding_values[0] : 0 |