plots: add widgetId option to text, meter and led
This commit is contained in:
parent
0899f5bc5e
commit
d6e801e0ee
5 changed files with 97 additions and 3 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue