Class: WhirledPeas::Graphics::GridPainter
- Inherits:
-
ContainerPainter
- Object
- Painter
- ContainerPainter
- WhirledPeas::Graphics::GridPainter
- Defined in:
- lib/whirled_peas/graphics/grid_painter.rb
Constant Summary
Constants inherited from ContainerPainter
Instance Method Summary collapse
Instance Method Details
#dimensions ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/whirled_peas/graphics/grid_painter.rb', line 29 def dimensions @dimensions ||= begin num_cols = settings.num_cols num_rows = (num_children.to_f / num_cols).ceil content_width = 0 each_child do |child| if child.dimensions.outer_width > content_width content_width = child.dimensions.outer_width end end content_height = 0 each_child do |child| if child.dimensions.outer_height > content_height content_height = child.dimensions.outer_height end end ContainerDimensions.new( settings, content_width, content_height, num_cols, num_rows ) end end |
#paint(canvas, left, top, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/whirled_peas/graphics/grid_painter.rb', line 7 def paint(canvas, left, top, &block) super return unless canvas.writable? each_child.with_index do |child, index| col_index, row_index = grid_cell(index) left_offset, _ = horiz_justify_offset(child.dimensions.outer_width) top_offset, _ = vert_justify_offset(child.dimensions.outer_height) child_canvas = canvas.child( coords(left, top).content_left(col_index) + left_offset, coords(left, top).content_top(row_index) + top_offset, [dimensions.content_width, child.dimensions.outer_width].min, [dimensions.content_height, child.dimensions.outer_height].min ) child.paint( child_canvas, coords(left, top).content_left(col_index) + left_offset, coords(left, top).content_top(row_index) + top_offset, &block ) end end |