From 1b73dbfaa5c0ee2f68f4956b694d0ef0e2416e05 Mon Sep 17 00:00:00 2001 From: bordun Date: Fri, 20 Mar 2020 10:08:38 +0100 Subject: [PATCH] fix dragresize position to grid when initial position/size is not on the grid --- src/client/editor/index.js | 12 ++++++++---- src/client/ui/ui-dragresize.js | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/client/editor/index.js b/src/client/editor/index.js index b7136a44..53be7876 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -75,13 +75,17 @@ class Editor { this.widgetDragResize = new UiDragResize({}) this.widgetDragResize.on('move', (e)=>{ - var dX = Math.round((e.left - e.initLeft) / GRIDWIDTH) * GRIDWIDTH, - dY = Math.round((e.top - e.initTop) / GRIDWIDTH) * GRIDWIDTH + var left = Math.round(e.left / GRIDWIDTH) * GRIDWIDTH, + top = Math.round(e.top / GRIDWIDTH) * GRIDWIDTH + var dX = left - e.initLeft, + dY = top - e.initTop this.moveWidget(dX, dY) }) this.widgetDragResize.on('resize', (e)=>{ - var dX = Math.round((e.width - e.initWidth) / GRIDWIDTH) * GRIDWIDTH, - dY = Math.round((e.height - e.initHeight) / GRIDWIDTH) * GRIDWIDTH + var width = Math.round(e.width / GRIDWIDTH) * GRIDWIDTH, + height = Math.round(e.height / GRIDWIDTH) * GRIDWIDTH + var dX = width - e.initWidth, + dY = height - e.initHeight this.resizeWidget(dX, dY) }) diff --git a/src/client/ui/ui-dragresize.js b/src/client/ui/ui-dragresize.js index 4541d649..052fb62f 100644 --- a/src/client/ui/ui-dragresize.js +++ b/src/client/ui/ui-dragresize.js @@ -155,12 +155,14 @@ class UiDragResize extends UiWidget { updateCss(grid) { - for (var k of ['top', 'left', 'width', 'height']) { + for (let k of ['top', 'left', 'width', 'height']) { var val = this[k] if (k === 'width' || k === 'height') val = Math.max(10 * PXSCALE, val) - if (grid) val = Math.round(val / GRIDWIDTH) * GRIDWIDTH + if (grid && this.dragging.includes(k)) { + val = Math.round(val / GRIDWIDTH) * GRIDWIDTH + } this.container.style.setProperty('--' + k, val + 'rem')