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,26 +121,16 @@ Item{
|
|||
onPositionChanged:
|
||||
(mouse)=>{
|
||||
if(!input.enabled && mouse.buttons&Qt.LeftButton){
|
||||
if(!isLimited){
|
||||
var offset = mouse.x - lastPressX
|
||||
setNumber(number + offset * step)
|
||||
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)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ColorAnimation on border.color{
|
||||
|
|
|
|||
Loading…
Reference in New Issue