From fbfe167cdc4180f7886a872f5e633ae5b906868b Mon Sep 17 00:00:00 2001 From: jessequ Date: Fri, 31 Jul 2026 16:55:05 +0800 Subject: [PATCH] fix: unify NumberBox drag behavior to prevent value jumps in limited mode The limited drag mode used absolute mouse position to compute the value (min + xPercent * range), causing an immediate jump away from the property's current value at drag start. Unify both modes to use the relative offset formula (number + offset * step), with the limited mode only adding min/max clamping on top. Also removes the cursor-constraining logic that was specific to the old absolute mode. --- .../resources/Qml/ValueEditor/NumberBox.qml | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/PropertyEditor/resources/Qml/ValueEditor/NumberBox.qml b/PropertyEditor/resources/Qml/ValueEditor/NumberBox.qml index 2178bb6..e3cf142 100644 --- a/PropertyEditor/resources/Qml/ValueEditor/NumberBox.qml +++ b/PropertyEditor/resources/Qml/ValueEditor/NumberBox.qml @@ -121,25 +121,15 @@ Item{ onPositionChanged: (mouse)=>{ if(!input.enabled && mouse.buttons&Qt.LeftButton){ - if(!isLimited){ - var offset = mouse.x - lastPressX - setNumber(number + offset * step) - var global = dragArea.mapToGlobal(lastPressX, lastPressY) - var local = dragArea.mapFromGlobal(global.x,global.y) - helper.setCursorPos(global.x,global.y) - } - else{ - var xPercent = Math.max(0, Math.min(1, mouse.x / dragArea.width)) - var range = max - min - var newValue = min + xPercent * range - control.setNumber(newValue) - const validMouseX = Math.max (0, Math.min (dragArea.width, mouse.x)); - const validMouseY = Math.max (0, Math.min (dragArea.height, mouse.y)); - if (mouse.x !== validMouseX || mouse.y !== validMouseY) { - const validGlobalPos = dragArea.mapToGlobal (validMouseX, validMouseY); - helper.setCursorPos (validGlobalPos.x, validGlobalPos.y); - } + var offset = mouse.x - lastPressX + var newValue = number + offset * step + if(isLimited){ + if(newValue > max) newValue = max + if(newValue < min) newValue = min } + setNumber(newValue) + var global = dragArea.mapToGlobal(lastPressX, lastPressY) + helper.setCursorPos(global.x,global.y) } } }