Class: Prawn::Document::ColumnBox

Inherits:
BoundingBox show all
Defined in:
lib/prawn/document/column_box.rb

Overview

Implements the necessary functionality to allow #column_box to work.

Experimental API collapse

Constructor Details

#initialize(document, parent, point, options = {}) ⇒ ColumnBox

Returns a new instance of ColumnBox.

Parameters:

  • point (Array(Number, Number))
  • options (Hash{Symbol => any}) (defaults to: {})

Options Hash (options):

  • :width (Number)

    width of the new column box, must be specified.

  • :height (Number)

    height of the new column box, stretchy box if omitted.

  • :columns (Integer) — default: 3
  • :spacer (Number) — default: font_size
  • :reflow_margins (Boolean) — default: false


68
69
70
71
72
73
74
# File 'lib/prawn/document/column_box.rb', line 68

def initialize(document, parent, point, options = {})
  super
  @columns = options[:columns] || 3
  @spacer = options[:spacer] || @document.font_size
  @current_column = 0
  @reflow_margins = options[:reflow_margins]
end

Instance Method Details

#bare_column_widthNumber

The column width, not the width of the whole box, before left and/or right padding.

Returns:

  • (Number)


80
81
82
# File 'lib/prawn/document/column_box.rb', line 80

def bare_column_width
  (@width - (@spacer * (@columns - 1))) / @columns
end

#leftNumber

Relative position of the left edge of the current column.

Returns:

  • (Number)


109
110
111
# File 'lib/prawn/document/column_box.rb', line 109

def left
  width_of_column * @current_column
end

#left_sideNumber

x coordinate of the left edge of the current column.

Returns:

  • (Number)


102
103
104
# File 'lib/prawn/document/column_box.rb', line 102

def left_side
  absolute_left + (width_of_column * @current_column)
end

#move_past_bottomvoid

This method returns an undefined value.

Moves to the next column or starts a new page if currently positioned at the rightmost column.



132
133
134
135
136
137
138
139
140
141
# File 'lib/prawn/document/column_box.rb', line 132

def move_past_bottom
  @current_column = (@current_column + 1) % @columns
  @document.y = @y
  if @current_column.zero?
    if @reflow_margins
      @y = @parent.absolute_top
    end
    @document.start_new_page
  end
end

#rightNumber

Relative position of the right edge of the current column.

Returns:

  • (Number)


124
125
126
# File 'lib/prawn/document/column_box.rb', line 124

def right
  left + width
end

#right_sideNumber

x coordinate of the right edge of the current column.

Returns:

  • (Number)


116
117
118
119
# File 'lib/prawn/document/column_box.rb', line 116

def right_side
  columns_from_right = @columns - (1 + @current_column)
  absolute_right - (width_of_column * columns_from_right)
end

#widthNumber

The column width after padding. Used to calculate how long a line of text can be.

Returns:

  • (Number)


88
89
90
# File 'lib/prawn/document/column_box.rb', line 88

def width
  bare_column_width - (@total_left_padding + @total_right_padding)
end

#width_of_columnNumber

Column width including the spacer.

Returns:

  • (Number)


95
96
97
# File 'lib/prawn/document/column_box.rb', line 95

def width_of_column
  bare_column_width + @spacer
end