sliders: make scrolling granular when steps are defined (#460)

This commit is contained in:
bordun 2019-01-28 15:29:48 +01:00
parent cc1ae45b32
commit 1b523a0d86
2 changed files with 12 additions and 4 deletions

View file

@ -4,7 +4,9 @@
- bug fixes
- editor: changes applied to wrong widget when clicking on a widget while editing another widget's property
- push: allow setting `value` property
- push: allow setting `value` property
- widgets
- sliders: when `steps` is set, scrolling on the widget makes it go directly from one step to another
## 0.41.4

View file

@ -140,9 +140,15 @@ class Slider extends Canvas {
var direction = e.wheelDelta / Math.abs(e.wheelDelta),
increment = e.ctrlKey?0.25:1
this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.precision + 1)) * direction, [0,100])
this.setValue(this.percentToValue(this.percent), {sync:true,send:true,dragged:true})
if (this.getProp('steps')) {
var i = this.steps.indexOf(this.value)
if (i > -1 && i < this.steps.length) {
this.setValue(this.steps[i + direction], {sync: true, send: true, fromLocal: true})
}
} else {
this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.precision + 1)) * direction, [0,100])
this.setValue(this.percentToValue(this.percent), {sync: true, send: true, dragged: true})
}
}