Class: Cards::ColumnLayout
Instance Method Summary collapse
- #height(card) ⇒ Object
-
#initialize(options = {}) ⇒ ColumnLayout
constructor
A new instance of ColumnLayout.
- #layout(card) ⇒ Object
- #width(card) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ColumnLayout
Returns a new instance of ColumnLayout.
5 6 7 |
# File 'lib/cards/layouts/column_layout.rb', line 5 def initialize( = {}) @wrap_at = .delete(:wrap_at) || 10 end |
Instance Method Details
#height(card) ⇒ Object
30 31 32 |
# File 'lib/cards/layouts/column_layout.rb', line 30 def height(card) card.children.heights.sum end |
#layout(card) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cards/layouts/column_layout.rb', line 9 def layout(card) x = card.x card.children.each_slice(@wrap_at) do |slice| y = card.y + 1 slice.each do |child| child.x, child.y = x, y child.layout y += child.height end x += slice.widths.max end end |
#width(card) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/cards/layouts/column_layout.rb', line 22 def width(card) width = 0 card.children.each_slice(@wrap_at) do |slice| width += slice.widths.max end width end |