From 520e79ff20a1bad9d3433daa456ebc92f01cb2a8 Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Tue, 29 Oct 2013 11:16:03 -0500 Subject: [PATCH] Consider spacing on smart layout. Improves #1303 Fixes #718 --- .../sass_extensions/sprites/layout/smart.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/compass/sass_extensions/sprites/layout/smart.rb b/lib/compass/sass_extensions/sprites/layout/smart.rb index 14bfb29b00..e2cc75bb83 100644 --- a/lib/compass/sass_extensions/sprites/layout/smart.rb +++ b/lib/compass/sass_extensions/sprites/layout/smart.rb @@ -13,14 +13,29 @@ def layout! def calculate_positions! fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images) current_y = 0 + width = 0 + height = 0 + last_row_spacing = 9999 fitter.fit!.each do |row| current_x = 0 + current_x = 0 + row_height = 0 row.images.each_with_index do |image, index| + extra_y = [image.spacing - last_row_spacing,0].max + if index > 0 + last_image = row.images[index-1] + current_x += [image.spacing, last_image.spacing].max + end image.left = current_x - image.top = current_y + image.top = current_y + extra_y current_x += image.width + width = [width, current_x].max + row_height = [row_height, extra_y + image.height + image.spacing].max end current_y += row.height + height = [height, current_y].max + last_row_spacing = row_height - row.height + current_y += last_row_spacing end @width = fitter.width @height = fitter.height