Class: Arrolio::Flowables::NoteFlowable

Inherits:
ListFlowable show all
Defined in:
lib/arrolio/flowables/note_flowable.rb

Overview

Note / example callout. Two label layouts:

  • :hanging (notes) — italic label in the marker column, body wraps on the same first line (hanging indent). Implemented on ListFlowable's hanging-indent infrastructure.
  • :block (examples) — the label is a heading on its own line at the column edge ("Example:"), body flows below it indented by body_indent. Emitted sequentially: the label line's height is part of the flow, so page breaking sees the whole block.

Constant Summary collapse

BLOCK_LABEL_GAP =
6.0

Instance Attribute Summary collapse

Attributes inherited from ListFlowable

#body_indent, #item_spacing, #items, #kind, #marker_indent, #marker_width

Attributes inherited from Arrolio::Flowable

#style

Instance Method Summary collapse

Methods inherited from ListFlowable

#min_keep_height, #splittable?

Methods inherited from Arrolio::Flowable

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

Constructor Details

#initialize(label_text, body_flowables, style: Style::Definition.new, marker_width: 22.0, body_indent: 6.0, label_style: nil, label_mode: :hanging) ⇒ NoteFlowable

Returns a new instance of NoteFlowable.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/arrolio/flowables/note_flowable.rb', line 20

def initialize(label_text, body_flowables, style: Style::Definition.new,
               marker_width: 22.0, body_indent: 6.0, label_style: nil,
               label_mode: :hanging)
  @label_mode = label_mode.to_sym
  effective_label_style = label_style || style.with(font_size: style.font_size)
  if @label_mode == :block
    @block_label = TextFlowable.new(
      [InlineRun.new("#{label_text}:", style: effective_label_style)],
      style: effective_label_style
    )
    @block_body = Array(body_flowables)
    @block_indent = body_indent.to_f
    super([[nil, []]], kind: :note, style: style)
  else
    marker_run = InlineRun.new("#{label_text} ", style: effective_label_style)
    marker_flow = TextFlowable.new([marker_run], style: effective_label_style)
    super([[marker_flow, Array(body_flowables)]],
          kind: :note, style: style,
          marker_width: marker_width, body_indent: body_indent)
  end
end

Instance Attribute Details

#label_modeObject (readonly)

Returns the value of attribute label_mode.



18
19
20
# File 'lib/arrolio/flowables/note_flowable.rb', line 18

def label_mode
  @label_mode
end

Instance Method Details

#do_split(width, remaining_height, context = nil) ⇒ Object

Notes stay intact across page breaks: if the whole note does not fit, it moves to the next page. ListFlowable#do_split is not usable here — it rebuilds via self.class.new(items, ...) which does not match this constructor's signature.



58
59
60
61
62
63
64
65
# File 'lib/arrolio/flowables/note_flowable.rb', line 58

def do_split(width, remaining_height, context = nil)
  total = height(width, context)
  if total <= remaining_height
    [self, nil]
  else
    [nil, self]
  end
end

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



48
49
50
51
52
# File 'lib/arrolio/flowables/note_flowable.rb', line 48

def emit(x, y, width, context = nil)
  return block_emit(x, y, width, context) if @label_mode == :block

  super
end

#height(width, context = nil) ⇒ Object



42
43
44
45
46
# File 'lib/arrolio/flowables/note_flowable.rb', line 42

def height(width, context = nil)
  return block_height(width, context) if @label_mode == :block

  super
end