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:
jessequ 2026-07-31 16:55:05 +08:00
parent e1671fdbe3
commit fbfe167cdc
1 changed files with 8 additions and 18 deletions

View File

@ -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)
}
}
}