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.
This commit is contained in:
parent
e1671fdbe3
commit
fbfe167cdc
|
|
@ -121,25 +121,15 @@ Item{
|
||||||
onPositionChanged:
|
onPositionChanged:
|
||||||
(mouse)=>{
|
(mouse)=>{
|
||||||
if(!input.enabled && mouse.buttons&Qt.LeftButton){
|
if(!input.enabled && mouse.buttons&Qt.LeftButton){
|
||||||
if(!isLimited){
|
var offset = mouse.x - lastPressX
|
||||||
var offset = mouse.x - lastPressX
|
var newValue = number + offset * step
|
||||||
setNumber(number + offset * step)
|
if(isLimited){
|
||||||
var global = dragArea.mapToGlobal(lastPressX, lastPressY)
|
if(newValue > max) newValue = max
|
||||||
var local = dragArea.mapFromGlobal(global.x,global.y)
|
if(newValue < min) newValue = min
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
setNumber(newValue)
|
||||||
|
var global = dragArea.mapToGlobal(lastPressX, lastPressY)
|
||||||
|
helper.setCursorPos(global.x,global.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue