Class: Cards::Layouts::ColumnLayout
- Defined in:
- lib/cards/layouts/column_layout.rb
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.
6 7 8 |
# File 'lib/cards/layouts/column_layout.rb', line 6 def initialize( = {}) @wrap_at = .delete(:wrap_at) || 10 end |
Instance Method Details
#height(card) ⇒ Object
31 32 33 |
# File 'lib/cards/layouts/column_layout.rb', line 31 def height(card) card.children.heights.sum end |
#layout(card) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cards/layouts/column_layout.rb', line 10 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
23 24 25 26 27 28 29 |
# File 'lib/cards/layouts/column_layout.rb', line 23 def width(card) width = 0 card.children.each_slice(@wrap_at) do |slice| width += slice.widths.max end width end |