encoder: apply knob sensibility change

This commit is contained in:
bordun 2022-07-04 10:39:23 +02:00
parent fb621a6f9c
commit aa2b9fea08
2 changed files with 8 additions and 14 deletions

View file

@ -6,8 +6,8 @@
- editor: error when ctrl+clicking on a root's child
- widget
- knob: `sensitivity` and ctrl+drag preserve `circular` mode behavior
- knob: `snap` mode now works like `circular` mode except for the touch start event (value can't jump from start to end anymore)
- knob / encoder: `sensitivity` and ctrl+drag gesture preserve `circular` mode behavior
- knob / encoder: `snap` mode now works like `circular` mode except for the touch start event (value can't jump from start to end anymore)
## 1.16.6

View file

@ -112,25 +112,19 @@ module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range
// knob.js without clipping + extra case for snap
if ((this.getProp('mode') === 'vertical' && !e.traversing) || e.ctrlKey) {
if ((this.getProp('mode') === 'vertical' && !e.traversing)) {
// vertical
this.setPercent(-100 * e.movementY / this.height + this.percent)
this.setPercent(this.percent + (-100 * e.movementY / this.height) * this.getProp('sensitivity') / e.inertia)
} else {
// snap or circular
var offsetX = this.lastOffsetX + e.movementX,
offsetY = this.lastOffsetY + e.movementY
if (e.traversing || this.getProp('mode') === 'circular') {
// circular
var diff = this.angleToPercent(this.coordsToAngle(offsetX, offsetY), true) - this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY), true)
if (Math.abs(diff) < 50 && diff !== 0) this.setPercent(this.percent + diff)
} else {
// snap
this.setPercent(this.angleToPercent(this.coordsToAngle(offsetX, offsetY), true))
var diff = this.angleToPercent(this.coordsToAngle(offsetX, offsetY), true) - this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY), true)
if (Math.abs(diff) < 50 && diff !== 0) {
diff = diff * this.getProp('sensitivity') / e.inertia
this.setPercent(this.percent + diff)
}
this.lastOffsetX = offsetX