5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/sprite_factory/layout/horizontal.rb', line 5
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) i[:cssx] = x + hmargin i[:x] = i[:cssx] + hpadding end
if height
i[:cssh] = height
i[:cssy] = 0
i[:y] = 0 + (height - i[:height]) / 2
else
i[:cssh] = i[:height] + (2 * vpadding) i[:cssy] = (max_height - i[:cssh]) / 2 i[:y] = i[:cssy] + vpadding end
x += i[:cssw] + 2 * hmargin
end
{ :width => x, :height => max_height }
end
|