Class: Pdfrb::Layout::ContainerBox

Inherits:
Box
  • Object
show all
Defined in:
lib/pdfrb/layout/container_box.rb

Overview

A box that holds an ordered list of child boxes laid out vertically. Each child is fit in turn; if a child doesn't fit in the remaining height, fit returns false and the fitter moves to a new Frame.

Instance Attribute Summary collapse

Attributes inherited from Box

#height, #style, #width

Instance Method Summary collapse

Methods inherited from Box

#supports_position_flow?

Constructor Details

#initialize(children: []) ⇒ ContainerBox

Returns a new instance of ContainerBox.



12
13
14
15
# File 'lib/pdfrb/layout/container_box.rb', line 12

def initialize(children: [], **)
  super(**)
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



10
11
12
# File 'lib/pdfrb/layout/container_box.rb', line 10

def children
  @children
end

Instance Method Details

#draw(canvas, x, y) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/pdfrb/layout/container_box.rb', line 31

def draw(canvas, x, y)
  super
  offset_y = y
  @children.each do |child|
    child.draw(canvas, x, offset_y)
    offset_y -= child.height
  end
end

#empty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/pdfrb/layout/container_box.rb', line 40

def empty?
  @children.empty?
end

#fit?(available_width, available_height) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pdfrb/layout/container_box.rb', line 17

def fit?(available_width, available_height)
  remaining_height = available_height
  @children.each do |child|
    if child.fit?(available_width, remaining_height)
      remaining_height -= child.height
    else
      return false
    end
  end
  @width = available_width
  @height = available_height - remaining_height
  true
end