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. Since the boxes should be laid out together, if any box doesn’t fit, the whole container doesn’t fit. Splitting the container is also not possible for the same reason.

By default the child boxes are laid out from top to bottom by default. 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(:base, height: 20, style: {background_color: "hp-blue-dark"})
      container.box(:base, height: 20, style: {background_color: "hp-blue"})
      container.box(:base, 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(:base, height: 20, style: {background_color: "hp-blue-dark",
                                               mask_mode: :fill_horizontal, valign: :bottom})
      container.box(:base, height: 20, style: {background_color: "hp-blue",
                                               mask_mode: :fill_horizontal, valign: :bottom})
      container.box(:base, 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(:base, width: 20, style: {background_color: "hp-blue-dark",
                                              mask_mode: :fill_vertical})
      container.box(:base, width: 20, style: {background_color: "hp-blue",
                                              mask_mode: :fill_vertical})
      container.box(:base, 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(:base, width: 20, style: {background_color: "hp-blue-dark",
                                              mask_mode: :fill_vertical, align: :right})
      container.box(:base, width: 20, style: {background_color: "hp-blue",
                                              mask_mode: :fill_vertical, align: :right})
      container.box(:base, 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.

Public Class Methods

new(children: [], **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?