Class: Arrolio::Flowables::PositionedBlock

Inherits:
Arrolio::Flowable show all
Defined in:
lib/arrolio/flowables/positioned_block.rb

Overview

Absolute-positioned container for cover-page layouts. Renders its children at a fixed (top, left) offset within the page, regardless of the normal top-down flow.

The engine treats PositionedBlock as zero-height in the flow (consumed = 0), so the next flowable continues at the same y-coordinate. The block's children are placed at page-relative coordinates computed from top and left.

Used by cover layouts to place the title border-box, the organisation footer block, and similar non-flow regions.

Instance Attribute Summary collapse

Attributes inherited from Arrolio::Flowable

#style

Instance Method Summary collapse

Methods inherited from Arrolio::Flowable

#do_split, #keep_together?, #keep_with_next?, #min_keep_height, #page_break_after?, #page_break_before?, #space_after, #space_before, #split, #splittable?

Constructor Details

#initialize(children:, top:, left:, width:, height:, style: Style::Definition.new) ⇒ PositionedBlock

children: Array of Flowable to render at the fixed position. top: Distance from the page's top edge (points). left: Distance from the page's left edge (points). width: Width of the block (points). height: Height of the block (points); content overflowing is clipped at render time.



25
26
27
28
29
30
31
32
33
# File 'lib/arrolio/flowables/positioned_block.rb', line 25

def initialize(children:, top:, left:, width:, height:,
               style: Style::Definition.new)
  super(style: style)
  @children = Array(children)
  @top = top.to_f
  @left = left.to_f
  @width = width.to_f
  @height_value = height.to_f
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



17
18
19
# File 'lib/arrolio/flowables/positioned_block.rb', line 17

def children
  @children
end

#height_valueObject (readonly)

Returns the value of attribute height_value.



17
18
19
# File 'lib/arrolio/flowables/positioned_block.rb', line 17

def height_value
  @height_value
end

#leftObject (readonly)

Returns the value of attribute left.



17
18
19
# File 'lib/arrolio/flowables/positioned_block.rb', line 17

def left
  @left
end

#topObject (readonly)

Returns the value of attribute top.



17
18
19
# File 'lib/arrolio/flowables/positioned_block.rb', line 17

def top
  @top
end

#widthObject (readonly)

Returns the value of attribute width.



17
18
19
# File 'lib/arrolio/flowables/positioned_block.rb', line 17

def width
  @width
end

Instance Method Details

#emit(x, y, _region_width, context = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/arrolio/flowables/positioned_block.rb', line 39

def emit(x, y, _region_width, context = nil)
  page_top = y + (y).abs # approximate page-top from current y
  block_y = page_top - @top - @height_value
  block_x = x + @left
  boxes = []
  cursor = block_y + @height_value
  @children.each do |child|
    child_boxes, consumed = child.emit(block_x, cursor, @width, context)
    boxes.concat(child_boxes)
    cursor -= consumed
  end
  # The block consumes zero flow height — siblings continue at y.
  [boxes, 0.0]
end

#height(_width, _context = nil) ⇒ Object



35
36
37
# File 'lib/arrolio/flowables/positioned_block.rb', line 35

def height(_width, _context = nil)
  0.0
end