diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a765db9..7b3438ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - widgets - `panel/modal`: add `layout` option ([Visual Format Language](https://github.com/IjzerenHein/autolayout.js)) - `css` option now interprets `&` as a selector for the widget's element itself (useful for targetting pseudo-elements such as `&:after`) + - `plots`: add `widgetId` option to `text`, `meter` and `led` ## 0.17.1 diff --git a/resources/docs/user-guide/widgets-specifics/plots.md b/resources/docs/user-guide/widgets-specifics/plots.md index 98409455..af91ad7d 100644 --- a/resources/docs/user-guide/widgets-specifics/plots.md +++ b/resources/docs/user-guide/widgets-specifics/plots.md @@ -162,6 +162,11 @@ Text displays incoming values (via osc) as text. Sending a message with no argum } ``` +#### `widgetId` +- type: `object` +- default: `empty` +- usage: a widget's `id` whose value will be displayed + #### `vertical` - type: `boolean` - default: `false` @@ -178,6 +183,11 @@ Meter displays incoming numerical values (via osc) as a gauge level } ``` +#### `widgetId` +- type: `object` +- default: `empty` +- usage: a widget's `id` whose value will be displayed + #### `horizontal` - type: `boolean` - default: `false` diff --git a/src/browser/js/app/widgets/plots/led.js b/src/browser/js/app/widgets/plots/led.js index d6340380..975f9d40 100644 --- a/src/browser/js/app/widgets/plots/led.js +++ b/src/browser/js/app/widgets/plots/led.js @@ -1,5 +1,6 @@ var {mapToScale} = require('../utils'), - _widgets_base = require('../common/_widgets_base') + _widgets_base = require('../common/_widgets_base'), + {widgetManager} = require('../../managers') module.exports = class Led extends _widgets_base { @@ -19,6 +20,10 @@ module.exports = class Led extends _widgets_base { color:'auto', css:'', + _plot:'plot', + + widgetId:'', + _osc:'osc', range:{min:0,max:1}, @@ -43,10 +48,31 @@ module.exports = class Led extends _widgets_base { this.led = this.widget.find('span') + if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this)) + this.setValue(widgetData.range.min) } + onRemove() { + + $('body').off(`sync.${this.hash}`) + + } + + syncHandle(e) { + + if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return + var widget = widgetManager.getWidgetById(e.id), + value + for (var i=widget.length-1; i>=0; i--) { + if (widget[i].getValue) { + this.setValue(widget[i].getValue()) + return + } + } + + } setValue(v) { if (typeof v != 'number') return diff --git a/src/browser/js/app/widgets/plots/meter.js b/src/browser/js/app/widgets/plots/meter.js index d8c5bc20..9f92b6bf 100644 --- a/src/browser/js/app/widgets/plots/meter.js +++ b/src/browser/js/app/widgets/plots/meter.js @@ -1,4 +1,6 @@ -var Fader = require('../sliders/fader') +var Fader = require('../sliders/fader'), + {widgetManager} = require('../../managers') + module.exports = class Meter extends Fader { @@ -20,6 +22,11 @@ module.exports = class Meter extends Fader { color:'auto', css:'', + + _plot:'plot', + + widgetId:'', + _osc:'osc', range:{min:0,max:1}, @@ -45,6 +52,29 @@ module.exports = class Meter extends Fader { this.canvas.off('draginit drag') + if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this)) + + + } + + onRemove() { + + $('body').off(`sync.${this.hash}`) + + } + + syncHandle(e) { + + if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return + var widget = widgetManager.getWidgetById(e.id), + value + for (var i=widget.length-1; i>=0; i--) { + if (widget[i].getValue) { + this.setValue(widget[i].getValue()) + return + } + } + } sendValue() { diff --git a/src/browser/js/app/widgets/plots/text.js b/src/browser/js/app/widgets/plots/text.js index 3abc4e64..18c2f663 100644 --- a/src/browser/js/app/widgets/plots/text.js +++ b/src/browser/js/app/widgets/plots/text.js @@ -1,5 +1,6 @@ var {iconify} = require('../../utils'), - _widgets_base = require('../common/_widgets_base') + _widgets_base = require('../common/_widgets_base'), + {widgetManager} = require('../../managers') module.exports = class Text extends _widgets_base { @@ -20,6 +21,10 @@ module.exports = class Text extends _widgets_base { color:'auto', css:'', + _plot:'plot', + + widgetId:'', + _osc:'osc', value:'', @@ -46,10 +51,32 @@ module.exports = class Text extends _widgets_base { this.value = this.defaultValue + if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this)) + this.setValue(this.value) } + onRemove() { + + $('body').off(`sync.${this.hash}`) + + } + + syncHandle(e) { + + if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return + var widget = widgetManager.getWidgetById(e.id), + value + for (var i=widget.length-1; i>=0; i--) { + if (widget[i].getValue) { + this.setValue(widget[i].getValue()) + return + } + } + + } + setValue(v) { this.value = typeof v=='object' && !v.length ? this.defaultValue : v