widgets: make prop inheritance work with object props and as object items
This commit is contained in:
parent
ac0f7dcd65
commit
000e34e9b7
7 changed files with 35 additions and 25 deletions
|
|
@ -138,20 +138,6 @@ module.exports.widgets = function(data, parentNode, parentWidget) {
|
|||
delete props.left
|
||||
}
|
||||
|
||||
// Turn preArgs into array
|
||||
if (props.preArgs!=undefined) {
|
||||
props.preArgs = Array.isArray(props.preArgs)?props.preArgs:[props.preArgs]
|
||||
}
|
||||
|
||||
// Turn preArgs into array
|
||||
if (props.target!=undefined) {
|
||||
props.target = Array.isArray(props.target)?props.target:[props.target]
|
||||
}
|
||||
|
||||
if (props.precision) {
|
||||
props.precision = Math.min(20,Math.max(props.precision,0))
|
||||
}
|
||||
|
||||
// create container
|
||||
var widgetContainer = $(`
|
||||
<div class="widget ${props.type}-container">
|
||||
|
|
|
|||
|
|
@ -23,6 +23,19 @@ module.exports = class _widgets_base {
|
|||
this.parent = options.parent
|
||||
this.hash = _widgets_base.createHash()
|
||||
|
||||
// Turn preArgs into array
|
||||
if (this.props.preArgs != undefined && !Array.isArray(this.getProp('preArgs'))) {
|
||||
this.props.preArgs = [this.props.preArgs]
|
||||
}
|
||||
|
||||
// Turn preArgs into array
|
||||
if (this.props.target != undefined && !Array.isArray(this.getProp('target'))) {
|
||||
this.props.target = [this.props.target]
|
||||
}
|
||||
|
||||
if (this.props.precision) {
|
||||
this.precision = Math.min(20,Math.max(this.getProp('precision'),0))
|
||||
}
|
||||
}
|
||||
|
||||
sendValue(overrides) {
|
||||
|
|
@ -68,9 +81,10 @@ module.exports = class _widgets_base {
|
|||
|
||||
}
|
||||
|
||||
getProp(key) {
|
||||
getProp(key, opt) {
|
||||
|
||||
var opt = this.props[key]
|
||||
var opt = key == null ? opt : _widgets_base.deepCopy(this.props[key]),
|
||||
obj
|
||||
|
||||
if (typeof opt == 'string' && opt.indexOf('@{') != -1) {
|
||||
opt = opt.replace(/@\{([^\}]+)\}/g, (m)=>{
|
||||
|
|
@ -83,11 +97,21 @@ module.exports = class _widgets_base {
|
|||
|
||||
for (var i in widgets) {
|
||||
if (widgets[i].props.hasOwnProperty(k)) {
|
||||
return widgets[i].getProp(k)
|
||||
var r = widgets[i].getProp(k)
|
||||
if (typeof r != 'string') r = JSON.stringify(r)
|
||||
return r
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
opt = JSON.parse(opt)
|
||||
} catch (err) {}
|
||||
|
||||
} else if (opt != null && typeof opt == 'object') {
|
||||
for (var k in opt) {
|
||||
opt[k] = this.getProp(null, opt[k])
|
||||
}
|
||||
}
|
||||
|
||||
return opt
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ module.exports = class Formula extends _widgets_base {
|
|||
|
||||
this.input.val(
|
||||
(this.getProp('condition').length && !this.conditionState ? '* ' : '') +
|
||||
JSON.stringify(Formula.deepCopyWithPrecision(this.value, this.getProp('precision')))
|
||||
JSON.stringify(Formula.deepCopyWithPrecision(this.value, this.precision))
|
||||
)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ module.exports = class MultiXy extends _pads_base {
|
|||
value:this.getProp('value').length == this.getProp('points') * 2 ? [this.getProp('value')[i*2], this.getProp('value')[i*2 + 1]] : '',
|
||||
rangeX:this.getProp('rangeX'),
|
||||
rangeY:this.getProp('rangeY'),
|
||||
precision:this.getProp('precision'),
|
||||
precision:this.precision,
|
||||
logScaleX:this.getProp('logScaleX'),
|
||||
logScaleY:this.getProp('logScaleY')
|
||||
}})
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ module.exports = class Rgb extends _pads_base {
|
|||
}
|
||||
|
||||
for (let i in this.inputs) [
|
||||
this.inputs[i].val(this.value[i].toFixed(this.getProp('precision')))
|
||||
this.inputs[i].val(this.value[i].toFixed(this.precision))
|
||||
]
|
||||
|
||||
this.draw()
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ module.exports = class Xy extends _pads_base {
|
|||
snap:this.getProp('snap'),
|
||||
range:this.getProp('rangeX'),
|
||||
origin:'auto',
|
||||
precision:this.getProp('precision'),
|
||||
precision:this.precision,
|
||||
logScale:this.getProp('logScaleX')
|
||||
}, cancelDraw: true}),
|
||||
y: new Fader({props:{
|
||||
|
|
@ -92,7 +92,7 @@ module.exports = class Xy extends _pads_base {
|
|||
snap:this.getProp('snap'),
|
||||
range:this.getProp('rangeY'),
|
||||
origin:'auto',
|
||||
precision:this.getProp('precision'),
|
||||
precision:this.precision,
|
||||
logScale:this.getProp('logScaleY')
|
||||
}, cancelDraw: true}),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ module.exports = class _sliders_base extends _canvas_base {
|
|||
var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
|
||||
increment = e.ctrlKey?0.25:1
|
||||
|
||||
this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.getProp('precision') + 1)) * direction, [0,100])
|
||||
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})
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ module.exports = class _sliders_base extends _canvas_base {
|
|||
|
||||
var value = clip(v,[this.rangeValsMin,this.rangeValsMax])
|
||||
|
||||
if ((options.dragged || options.fromLocal) && this.value.toFixed(this.getProp('precision')) == value.toFixed(this.getProp('precision'))) options.send = false
|
||||
if ((options.dragged || options.fromLocal) && this.value.toFixed(this.precision) == value.toFixed(this.precision)) options.send = false
|
||||
|
||||
this.value = value
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ module.exports = class _sliders_base extends _canvas_base {
|
|||
|
||||
showValue() {
|
||||
|
||||
this.input.val(this.value.toFixed(this.getProp('precision')) + this.unit)
|
||||
this.input.val(this.value.toFixed(this.precision) + this.unit)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue