Class: Pdfrb::Layout::Box
- Inherits:
-
Object
- Object
- Pdfrb::Layout::Box
- Defined in:
- lib/pdfrb/layout/box.rb
Overview
Base class for all layout boxes. A Box has a width, height, and content; it knows how to fit itself into a Frame region and how to draw onto a Canvas at a given (x, y) location.
Subclasses override fit (compute height for given width) and
draw_content (render to canvas).
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#draw(canvas, x, y) ⇒ Object
Draw this box at (x, y) on
canvas. - #empty? ⇒ Boolean
-
#fit?(_available_width, _available_height) ⇒ Boolean
Fit this box into the given available (width, height) region.
-
#initialize(width: 0, height: 0, style: Style.new(:base)) ⇒ Box
constructor
A new instance of Box.
- #supports_position_flow? ⇒ Boolean
Constructor Details
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
12 13 14 |
# File 'lib/pdfrb/layout/box.rb', line 12 def height @height end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
12 13 14 |
# File 'lib/pdfrb/layout/box.rb', line 12 def style @style end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
12 13 14 |
# File 'lib/pdfrb/layout/box.rb', line 12 def width @width end |
Instance Method Details
#draw(canvas, x, y) ⇒ Object
Draw this box at (x, y) on canvas. Subclasses override
draw_content.
29 30 31 32 |
# File 'lib/pdfrb/layout/box.rb', line 29 def draw(canvas, x, y) draw_background(canvas, x, y) draw_content(canvas, x, y) end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/pdfrb/layout/box.rb', line 38 def empty? false end |
#fit?(_available_width, _available_height) ⇒ Boolean
Fit this box into the given available (width, height) region. Returns true if it fits (sets @height); false otherwise. Subclasses override.
23 24 25 |
# File 'lib/pdfrb/layout/box.rb', line 23 def fit?(_available_width, _available_height) true end |
#supports_position_flow? ⇒ Boolean
34 35 36 |
# File 'lib/pdfrb/layout/box.rb', line 34 def supports_position_flow? false end |