switch: receive array properly (issue #136)
This commit is contained in:
parent
ea55e99662
commit
097a6de666
2 changed files with 13 additions and 4 deletions
|
|
@ -11,7 +11,7 @@
|
|||
- widgets
|
||||
- inputs: **new** `keys` widget, for keyboard bindings
|
||||
- property inheritance: new special property name `_value` (retrieve the widget's value, and update when it changes)
|
||||
- switch: added `showValues` to display both values and labels in the buttons
|
||||
- switch: added `showValues` to display both values and labels in the buttons; array values can now be selected via osc
|
||||
- rgb: **removed** `touchAddress` option
|
||||
- labels/texts: multiple white spaces are no longer merged
|
||||
- misc
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ module.exports = class Switch extends _widgets_base {
|
|||
if (this.getProp('horizontal')) this.widget.classList.add('horizontal')
|
||||
|
||||
this.values = []
|
||||
this.stringValues = []
|
||||
|
||||
var isArray = Array.isArray(this.getProp('values'))
|
||||
|
||||
|
|
@ -56,6 +57,12 @@ module.exports = class Switch extends _widgets_base {
|
|||
|
||||
this.values.push(this.getProp('values')[k])
|
||||
|
||||
if (typeof this.getProp('values')[k] == 'object') {
|
||||
this.stringValues.push(JSON.stringify(this.getProp('values')[k]))
|
||||
} else {
|
||||
this.stringValues.push(-1)
|
||||
}
|
||||
|
||||
var label = isArray ? this.getProp('values')[k]: k
|
||||
if (this.getProp('showValues') && !isArray) label = label + ': ' + this.getProp('values')[k]
|
||||
|
||||
|
|
@ -67,7 +74,7 @@ module.exports = class Switch extends _widgets_base {
|
|||
|
||||
this.value = undefined
|
||||
|
||||
this.on('draginit',(e)=>{
|
||||
this.on('draginit', (e)=>{
|
||||
|
||||
var index = 0,
|
||||
node = e.target
|
||||
|
|
@ -86,9 +93,11 @@ module.exports = class Switch extends _widgets_base {
|
|||
|
||||
}
|
||||
|
||||
setValue(v,options={}) {
|
||||
setValue(v, options={}) {
|
||||
|
||||
var i = this.values.indexOf(v)
|
||||
var i = typeof v == 'object' ?
|
||||
this.stringValues.indexOf(JSON.stringify(v)) :
|
||||
this.values.indexOf(v)
|
||||
|
||||
DOM.each(this.widget, '.on', (el)=>{el.classList.remove('on')})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue