From 4c94976527283ac405d961061ac74da9cd28fd12 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 2 Jan 2020 18:20:08 -0800 Subject: [PATCH] Random fixes (#57) --- src/index.tsx | 230 ++++++++++++++++++++++++++----------------------- src/styles.css | 24 ++---- 2 files changed, 126 insertions(+), 128 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 67dea4fb..ce2dd4d2 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -279,11 +279,11 @@ function generateDraw( const [x1, y1, x2, y2, x3, y3, x4, y4] = getArrowPoints(element); const shapes = [ // \ - generator.line(x3, y3, x2, y2), + generator.line(x3, y3, x2, y2, { stroke: itemStrokeColor }), // ----- - generator.line(x1, y1, x2, y2), + generator.line(x1, y1, x2, y2, { stroke: itemStrokeColor }), // / - generator.line(x4, y4, x2, y2) + generator.line(x4, y4, x2, y2, { stroke: itemStrokeColor }) ]; element.draw = (rc, context) => { @@ -384,9 +384,9 @@ class App extends React.Component<{}, AppState> { exportBackground: false, exportVisibleOnly: true, exportPadding: 10, - itemStrokeColor: "#000", - itemBackgroundColor: "#FFF", - viewBgColor: "#FFF" + itemStrokeColor: "#000000", + itemBackgroundColor: "#ffffff", + viewBgColor: "#ffffff" }; private onKeyDown = (event: KeyboardEvent) => { @@ -454,82 +454,15 @@ class App extends React.Component<{}, AppState> { public render() { return ( <> -
- - - - - - - (padding: - { - this.setState({ exportPadding: Number(e.target.value) }); - }} - disabled={!this.state.exportVisibleOnly} - /> - px) -
+
+ Shapes + {this.renderOption({ type: "rectangle", children: "Rectangle" })} + {this.renderOption({ type: "ellipse", children: "Ellipse" })} + {this.renderOption({ type: "arrow", children: "Arrow" })} + {this.renderOption({ type: "text", children: "Text" })} + {this.renderOption({ type: "selection", children: "Selection" })} +
{ e.clipboardData.setData( "text/plain", @@ -573,15 +506,10 @@ class App extends React.Component<{}, AppState> { e.preventDefault(); }} > - {this.renderOption({ type: "rectangle", children: "Rectangle" })} - {this.renderOption({ type: "ellipse", children: "Ellipse" })} - {this.renderOption({ type: "arrow", children: "Arrow" })} - {this.renderOption({ type: "text", children: "Text" })} - {this.renderOption({ type: "selection", children: "Selection" })} { const x = e.clientX - (e.target as HTMLElement).offsetLeft; const y = e.clientY - (e.target as HTMLElement).offsetTop; @@ -746,9 +674,114 @@ class App extends React.Component<{}, AppState> { }} />
+
+ Colors + + + +
+
+ Export + + + + (padding: + { + this.setState({ exportPadding: Number(e.target.value) }); + }} + disabled={!this.state.exportVisibleOnly} + /> + px) +
); } + componentDidUpdate() { + const fillStyle = context.fillStyle; + context.fillStyle = this.state.viewBgColor; + context.fillRect(-0.5, -0.5, canvas.width, canvas.height); + context.fillStyle = fillStyle; + + elements.forEach(element => { + element.draw(rc, context); + if (element.isSelected) { + const margin = 4; + + const elementX1 = getElementAbsoluteX1(element); + const elementX2 = getElementAbsoluteX2(element); + const elementY1 = getElementAbsoluteY1(element); + const elementY2 = getElementAbsoluteY2(element); + const lineDash = context.getLineDash(); + context.setLineDash([8, 4]); + context.strokeRect( + elementX1 - margin, + elementY1 - margin, + elementX2 - elementX1 + margin * 2, + elementY2 - elementY1 + margin * 2 + ); + context.setLineDash(lineDash); + } + }); + } } const rootElement = document.getElementById("root"); @@ -763,29 +796,6 @@ context.translate(0.5, 0.5); function drawScene() { ReactDOM.render(, rootElement); - - context.clearRect(-0.5, -0.5, canvas.width, canvas.height); - - elements.forEach(element => { - element.draw(rc, context); - if (element.isSelected) { - const margin = 4; - - const elementX1 = getElementAbsoluteX1(element); - const elementX2 = getElementAbsoluteX2(element); - const elementY1 = getElementAbsoluteY1(element); - const elementY2 = getElementAbsoluteY2(element); - const lineDash = context.getLineDash(); - context.setLineDash([8, 4]); - context.strokeRect( - elementX1 - margin, - elementY1 - margin, - elementX2 - elementX1 + margin * 2, - elementY2 - elementY1 + margin * 2 - ); - context.setLineDash(lineDash); - } - }); } drawScene(); diff --git a/src/styles.css b/src/styles.css index 7c3721cf..7be6572b 100644 --- a/src/styles.css +++ b/src/styles.css @@ -3,24 +3,12 @@ font-family: "Virgil"; src: url("https://uploads.codesandbox.io/uploads/user/ed077012-e728-4a42-8395-cbd299149d62/AflB-FG_Virgil.ttf"); } - -.exportWrapper { - margin-bottom: 10px; - display: flex; - align-items: center; -} -.exportWrapper label { - display: flex; - align-items: center; - margin: 0 5px; -} - -.exportWrapper button { +label { margin-right: 10px; } - -.exportWrapper input[type="number"] { - width: 40px; - padding: 2px; - margin-left: 10px; +input[type="number"] { + width: 30px; +} +input { + margin-right: 5px; }