widgets: don't round value internally in sliders, remove roundTo util (use native toFixed), limit precision between 0 and 20
This commit is contained in:
parent
557cf4620a
commit
edfa2f7d6f
4 changed files with 9 additions and 12 deletions
|
|
@ -135,6 +135,9 @@ module.exports.widgets = function(data,parent) {
|
|||
widgetData.target = Array.isArray(widgetData.target)?widgetData.target:[widgetData.target]
|
||||
}
|
||||
|
||||
if (widgetData.precision) {
|
||||
widgetData.precision = Math.min(20,Math.max(widgetData.precision,0))
|
||||
}
|
||||
|
||||
// dimensions / coordinates can't be < 0
|
||||
for (t in {width:'',height:'',top:'',left:''}) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
var _pads_base = require('./_pads_base'),
|
||||
Fader = require('./_fake_fader'),
|
||||
{clip, roundTo, hsbToRgb, rgbToHsb} = require('../utils')
|
||||
{clip, hsbToRgb, rgbToHsb} = require('../utils')
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
|
|
@ -200,7 +200,7 @@ Rgb.prototype.update = function(options={}) {
|
|||
}
|
||||
|
||||
for (i in this.inputs) [
|
||||
this.inputs[i].val(roundTo(this.value[i],this.widgetData.precision))
|
||||
this.inputs[i].val(this.value[i].toFixed(this.widgetData.precision))
|
||||
]
|
||||
|
||||
this.draw()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
var {clip, roundTo, mapToScale, sendOsc} = require('../utils')
|
||||
var {clip, mapToScale, sendOsc} = require('../utils')
|
||||
var _canvas_base = require('../common/_canvas_base')
|
||||
|
||||
var _sliders_base = module.exports = function(){
|
||||
|
|
@ -16,7 +16,6 @@ var _sliders_base = module.exports = function(){
|
|||
|
||||
this.wrapper = this.widget.find('.wrapper')
|
||||
this.input = this.widget.find('.input').fakeInput({align:'center'})
|
||||
this.roundFactor = Math.pow(10,this.widgetData.precision)
|
||||
this.value = undefined
|
||||
this.percent = 0
|
||||
|
||||
|
|
@ -147,7 +146,7 @@ _sliders_base.prototype.valueToPercent = function(value) {
|
|||
_sliders_base.prototype.setValue = function(v,options={}) {
|
||||
if (typeof v != 'number') return
|
||||
|
||||
var value = roundTo(clip(Math.round(v*this.roundFactor)/this.roundFactor,[this.rangeValsMin,this.rangeValsMax]),this.widgetData.precision)
|
||||
var value = clip(v,[this.rangeValsMin,this.rangeValsMax])
|
||||
|
||||
if ((options.dragged || options.fromLocal) && this.value == value) options.send = false
|
||||
|
||||
|
|
@ -164,5 +163,5 @@ _sliders_base.prototype.setValue = function(v,options={}) {
|
|||
}
|
||||
|
||||
_sliders_base.prototype.showValue = function() {
|
||||
this.input.val(this.value + this.unit)
|
||||
this.input.val(this.value.toFixed(this.widgetData.precision) + this.unit)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,18 +29,13 @@ module.exports = {
|
|||
|
||||
value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1])))
|
||||
|
||||
if (precision!==false) value = module.exports.roundTo(value, precision)
|
||||
if (precision!==false) value = parseFloat(value.toFixed(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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue