Sha256: f4c984e1388b728d384aec4a0b9b04c0bde7bd692b3aa38e75efa819a57d97a8

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

module SpriteFactory
  module Layout
    module Horizontal

      def self.layout(images, options = {})
        width      = options[:width]
        height     = options[:height]
        hpadding   = options[:hpadding] || 0
        vpadding   = options[:vpadding] || 0
        max_height = height || ((2 * vpadding) + images.map{|i| i[:height]}.max)
        x = 0
        images.each do |i|

          if width
            i[:cssw] = width
            i[:cssx] = x
            i[:x]    = x + (width - i[:width]) / 2
          else
            i[:cssw] = i[:width]  + (2 * hpadding)   # image width plus padding
            i[:cssx] = x                             # anchored at x
            i[:x] = i[:cssx] + hpadding              # image drawn offset to account for padding
          end

          if height
            i[:cssh] = height
            i[:cssy] = 0
            i[:y]    = 0 + (height - i[:height]) / 2
          else
            i[:cssh] = i[:height] + (2 * vpadding)   # image height plus padding
            i[:cssy] = (max_height - i[:cssh]) / 2   # centered vertically
            i[:y]    = i[:cssy] + vpadding           # image drawn offset to account for padding
          end

          x = x + i[:cssw]

        end 
        { :width  => x, :height => max_height }
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sprite-factory-1.4.2 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.4.1 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.3.0 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.2.0 lib/sprite_factory/layout/horizontal.rb