Class: Pdfrb::Layout::ContainerBox
- 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
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Attributes inherited from Box
Instance Method Summary collapse
- #draw(canvas, x, y) ⇒ Object
- #empty? ⇒ Boolean
- #fit?(available_width, available_height) ⇒ Boolean
-
#initialize(children: []) ⇒ ContainerBox
constructor
A new instance of ContainerBox.
Methods inherited from Box
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
#children ⇒ Object (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
40 41 42 |
# File 'lib/pdfrb/layout/container_box.rb', line 40 def empty? @children.empty? end |
#fit?(available_width, available_height) ⇒ 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 |