Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Added support for spacing to smart sprite layouts. #1314

wants to merge 1 commit into from

6 participants


This makes no changes to the RowFitter calculations - it merely adds spacing around the sprites after they've already been divided into rows. As a result, this could potentially generate a suboptimal layout given the right combination of images and spacing settings, but I suspect that would be fairly unlikely in most use cases. If it is deemed to be a major issue, the RowFitter algorithm could always be optimised at a later stage.


I have been having the same issue and I would love to see/help this get merged.


Is there some news about this issue ? I would also love to this see this get merged !

@scottdavis scottdavis was assigned

I'm closing this PR because there's been too much change since it was initially submitted. Sorry, We're going to do better going forward. Hopefully, someone can resubmit the change against 1.0. Features should be submitted to the master branch, bug fixes to the stable branch.

@scottdavis has extracted sprites to a plugin and we'll be releasing that in 1.1. This needs to be patch on top of his work which should land soon.


Should be on top of the changes coming in #1771.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 8, 2013
  1. @j4james
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 4 deletions.
  1. +23 −4 lib/compass/sass_extensions/sprites/layout/smart.rb
27 lib/compass/sass_extensions/sprites/layout/smart.rb
@@ -13,17 +13,36 @@ def layout!
def calculate_positions!
fitter =
current_y = 0
+ width = 0
+ height = 0
+ # We set the last_row_spacing to a very high number initially so
+ # no extra spacing will be added to the y offset on the first row.
+ last_row_spacing = 9999!.each do |row|
current_x = 0
+ row_height = 0
+ row_spacing = 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
- = current_y
+ = current_y + extra_y
current_x += image.width
+ width = [width, current_x].max
+ row_height = [row_height, extra_y+image.height].max
+ row_spacing = [row_spacing, extra_y+image.height+image.spacing].max
- current_y += row.height
+ current_y += row_height
+ height = [height,current_y].max
+ row_spacing -= row_height
+ current_y += row_spacing
+ last_row_spacing = row_spacing
- @width = fitter.width
- @height = fitter.height
+ @width = width
+ @height = height
Something went wrong with that request. Please try again.