diff --git a/CHANGELOG.md b/CHANGELOG.md index 878e37ef..e345d47f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/browser/js/app/widgets/buttons/switch.js b/src/browser/js/app/widgets/buttons/switch.js index 86f6f946..4dbb218a 100644 --- a/src/browser/js/app/widgets/buttons/switch.js +++ b/src/browser/js/app/widgets/buttons/switch.js @@ -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')})