Class: Cards::Layouts::ColumnLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/cards/layouts/column_layout.rb

Instance Method Summary collapse

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(options = {})
  @wrap_at = options.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