Skip to content

Commit

Permalink
Did it
Browse files Browse the repository at this point in the history
  • Loading branch information
Volorf committed Apr 5, 2017
1 parent 893160c commit a3e5baf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
35 changes: 31 additions & 4 deletions gridy.sketchplugin/Contents/Sketch/gridy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ function createHorizontalGuides(context) {
superMainFunc(context, "horizontal")
}

function removeAllGuides(context) {
superMainFunc(context, "remove")
}

function superMainFunc (context, whatWeDo) {

var doc = context.document,
Expand All @@ -14,8 +18,12 @@ function superMainFunc (context, whatWeDo) {
fontSizeSelectedTextLayer = 0,
sketch = context.api(),
layerWidth = layer.frame().width(),
layerHeight = layer.frame().height(),
layerXMin = layer.frame().x(),
layerXMax = layer.frame().x() + layerWidth;
layerYMin = layer.frame().y(),
layerXMax = layerXMin + layerWidth,
layerYMax = layerYMin + layerHeight,
target = [[doc currentPage] currentArtboard] || [doc currentPage];

if (selection.length == 0) {
doc.showMessage("You should select at least one text layer");
Expand All @@ -36,7 +44,6 @@ function superMainFunc (context, whatWeDo) {
}

function createVeticalGuides () {
var target = [[doc currentPage] currentArtboard] || [doc currentPage];
var input = Number(doc.askForUserInput_initialValue("Amount of sections", "1"));
var unit = layerWidth / input
[[target horizontalRulerData] addGuideWithValue:layerXMin]
Expand All @@ -46,14 +53,34 @@ function superMainFunc (context, whatWeDo) {
[[target horizontalRulerData] addGuideWithValue: layerXMin + (unit * i)]
}
}
doc.showMessage("Vertical guidelines have been created")
}

function createHorizontalGuides () {

var input = Number(doc.askForUserInput_initialValue("Amount of sections", "1"));
var unit = layerHeight / input
[[target verticalRulerData] addGuideWithValue:layerYMin]
[[target verticalRulerData] addGuideWithValue:layerYMax]
if (input > 1) {
for (var i = 1; i < input; i++) {
[[target verticalRulerData] addGuideWithValue: layerYMin + (unit * i)]
}
}
doc.showMessage("Horizontal guidelines have been created");
}

function removeAllGuides () {

var countVertical = [[target verticalRulerData] numberOfGuides]
var countHorizontal = [[target horizontalRulerData] numberOfGuides]
while(countVertical > 0 ) {
[[target verticalRulerData] removeGuideAtIndex:0]
var countVertical = [[target verticalRulerData] numberOfGuides]
}
while(countHorizontal > 0 ) {
[[target horizontalRulerData] removeGuideAtIndex:0]
var countHorizontal = [[target horizontalRulerData] numberOfGuides]
}
doc.showMessage("Guidelines have been removed");
}

}
22 changes: 19 additions & 3 deletions gridy.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,32 @@
"bundleVersion": 1,
"commands": [
{
"name": "Vertical guidelines",
"name": "Vertical guides",
"identifier": "verticalGuides",
"shortcut": "ctrl shift alt v",
"shortcut": "ctrl alt v",
"script": "gridy.js",
"handler": "createVerticalGuides"
},
{
"name": "Horizontal guides",
"identifier": "horizontalGuides",
"shortcut": "ctrl alt h",
"script": "gridy.js",
"handler": "createHorizontalGuides"
},
{
"name": "Remove all guides",
"identifier": "allGuides",
"shortcut": "ctrl alt r",
"script": "gridy.js",
"handler": "removeAllGuides",
}
],
"menu": {
"items": [
"verticalGuides"
"verticalGuides",
"horizontalGuides",
"allGuides"
]
}
}

0 comments on commit a3e5baf

Please sign in to comment.