From 79c04cc69ad9e63b2e708c65351d28fccc993ec0 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 4 Jul 2026 14:05:16 +0200 Subject: [PATCH] editor: fix moving/resing widgets inside folders when using percent units --- CHANGELOG.md | 1 + src/client/editor/index.mjs | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 834048cd..27b29e1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - bug fixes - remote control: add support for icon transform suffixes + - editor: fix moving/resing widgets inside folders when using percent units - widgets - encoder: add `horizontal` mode diff --git a/src/client/editor/index.mjs b/src/client/editor/index.mjs index 04466646..882b46e4 100644 --- a/src/client/editor/index.mjs +++ b/src/client/editor/index.mjs @@ -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 }