Class: Arrolio::Flowables::TwoColumnBlock
- Inherits:
-
Arrolio::Flowable
- Object
- Arrolio::Flowable
- Arrolio::Flowables::TwoColumnBlock
- Defined in:
- lib/arrolio/flowables/two_column_block.rb
Overview
Two-column layout for a cover-page header. Renders left and right content blocks side-by-side without table borders, matching the reference PDF's two-column fo:table layout. Used by flow builders to place flavor-specific cover text in two columns.
Instance Attribute Summary collapse
-
#left_flowables ⇒ Object
readonly
Returns the value of attribute left_flowables.
-
#left_ratio ⇒ Object
readonly
Returns the value of attribute left_ratio.
-
#right_flowables ⇒ Object
readonly
Returns the value of attribute right_flowables.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Instance Method Summary collapse
- #emit(x, y, width, context = nil) ⇒ Object
- #height(width, context = nil) ⇒ Object
-
#initialize(left_flowables:, right_flowables:, left_ratio: 0.5, style: Style::Definition.new) ⇒ TwoColumnBlock
constructor
left_flowables:Array of TextFlowable for the left column.
Methods inherited from Arrolio::Flowable
#do_split, #keep_together?, #keep_with_next?, #page_break_after?, #page_break_before?, #space_after, #space_before, #split, #splittable?
Constructor Details
#initialize(left_flowables:, right_flowables:, left_ratio: 0.5, style: Style::Definition.new) ⇒ TwoColumnBlock
left_flowables: Array of TextFlowable for the left column.
right_flowables: Array of TextFlowable for the right column.
left_ratio: Fraction of width for the left column (default 0.5).
15 16 17 18 19 20 21 |
# File 'lib/arrolio/flowables/two_column_block.rb', line 15 def initialize(left_flowables:, right_flowables:, left_ratio: 0.5, style: Style::Definition.new) super(style: style) @left_flowables = Array(left_flowables) @right_flowables = Array(right_flowables) @left_ratio = left_ratio.to_f end |
Instance Attribute Details
#left_flowables ⇒ Object (readonly)
Returns the value of attribute left_flowables.
10 11 12 |
# File 'lib/arrolio/flowables/two_column_block.rb', line 10 def left_flowables @left_flowables end |
#left_ratio ⇒ Object (readonly)
Returns the value of attribute left_ratio.
10 11 12 |
# File 'lib/arrolio/flowables/two_column_block.rb', line 10 def left_ratio @left_ratio end |
#right_flowables ⇒ Object (readonly)
Returns the value of attribute right_flowables.
10 11 12 |
# File 'lib/arrolio/flowables/two_column_block.rb', line 10 def right_flowables @right_flowables end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
10 11 12 |
# File 'lib/arrolio/flowables/two_column_block.rb', line 10 def style @style end |
Instance Method Details
#emit(x, y, width, context = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/arrolio/flowables/two_column_block.rb', line 31 def emit(x, y, width, context = nil) left_w = width * @left_ratio right_w = width * (1.0 - @left_ratio) right_x = x + left_w boxes = [] left_cursor = y @left_flowables.each do |f| fboxes, consumed = f.emit(x, left_cursor, left_w, context) boxes.concat(fboxes) left_cursor -= consumed end right_cursor = y @right_flowables.each do |f| fboxes, consumed = f.emit(right_x, right_cursor, right_w, context) boxes.concat(fboxes) right_cursor -= consumed end consumed = [y - left_cursor, y - right_cursor].max [boxes, consumed] end |
#height(width, context = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/arrolio/flowables/two_column_block.rb', line 23 def height(width, context = nil) left_w = width * @left_ratio right_w = width * (1.0 - @left_ratio) left_h = @left_flowables.sum { |f| f.height(left_w, context) } right_h = @right_flowables.sum { |f| f.height(right_w, context) } [left_h, right_h].max end |