widgets: use roundTo outside of mapToScale method to allow fine grain control with mousewheel (otherwise the precision factor messes with it)
This commit is contained in:
parent
bcf603bcc5
commit
e3afaa3818
5 changed files with 24 additions and 18 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
var {clip, mapToScale, sendOsc} = require('../utils')
|
||||
var {clip, roundTo, mapToScale, sendOsc} = require('../utils')
|
||||
var _canvas_base = require('../common/_canvas_base')
|
||||
|
||||
var _sliders_base = module.exports = function(){
|
||||
|
|
@ -99,7 +99,7 @@ _sliders_base.prototype.mousewheelHandle = function(e, data, traversing) {
|
|||
var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
|
||||
increment = e.ctrlKey?0.25:1
|
||||
|
||||
this.percent = clip(this.percent + Math.max(increment,100/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
|
||||
this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true)
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ _sliders_base.prototype.percentToValue = function(percent) {
|
|||
var h = clip(percent,[0,100])
|
||||
for (var i=0;i<this.rangeKeys.length-1;i++) {
|
||||
if (h <= this.rangeKeys[i+1] && h >= this.rangeKeys[i]) {
|
||||
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],this.widgetData.precision,this.widgetData.logScale)
|
||||
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],false,this.widgetData.logScale)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ _sliders_base.prototype.valueToPercent = function(value) {
|
|||
_sliders_base.prototype.setValue = function(v,send,sync, dragged) {
|
||||
if (typeof v != 'number') return
|
||||
|
||||
this.value = clip(Math.round(v*this.roundFactor)/this.roundFactor,[this.rangeValsMin,this.rangeValsMax])
|
||||
this.value = roundTo(clip(Math.round(v*this.roundFactor)/this.roundFactor,[this.rangeValsMin,this.rangeValsMax]),this.widgetData.precision)
|
||||
|
||||
if (!dragged) this.percent = this.valueToPercent(this.value)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ module.exports = {
|
|||
// map a value from a scale to another input and output must be range arrays
|
||||
mapToScale: function(value,rangeIn,rangeOut,precision,log,revertlog) {
|
||||
|
||||
var value = module.exports.clip(value,[rangeIn[0],rangeIn[1]]),
|
||||
roundFactor = precision!=undefined?Math.pow(10,precision):100,
|
||||
|
||||
var value = module.exports.clip(value,[rangeIn[0],rangeIn[1]])
|
||||
|
||||
value = log?
|
||||
revertlog?
|
||||
|
|
@ -27,13 +25,18 @@ module.exports = {
|
|||
|
||||
value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1])))
|
||||
|
||||
if (precision!==false) value = Math.round(value*roundFactor)/roundFactor
|
||||
if (precision!==false) value = module.exports.roundTo(value, precision)
|
||||
|
||||
|
||||
return value
|
||||
|
||||
},
|
||||
|
||||
roundTo: function(value, precision) {
|
||||
var roundFactor = precision!=undefined?Math.pow(10,precision):100
|
||||
return Math.round(value*roundFactor)/roundFactor
|
||||
},
|
||||
|
||||
hsbToRgb: function (hsb) {
|
||||
var rgb = {}
|
||||
var h = hsb.h
|
||||
|
|
|
|||
|
|
@ -3509,7 +3509,7 @@ module.exports.create = function(widgetData,container) {
|
|||
}
|
||||
|
||||
},{"./utils":37}],32:[function(require,module,exports){
|
||||
var {clip, mapToScale, sendOsc} = require('../utils')
|
||||
var {clip, roundTo, mapToScale, sendOsc} = require('../utils')
|
||||
var _canvas_base = require('../common/_canvas_base')
|
||||
|
||||
var _sliders_base = module.exports = function(){
|
||||
|
|
@ -3610,7 +3610,7 @@ _sliders_base.prototype.mousewheelHandle = function(e, data, traversing) {
|
|||
var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
|
||||
increment = e.ctrlKey?0.25:1
|
||||
|
||||
this.percent = clip(this.percent + Math.max(increment,100/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
|
||||
this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true)
|
||||
|
||||
|
|
@ -3640,7 +3640,7 @@ _sliders_base.prototype.percentToValue = function(percent) {
|
|||
var h = clip(percent,[0,100])
|
||||
for (var i=0;i<this.rangeKeys.length-1;i++) {
|
||||
if (h <= this.rangeKeys[i+1] && h >= this.rangeKeys[i]) {
|
||||
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],this.widgetData.precision,this.widgetData.logScale)
|
||||
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],false,this.widgetData.logScale)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3655,7 +3655,7 @@ _sliders_base.prototype.valueToPercent = function(value) {
|
|||
_sliders_base.prototype.setValue = function(v,send,sync, dragged) {
|
||||
if (typeof v != 'number') return
|
||||
|
||||
this.value = clip(Math.round(v*this.roundFactor)/this.roundFactor,[this.rangeValsMin,this.rangeValsMax])
|
||||
this.value = roundTo(clip(Math.round(v*this.roundFactor)/this.roundFactor,[this.rangeValsMin,this.rangeValsMax]),this.widgetData.precision)
|
||||
|
||||
if (!dragged) this.percent = this.valueToPercent(this.value)
|
||||
|
||||
|
|
@ -4179,9 +4179,7 @@ module.exports = {
|
|||
// map a value from a scale to another input and output must be range arrays
|
||||
mapToScale: function(value,rangeIn,rangeOut,precision,log,revertlog) {
|
||||
|
||||
var value = module.exports.clip(value,[rangeIn[0],rangeIn[1]]),
|
||||
roundFactor = precision!=undefined?Math.pow(10,precision):100,
|
||||
|
||||
var value = module.exports.clip(value,[rangeIn[0],rangeIn[1]])
|
||||
|
||||
value = log?
|
||||
revertlog?
|
||||
|
|
@ -4191,13 +4189,18 @@ module.exports = {
|
|||
|
||||
value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1])))
|
||||
|
||||
if (precision!==false) value = Math.round(value*roundFactor)/roundFactor
|
||||
if (precision!==false) value = module.exports.roundTo(value, precision)
|
||||
|
||||
|
||||
return value
|
||||
|
||||
},
|
||||
|
||||
roundTo: function(value, precision) {
|
||||
var roundFactor = precision!=undefined?Math.pow(10,precision):100
|
||||
return Math.round(value*roundFactor)/roundFactor
|
||||
},
|
||||
|
||||
hsbToRgb: function (hsb) {
|
||||
var rgb = {}
|
||||
var h = hsb.h
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
}
|
||||
|
||||
.fader {
|
||||
|
||||
overflow: hidden;
|
||||
height:100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue