Skip to content

Commit

Permalink
Handle rotated layers correctly.
Browse files Browse the repository at this point in the history
Fixes #10.
  • Loading branch information
PEZ committed Feb 10, 2017
1 parent f03c0de commit f12d6ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Distributor.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
]
},
"identifier" : "com.betterthantomorrow.sketch.distributor",
"version" : "1.0.2.2",
"version" : "1.0.3",
"description" : "Distribute selected objects vertically or horizontally with exact spacing.",
"authorEmail" : "pez@pezius.com",
"name" : "Distributor"
Expand Down
13 changes: 8 additions & 5 deletions Distributor.sketchplugin/Contents/Sketch/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ var Distributor = {
return label;
},

trimmedLayer: function(layer) {
return MSSliceTrimming.trimmedRectForLayerAncestry(MSImmutableLayerAncestry.ancestryWithMSLayer(layer));
},

createChoices: function(msg) {
var viewBox = [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[viewBox setTitle:""];
Expand Down Expand Up @@ -103,20 +107,19 @@ var Distributor = {
formatter = [[NSNumberFormatter alloc] init],
spacing = [formatter numberFromString:spacingString];

// @TODO: Find out how to get a trimmed bounding box for the the layer, instead of [layer rect]
if (spacing != null) {
if (String(dimension) === "Vertically") {
var loopV = [sortedByTop objectEnumerator];
while (layer = [loopV nextObject]) {
[[layer frame] setTop:(top + ([[layer frame] top] - CGRectGetMinY([layer rect])))];
top = CGRectGetMinY([layer rect]) + CGRectGetHeight([layer rect]) + spacing;
[[layer frame] setTop:(top + ([[layer frame] top] - CGRectGetMinY(Distributor.trimmedLayer(layer))))];
top = CGRectGetMinY(Distributor.trimmedLayer(layer)) + CGRectGetHeight(Distributor.trimmedLayer(layer)) + spacing;
});
}
else {
var loopH = [sortedByLeft objectEnumerator];
while (layer = [loopH nextObject]) {
[[layer frame] setLeft:(left + ([[layer frame] left] - CGRectGetMinX([layer rect])))];
left = CGRectGetMinX([layer rect]) + CGRectGetWidth([layer rect]) + spacing;
[[layer frame] setLeft:(left + ([[layer frame] left] - CGRectGetMinX(Distributor.trimmedLayer(layer))))];
left = CGRectGetMinX(Distributor.trimmedLayer(layer)) + CGRectGetWidth(Distributor.trimmedLayer(layer)) + spacing;
});
}
}
Expand Down

0 comments on commit f12d6ab

Please sign in to comment.