Class: HexaPDF::Layout::ColumnBox

Inherits:
Box
  • Object
show all
Defined in:
lib/hexapdf/layout/column_box.rb

Overview

A ColumnBox arranges boxes in one or more columns.

The number and width of the columns as well as the size of the gap between the columns can be modified. Additionally, the contents can either fill the columns one after the other or the columns can be made equally high.

If the column box has padding and/or borders specified, they are handled like with any other box. This means they are around all columns and their contents and are not used separately for each column.

The following style properties are used (additionally to those used by the parent class):

Style#position

If this is set to :flow, the frames created for the columns will take the shape of the frame into account. This also means that the available_width and available_height arguments are ignored.

Constant Summary

Constants included from Utils

Utils::EPSILON

Instance Attribute Summary collapse

Attributes inherited from Box

#fit_result, #height, #properties, #style, #width

Instance Method Summary collapse

Methods inherited from Box

#content_height, #content_width, create, #draw, #fit, #split, #split_box?

Constructor Details

#initialize(children: [], columns: 2, gaps: 36, equal_height: true, **kwargs) ⇒ ColumnBox

Creates a new ColumnBox object for the given child boxes in children.

columns

Can either simply integer specify the number of columns or be a full column definition (see #columns for details).

gaps

Can either be a simply integer specifying the width between two columns or a full gap definition (see #gap for details).

equal_height

If true, the #fit method tries to balance the columns in terms of their height. Otherwise the columns are filled from the left.



123
124
125
126
127
128
129
# File 'lib/hexapdf/layout/column_box.rb', line 123

def initialize(children: [], columns: 2, gaps: 36, equal_height: true, **kwargs)
  super(**kwargs)
  @children = children
  @columns = (columns.kind_of?(Array) ? columns : [-1] * columns)
  @gaps = (gaps.kind_of?(Array) ? gaps : [gaps])
  @equal_height = equal_height
end

Instance Attribute Details

#childrenObject (readonly)

The child boxes of this ColumnBox. They need to be finalized before #fit is called.



61
62
63
# File 'lib/hexapdf/layout/column_box.rb', line 61

def children
  @children
end

#columnsObject (readonly)

The columns definition.

If the value is an array, it needs to contain the widths of the columns. The size of the array determines the number of columns. Otherwise, if the value is an integer, the value defines the number of equally sized columns, i.e. a value of N is equal to [-1]*N.

If a negative integer is used for the width, the column is auto-sized. Such columns split the remaining width (after substracting the widths of the fixed columns) proportionally among them. For example, if the definition is [-1, -2, -2], the first column is a fifth of the width and the other columns are each two fifth of the width.

Examples:

#>pdf-composer
composer.box(:column, columns: 2, gaps: 10,
             children: [composer.document.layout.lorem_ipsum_box])

#>pdf-composer
composer.box(:column, columns: [50, -2, -1], gaps: [10, 5],
             children: [composer.document.layout.lorem_ipsum_box])


85
86
87
# File 'lib/hexapdf/layout/column_box.rb', line 85

def columns
  @columns
end

#equal_heightObject (readonly)

Determines whether the columns should all be equally high or not.

Examples:

#>pdf-composer
composer.box(:column, children: [composer.document.layout.lorem_ipsum_box])

#>pdf-composer
composer.box(:column, equal_height: false,
             children: [composer.document.layout.lorem_ipsum_box])


107
108
109
# File 'lib/hexapdf/layout/column_box.rb', line 107

def equal_height
  @equal_height
end

#gapsObject (readonly)

The size of the gaps between the columns.

This is an array containing the width of the gaps. If there are more gaps than numbers in the array, the array is cycled.

Examples: see #columns



93
94
95
# File 'lib/hexapdf/layout/column_box.rb', line 93

def gaps
  @gaps
end

Instance Method Details

#empty?Boolean

Returns true if no box was fitted into the columns.

Returns:

  • (Boolean)


137
138
139
# File 'lib/hexapdf/layout/column_box.rb', line 137

def empty?
  super && (!@box_fitter || @box_fitter.fit_results.empty?)
end

#supports_position_flow?Boolean

Returns true as the ‘position’ style property value :flow is supported.

Returns:

  • (Boolean)


132
133
134
# File 'lib/hexapdf/layout/column_box.rb', line 132

def supports_position_flow?
  true
end