class HexaPDF::Layout::ContainerBox

Parent

This is a simple container box for laying out a number of boxes together. It is registered under the :container name.

The box does not support the value :flow for the style property position, so the child boxes are laid out in the current region only.

If splitable is false (the default) and if any box doesn’t fit, the whole container doesn’t fit.

By default the child boxes are laid out from top to bottom. By appropriately setting the style properties ‘mask_mode’, ‘align’ and ‘valign’, it is possible to lay out the children bottom to top, left to right, or right to left:

  • The standard top-to-bottom layout:

    composer.container do |container|
      container.box(height: 20, style: {background_color: "hp-blue-dark"})
      container.box(height: 20, style: {background_color: "hp-blue"})
      container.box(height: 20, style: {background_color: "hp-blue-light"})
    end

  • The bottom-to-top layout (using valign = :bottom to fill up from the bottom and mask_mode = :fill_horizontal to only remove the area to the left and right of the box):

    composer.container do |container|
      container.box(height: 20, style: {background_color: "hp-blue-dark",
                                        mask_mode: :fill_horizontal, valign: :bottom})
      container.box(height: 20, style: {background_color: "hp-blue",
                                        mask_mode: :fill_horizontal, valign: :bottom})
      container.box(height: 20, style: {background_color: "hp-blue-light",
                                        mask_mode: :fill_horizontal, valign: :bottom})
    end

  • The left-to-right layout (using mask_mode = :fill_vertical to fill the area to the top and bottom of the box):

    composer.container do |container|
      container.box(width: 20, style: {background_color: "hp-blue-dark",
                                       mask_mode: :fill_vertical})
      container.box(width: 20, style: {background_color: "hp-blue",
                                       mask_mode: :fill_vertical})
      container.box(width: 20, style: {background_color: "hp-blue-light",
                                       mask_mode: :fill_vertical})
    end

  • The right-to-left layout (using align = :right to fill up from the right and mask_mode = :fill_vertical to fill the area to the top and bottom of the box):

    composer.container do |container|
      container.box(width: 20, style: {background_color: "hp-blue-dark",
                                       mask_mode: :fill_vertical, align: :right})
      container.box(width: 20, style: {background_color: "hp-blue",
                                       mask_mode: :fill_vertical, align: :right})
      container.box(width: 20, style: {background_color: "hp-blue-light",
                                       mask_mode: :fill_vertical, align: :right})
    end

Attributes

children[R]

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

splitable[R]

Specifies whether the container box allows splitting its content.

If splitting is not allowed (the default), all child boxes must fit together into one region.

Examples:

# Fails with an error because the content of the container box is too big
composer.column do |col|
  col.container do |container|
    container.lorem_ipsum
  end
end

composer.column do |col|
  col.container(splitable: true) do |container|
    container.lorem_ipsum
  end
end

Public Class Methods

new(children: [], splitable: false, **kwargs)

Creates a new container box, optionally accepting an array of child boxes.

Example:

composer.text("A paragraph here")
composer.container(height: 40, style: {border: {width: 1}, padding: 5,
                                       align: :center}) do |container|
  container.text("Some", mask_mode: :fill_vertical)
  container.text("text", mask_mode: :fill_vertical, valign: :center)
  container.text("here", mask_mode: :fill_vertical, valign: :bottom)
end
composer.text("Another paragraph")

Calls superclass method HexaPDF::Layout::Box::new

Public Instance Methods

empty?()

Returns true if no box was fitted into the container.

Calls superclass method HexaPDF::Layout::Box#empty?