From 0406d1b261a46a8bd2deaaa05e943618513c7fc4 Mon Sep 17 00:00:00 2001 From: Matthew Lean Date: Sun, 24 May 2020 03:05:37 -0700 Subject: [PATCH 1/9] Draw gridlines --- src/scripts/draw.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/scripts/draw.js b/src/scripts/draw.js index a732efc..e2f1ae5 100644 --- a/src/scripts/draw.js +++ b/src/scripts/draw.js @@ -1,5 +1,5 @@ const commands = require('commands') -const { Color, Rectangle } = require('scenegraph') +const { Color, Line, Rectangle } = require('scenegraph') const { editDocument } = require('application') /** @@ -19,14 +19,13 @@ const draw = (calcState) => { topMargin, leftMargin, } = calcState - const color = new Color('#00ffff', 0.5) const newItems = [] const canvas = new Rectangle() canvas.name = 'Canvas' canvas.width = canvasWidth canvas.height = canvasHeight - canvas.fill = color + canvas.fill = new Color('#00ff00', 0.25) newItems.push(canvas) selection.insertionParent.addChild(canvas) @@ -36,11 +35,29 @@ const draw = (calcState) => { const col = new Rectangle() col.width = colWidth col.height = gridHeight - col.fill = color + col.fill = new Color('#00ffff', 0.5) col.name = `Column ${i + 1}` newItems.push(col) selection.insertionParent.addChild(col) + const gridlineA = new Line() + gridlineA.setStartEnd(pos.x, 0, pos.x, canvasHeight) + gridlineA.strokeEnabled = true + gridlineA.strokeWidth = 1 + gridlineA.stroke = new Color('#ff4fff') + gridlineA.name = 'Gridline' + newItems.push(gridlineA) + selection.insertionParent.addChild(gridlineA) + + const gridlineB = new Line() + gridlineB.setStartEnd(pos.x + colWidth, 0, pos.x + colWidth, canvasHeight) + gridlineB.strokeEnabled = true + gridlineB.strokeWidth = 1 + gridlineB.stroke = new Color('#ff4fff') + gridlineB.name = 'Gridline' + newItems.push(gridlineB) + selection.insertionParent.addChild(gridlineB) + if (pos.x > 0 || pos.y > 0) { col.moveInParentCoordinates(pos.x, pos.y) } @@ -66,21 +83,6 @@ const draw = (calcState) => { } canvas.visible = false - - // commands.alignHorizontalCenter() - // commands.alignVerticalCenter() - - // const newLine = new Line() - // newLine.setStartEnd(0, 0, 500, 500) - // newLine.strokeEnabled = true - // newLine.stroke = new Color('#ff00ff') - // newLine.strokeWidth = 3 - // // console.log(selection.items[0]) - // console.log(selection.editContext) - // console.log(selection.editContext.children) - // selection.insertionParent.addChild(newLine) - // // selection.editContext.addChild(newLine) - // selection.items = [newLine] }) } From 68b8fd011b9b792f71962697a528d7c93b2e5277 Mon Sep 17 00:00:00 2001 From: Matthew Lean Date: Sun, 24 May 2020 03:34:09 -0700 Subject: [PATCH 2/9] Add draw options --- src/components/Panel.jsx | 29 ++++++++++- src/scripts/draw.js | 105 ++++++++++++++++++++++----------------- 2 files changed, 87 insertions(+), 47 deletions(-) diff --git a/src/components/Panel.jsx b/src/components/Panel.jsx index 06e9f1a..8907025 100644 --- a/src/components/Panel.jsx +++ b/src/components/Panel.jsx @@ -38,6 +38,9 @@ const Panel = ({ selectionAmount, validSelection }) => { const [topBottomMarginsSum, setTopBottomMarginsSum] = useState(0) const [rightLeftMarginsSum, setRightLeftMarginsSum] = useState(0) + const [drawFields, setDrawFields] = useState(true) + const [drawGridlines, setDrawGridlines] = useState(true) + const [isCalcReady, setIsCalcReady] = useState(false) const calcState = { @@ -79,6 +82,8 @@ const Panel = ({ selectionAmount, validSelection }) => { setRightMargin(0) setBottomMargin(0) setLeftMargin(0) + setDrawFields(true) + setDrawGridlines(true) resetStats() } @@ -460,13 +465,35 @@ const Panel = ({ selectionAmount, validSelection }) => {
+ +