Skip to content

Commit

Permalink
Fixed for Sketch 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bomberstudios committed Apr 10, 2015
1 parent 9a9c0cc commit e46b837
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Fit to Width.sketchplugin
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Fit to Width (cmd shift 1)
// This plugin will zoom out to fit the canvas' contents in the window,
// but maximizing the width only
margin = 50
view = [doc currentView]

Expand All @@ -12,11 +14,11 @@ layerRect = [view totalRectForLayers:layers]
ratio = window_width / window_height

// Set rect height to new ratio
layerRect.setHeight(layerRect.width() / ratio)
layerRect.size.height = layerRect.size.width / ratio

layerRect.setX(layerRect.x() - margin)
layerRect.setY(layerRect.y() - margin)
layerRect.setWidth(layerRect.width() + margin*2)
layerRect.setHeight(layerRect.height() + margin*2)
layerRect.origin.x -= margin
layerRect.origin.y -= margin
layerRect.size.width += margin*2
layerRect.size.height += margin*2

[view zoomToFitRect:layerRect]

0 comments on commit e46b837

Please sign in to comment.