Skip to content

Commit

Permalink
Port Align commands to JS API. Closes #81
Browse files Browse the repository at this point in the history
  • Loading branch information
bomberstudios committed May 30, 2019
1 parent 44f3e49 commit 3bd2a78
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 61 deletions.

This file was deleted.

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)
})
}
)
}

This file was deleted.

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)
})
}
)
}
4 changes: 2 additions & 2 deletions Sketch Commands.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
"name": "Space Horizontal",
"identifier": "spacehorizontal",
"shortcut": "",
"script": "Align/Space Horizontal.cocoascript"
"script": "Align/Space Horizontal.js"
},
{
"name": "Space Vertical",
"identifier": "spacevertical",
"shortcut": "",
"script": "Align/Space Vertical.cocoascript"
"script": "Align/Space Vertical.js"
},
{
"name": "Alpha…",
Expand Down

0 comments on commit 3bd2a78

Please sign in to comment.