class WhirledPeas::Graphics::BoxPainter

Public Instance Methods

dimensions() click to toggle source
# File lib/whirled_peas/graphics/box_painter.rb, line 24
def dimensions
  @dimensions ||= begin
    content_width = 0
    content_height = 0
    if settings.horizontal_flow?
      each_child do |child|
        content_width += child.dimensions.outer_width
        if child.dimensions.outer_height > content_height
          content_height = child.dimensions.outer_height
        end
      end
    else
      each_child do |child|
        if child.dimensions.outer_width > content_width
          content_width = child.dimensions.outer_width
        end
        content_height += child.dimensions.outer_height
      end
    end
    ContainerDimensions.new(settings, content_width, content_height)
  end
end
each_child(&block) click to toggle source
Calls superclass method
# File lib/whirled_peas/graphics/box_painter.rb, line 47
def each_child(&block)
  if settings.reverse_flow?
    children.reverse.each(&block)
  else
    super
  end
end
paint(canvas, left, top, &block) click to toggle source
Calls superclass method
# File lib/whirled_peas/graphics/box_painter.rb, line 7
def paint(canvas, left, top, &block)
  super
  canvas_coords = coords(left, top)
  content_canvas = canvas.child(
    canvas_coords.content_left,
    canvas_coords.content_top,
    dimensions.content_width,
    dimensions.content_height
  )
  return unless content_canvas.writable?
  if settings.horizontal_flow?
    paint_horizontally(content_canvas, canvas_coords, &block)
  else
    paint_vertically(content_canvas, canvas_coords, &block)
  end
end

Private Instance Methods

paint_horizontally(canvas, canvas_coords, &block) click to toggle source
# File lib/whirled_peas/graphics/box_painter.rb, line 57
def paint_horizontally(canvas, canvas_coords, &block)
  stroke_left = canvas_coords.offset_content_left
  stroke_top = canvas_coords.offset_content_top
  children_width = 0
  each_child { |c| children_width += c.dimensions.outer_width }
  left_offset, spacing_offset = horiz_justify_offset(children_width)
  stroke_left += left_offset
  each_child do |child|
    top_offset, _ = vert_justify_offset(child.dimensions.outer_height)
    child_width = child.dimensions.outer_width
    child_canvas = canvas.child(
      stroke_left,
      stroke_top + top_offset,
      child_width,
      child.dimensions.outer_height
    )
    child.paint(child_canvas, stroke_left, stroke_top + top_offset, &block)
    stroke_left += child_width + spacing_offset
  end
end
paint_vertically(canvas, canvas_coords, &block) click to toggle source
# File lib/whirled_peas/graphics/box_painter.rb, line 78
def paint_vertically(canvas, canvas_coords, &block)
  stroke_left = canvas_coords.offset_content_left
  stroke_top = canvas_coords.offset_content_top
  children_height = 0
  each_child { |c| children_height += c.dimensions.outer_height }
  top_offset, spacing_offset = vert_justify_offset(children_height)
  stroke_top += top_offset
  each_child do |child|
    left_offset, _ = horiz_justify_offset(child.dimensions.outer_width)
    child_height = child.dimensions.outer_height
    child_canvas = canvas.child(
      stroke_left + left_offset,
      stroke_top ,
      child.dimensions.outer_width,
      child_height
    )
    child.paint(child_canvas, stroke_left + left_offset, stroke_top, &block)
    stroke_top += child_height + spacing_offset
  end
end