slow event speed with ondrag() in jsui

Thijs Pothoven's icon

Is there any way to make jsui more responsive to the mouse while dragging?
It's slower than other max ui objects like multislider.

also it's not the drawing speed, because when you input mouse data from mousestate it updates just as fast as a multislider. So i think the mouse input somehow, somewhere gets throttled.

Any solutions?

Thijs Pothoven's icon

Solved it with interpolation:

// Assume lastIndex, currentIndex, lastValue, currentValue are defined
var steps = Math.abs(lastIndex - currentIndex);
var valueDifference = currentValue - lastValue;
var valuePerStep = steps !== 0 ? valueDifference / steps : 0;

if (lastIndex <= currentIndex) {
    // Forward drag
    for (var i = lastIndex; i <= currentIndex; i++) {
        var interpolatedValue = lastValue + valuePerStep * (i - lastIndex);
        values[i - 1] = interpolatedValue; // Adjust based on your array structure
    }
} else {
    // Backward drag
    for (var i = lastIndex; i >= currentIndex; i--) {
        var interpolatedValue = lastValue + valuePerStep * (lastIndex - i); // Same calculation logic
        values[i - 1] = interpolatedValue; // Adjust based on your array structure
    }
}