-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Align commands to JS API. Closes #81
- Loading branch information
1 parent
44f3e49
commit 3bd2a78
Showing
5 changed files
with
64 additions
and
61 deletions.
There are no files selected for viewing
29 changes: 0 additions & 29 deletions
29
Sketch Commands.sketchplugin/Contents/Sketch/Align/Space Horizontal.cocoascript
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
Sketch Commands.sketchplugin/Contents/Sketch/Align/Space Horizontal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Distributes the selected elements horizontally, with the same distance beetween them. | ||
var onRun = function(context) { | ||
var sketch = require('sketch') | ||
var Document = sketch.Document | ||
var UI = sketch.UI | ||
var document = Document.getSelectedDocument() | ||
var selection = document.selectedLayers | ||
|
||
function sort_by_position(a,b){ | ||
return a.frame.x - b.frame.x | ||
} | ||
|
||
UI.getInputFromUser( | ||
"Spacing", | ||
{ | ||
initialValue: 10, | ||
}, | ||
(err, value) => { | ||
if (err) { | ||
return | ||
} | ||
var sorted_selection = selection.layers.sort(sort_by_position) | ||
var first_element = sorted_selection[0] | ||
var left_position = first_element.frame.x | ||
sorted_selection.forEach(layer => { | ||
layer.frame.x = left_position | ||
left_position = layer.frame.x + layer.frame.width + parseInt(value) | ||
}) | ||
} | ||
) | ||
} |
30 changes: 0 additions & 30 deletions
30
Sketch Commands.sketchplugin/Contents/Sketch/Align/Space Vertical.cocoascript
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
Sketch Commands.sketchplugin/Contents/Sketch/Align/Space Vertical.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Distributes the selected elements vertically, with the same distance beetween them. | ||
var onRun = function(context) { | ||
var sketch = require('sketch') | ||
var Document = sketch.Document | ||
var UI = sketch.UI | ||
var document = Document.getSelectedDocument() | ||
var selection = document.selectedLayers | ||
|
||
function sort_by_position(a,b){ | ||
return a.frame.x - b.frame.x | ||
} | ||
|
||
UI.getInputFromUser( | ||
"Spacing", | ||
{ | ||
initialValue: 10, | ||
}, | ||
(err, value) => { | ||
if (err) { | ||
return | ||
} | ||
var sorted_selection = selection.layers.sort(sort_by_position) | ||
var first_element = sorted_selection[0] | ||
var top_position = first_element.frame.y | ||
sorted_selection.forEach(layer => { | ||
layer.frame.y = top_position | ||
top_position = layer.frame.y + layer.frame.height + parseInt(value) | ||
}) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters