editor: fix moving/resing widgets inside folders when using percent units
This commit is contained in:
parent
045be39e87
commit
79c04cc69a
2 changed files with 19 additions and 7 deletions
|
|
@ -3,7 +3,7 @@ import {updateWidget, incrementWidget} from './data-workers.mjs'
|
|||
import {diff, diffToWidget} from './diff.mjs'
|
||||
import widgetManager from '../managers/widgets.mjs'
|
||||
import {deepCopy} from '../utils.mjs'
|
||||
import {defaults} from '../widgets/index.mjs'
|
||||
import {defaults, widgets} from '../widgets/index.mjs'
|
||||
import UiSelectArea from '../ui/ui-selectarea.mjs'
|
||||
import UiInspector from '../ui/ui-inspector.mjs'
|
||||
import UiTree from '../ui/ui-tree.mjs'
|
||||
|
|
@ -905,6 +905,17 @@ class Editor {
|
|||
|
||||
}
|
||||
|
||||
/* Utility function to retrieve the first sizable node */
|
||||
getWidgetParentContainer(widget) {
|
||||
|
||||
while (widget.parent instanceof widgets.folder) {
|
||||
widget = widget.parent
|
||||
}
|
||||
|
||||
return widget.container.parentNode
|
||||
|
||||
}
|
||||
|
||||
resizeWidget(deltaW, deltaH) {
|
||||
|
||||
if (!this.selectedWidgets.length) return
|
||||
|
|
@ -934,7 +945,7 @@ class Editor {
|
|||
if (deltaW !== 0 && w.props.width !== undefined && w.parent.getProp('layout') !== 'vertical') {
|
||||
var newWidth = Math.max(nW, GRIDWIDTH) / PXSCALE
|
||||
if (typeof w.props.width === 'string' && w.props.width.indexOf('%') > -1) {
|
||||
w.props.width = (100 * PXSCALE * newWidth / w.container.parentNode.offsetWidth).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
w.props.width = (100 * PXSCALE * newWidth / this.getWidgetParentContainer(w).offsetWidth).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
} else {
|
||||
w.props.width = newWidth
|
||||
}
|
||||
|
|
@ -943,7 +954,7 @@ class Editor {
|
|||
if (this.selectedWidgets.length > 1) {
|
||||
var newLeft = Math.max(nL, GRIDWIDTH) / PXSCALE
|
||||
if (typeof w.props.left === 'string' && w.props.left.indexOf('%') > -1) {
|
||||
w.props.left = (100 * PXSCALE * newLeft / w.container.parentNode.offsetWidth).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
w.props.left = (100 * PXSCALE * newLeft / this.getWidgetParentContainer(w).offsetWidth).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
} else if (w.props.left !== 'auto'){
|
||||
w.props.left = newLeft
|
||||
}
|
||||
|
|
@ -955,7 +966,7 @@ class Editor {
|
|||
if (deltaH !== 0 && w.props.height !== undefined && w.parent.getProp('layout') !== 'horizontal') {
|
||||
var newHeight = Math.max(nH, GRIDWIDTH) / PXSCALE
|
||||
if (typeof w.props.height === 'string' && w.props.height.indexOf('%') > -1) {
|
||||
w.props.height = (100 * PXSCALE * newHeight / w.container.parentNode.offsetHeight).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
w.props.height = (100 * PXSCALE * newHeight / this.getWidgetParentContainer(w).offsetHeight).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
} else {
|
||||
w.props.height = newHeight
|
||||
}
|
||||
|
|
@ -964,7 +975,7 @@ class Editor {
|
|||
if (this.selectedWidgets.length > 1) {
|
||||
var newTop = Math.max(nT, GRIDWIDTH) / PXSCALE
|
||||
if (typeof w.props.top === 'string' && w.props.top.indexOf('%') > -1) {
|
||||
w.props.top = (100 * PXSCALE * newTop / w.container.parentNode.offsetHeight).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
w.props.top = (100 * PXSCALE * newTop / this.getWidgetParentContainer(w).offsetHeight).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
} else if (w.props.top !== 'auto'){
|
||||
w.props.top = newTop
|
||||
}
|
||||
|
|
@ -998,13 +1009,13 @@ class Editor {
|
|||
|
||||
var newTop = Math.max(parseInt(w.container.offsetTop) / PXSCALE + deltaY, 0)
|
||||
if (typeof w.props.top === 'string' && w.props.top.indexOf('%') > -1) {
|
||||
w.props.top = (100 * PXSCALE * newTop / w.container.parentNode.offsetHeight).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
w.props.top = (100 * PXSCALE * newTop / this.getWidgetParentContainer(w).offsetHeight).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
} else {
|
||||
w.props.top = newTop
|
||||
}
|
||||
var newLeft = Math.max(parseInt(w.container.offsetLeft) / PXSCALE + deltaX, 0)
|
||||
if (typeof w.props.left === 'string' && w.props.left.indexOf('%') > -1) {
|
||||
w.props.left = (100 * PXSCALE * newLeft / w.container.parentNode.offsetWidth).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
w.props.left = (100 * PXSCALE * newLeft / this.getWidgetParentContainer(w).offsetWidth).toFixed(2).replace(/\.?0+$/, '') + '%'
|
||||
} else {
|
||||
w.props.left = newLeft
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue