Skip to content

Added support for spacing to smart sprite layouts. #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions lib/compass/sass_extensions/sprites/layout/smart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,36 @@ def layout!
def calculate_positions!
fitter = ::Compass::SassExtensions::Sprites::RowFitter.new(@images)
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
fitter.fit!.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
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].max
row_spacing = [row_spacing, extra_y+image.height+image.spacing].max
end
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
end
@width = fitter.width
@height = fitter.height
@width = width
@height = height
end

end
Expand Down