Sha256: 3c681d9c0eecba3ea587ad27623003169cd2c9c8e09c7db6dcdbf588070c0027

Contents?: true

Size: 1.4 KB

Versions: 18

Compression:

Stored size: 1.4 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
        hmargin    = options[:hmargin]  || 0
        vmargin    = options[:vmargin]  || 0
        max_height = height || (2 *(vpadding + vmargin) + 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 + hmargin                   # 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 += i[:cssw] + 2 * hmargin

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

    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
sprite-factory-1.7.1 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.7 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.6.2 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.6.1 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.4.5 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.4.4 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.4.3 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.4.2 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.4.1 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.3 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.2 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.1 lib/sprite_factory/layout/horizontal.rb
sprite-factory-custom-1.6.0 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.6.0 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.5.3 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.5.2 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.5.1 lib/sprite_factory/layout/horizontal.rb
sprite-factory-1.5.0 lib/sprite_factory/layout/horizontal.rb