Class: WhirledPeas::Graphics::ContainerDimensions

Inherits:
Object
  • Object
show all
Defined in:
lib/whirled_peas/graphics/container_dimensions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings, content_width, content_height, num_cols = 1, num_rows = 1) ⇒ ContainerDimensions

Returns a new instance of ContainerDimensions.



6
7
8
9
10
11
12
13
14
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 6

def initialize(settings, content_width, content_height, num_cols=1, num_rows=1)
  @orig_content_width = content_width
  @orig_content_height = content_height
  @children_width = content_width
  @children_height = content_height
  @num_cols = num_cols
  @num_rows = num_rows
  @settings = settings
end

Instance Attribute Details

#children_heightObject (readonly)

Returns the value of attribute children_height.



4
5
6
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 4

def children_height
  @children_height
end

#children_widthObject (readonly)

Returns the value of attribute children_width.



4
5
6
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 4

def children_width
  @children_width
end

#num_colsObject (readonly)

Returns the value of attribute num_cols.



4
5
6
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 4

def num_cols
  @num_cols
end

#num_rowsObject (readonly)

Returns the value of attribute num_rows.



4
5
6
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 4

def num_rows
  @num_rows
end

Instance Method Details

#content_heightObject



25
26
27
28
29
30
31
32
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 25

def content_height
  return orig_content_height unless settings.height
  if settings.border_sizing?
    settings.height - outer_border_height - scrollbar_height - padding_height
  else
    settings.height
  end
end

#content_widthObject



16
17
18
19
20
21
22
23
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 16

def content_width
  return orig_content_width unless settings.width
  if settings.border_sizing?
    settings.width - outer_border_width - scrollbar_width - padding_width
  else
    settings.width
  end
end

#grid_heightObject



52
53
54
55
56
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 52

def grid_height
  (settings.border.inner_horiz? ? 1 : 0) +
    inner_grid_height +
    (settings.scrollbar.horiz? ? 1 : 0)
end

#grid_widthObject



40
41
42
43
44
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 40

def grid_width
  (settings.border.inner_vert? ? 1 : 0) +
    inner_grid_width +
    (settings.scrollbar.vert? ? 1 : 0)
end

#inner_border_heightObject



92
93
94
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 92

def inner_border_height
  settings.border.inner_horiz? ? 1 : 0
end

#inner_border_widthObject



88
89
90
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 88

def inner_border_width
  settings.border.inner_vert? ? 1 : 0
end

#inner_grid_heightObject



46
47
48
49
50
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 46

def inner_grid_height
  settings.padding.top +
    content_height +
    settings.padding.bottom
end

#inner_grid_widthObject



34
35
36
37
38
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 34

def inner_grid_width
  settings.padding.left +
    content_width +
    settings.padding.right
end

#margin_heightObject



76
77
78
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 76

def margin_height
  settings.margin.top + settings.margin.bottom
end

#margin_widthObject



72
73
74
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 72

def margin_width
  settings.margin.left + settings.margin.right
end

#outer_border_heightObject



84
85
86
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 84

def outer_border_height
  (settings.border.top? ? 1 : 0) + (settings.border.bottom? ? 1 : 0)
end

#outer_border_widthObject



80
81
82
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 80

def outer_border_width
  (settings.border.left? ? 1 : 0) + (settings.border.right? ? 1 : 0)
end

#outer_heightObject



65
66
67
68
69
70
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 65

def outer_height
  @outer_height ||= margin_height +
    outer_border_height +
    num_rows * (padding_height + content_height + scrollbar_height) +
    (num_rows - 1) * inner_border_height
end

#outer_widthObject



58
59
60
61
62
63
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 58

def outer_width
  @outer_width ||= margin_width +
    outer_border_width +
    num_cols * (padding_width + content_width + scrollbar_width) +
    (num_cols - 1) * inner_border_width
end

#padding_heightObject



100
101
102
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 100

def padding_height
  settings.padding.top + settings.padding.bottom
end

#padding_widthObject



96
97
98
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 96

def padding_width
  settings.padding.left + settings.padding.right
end

#scrollbar_heightObject



108
109
110
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 108

def scrollbar_height
  settings.scrollbar.horiz? ? 1 : 0
end

#scrollbar_widthObject



104
105
106
# File 'lib/whirled_peas/graphics/container_dimensions.rb', line 104

def scrollbar_width
  settings.scrollbar.vert? ? 1 : 0
end