Class: Prawn::Document::ColumnBox

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

Overview

Implements the necessary functionality to allow Document#column_box to work.

Instance Attribute Summary

Attributes inherited from BoundingBox

#parent

Instance Method Summary collapse

Methods inherited from BoundingBox

#absolute_bottom, #absolute_bottom_left, #absolute_bottom_right, #absolute_left, #absolute_right, #absolute_top, #absolute_top_left, #absolute_top_right, #anchor, #bottom, #bottom_left, #bottom_right, #height, #indent, #left, #right, #stretchy?, #top, #top_left, #top_right

Constructor Details

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

:nodoc:



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

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

Instance Method Details

#left_sideObject

x coordinate of the left edge of the current column



91
92
93
# File 'lib/prawn/document/column_box.rb', line 91

def left_side
  absolute_left + (width_of_column * @current_column)
end

#move_past_bottomObject

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



104
105
106
107
108
109
110
# File 'lib/prawn/document/column_box.rb', line 104

def move_past_bottom 
  @current_column = (@current_column + 1) % @columns
  @parent.y = @y
  if 0 == @current_column
    @parent.start_new_page
  end
end

#right_sideObject

x co-orordinate of the right edge of the current column



97
98
99
100
# File 'lib/prawn/document/column_box.rb', line 97

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

#widthObject

The column width, not the width of the whole box. Used to calculate how long a line of text can be.



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

def width
  super / @columns - @spacer
end

#width_of_columnObject

Column width including the spacer.



85
86
87
# File 'lib/prawn/document/column_box.rb', line 85

def width_of_column
  width + @spacer
end