rgbled: add css color names support (issue #76); fix led/rgbled not storing their own value;

This commit is contained in:
jean-emmanuel 2017-07-27 17:06:40 +02:00
parent 404a445484
commit d8d1c88fa1
2 changed files with 24 additions and 6 deletions

View file

@ -75,6 +75,7 @@ module.exports = class Led extends _widgets_base {
setValue(v) {
if (typeof v != 'number') return
this.value = v
this.widget[0].style.setProperty('--opacity', mapToScale(v,[this.getProp('range').min,this.getProp('range').max],[0,1],false,this.getProp('logScale'),true))
}

View file

@ -3,7 +3,7 @@ var {mapToScale} = require('../utils'),
{widgetManager} = require('../../managers'),
{clip} = require('../utils')
module.exports = class Led extends _widgets_base {
module.exports = class Rbgled extends _widgets_base {
static defaults() {
@ -73,15 +73,32 @@ module.exports = class Led extends _widgets_base {
}
setValue(v) {
if (!v || !v.length || v.length<3) return
var c = ''
if (Array.isArray(v) && v.length >= 3) {
for (let i in [0,1,2]) {
v[i] = parseInt(clip(v[i],[0,255]))
}
v[3] = clip(v[3] != undefined ? v[3] : 1,[0,1])
c = `rgba(${v[0]}, ${v[1]}, ${v[2]}, ${v[3]})`
} else if (typeof v == 'string') {
c = v
} else {
return
for (let i in [0,1,2]) {
v[i] = parseInt(clip(v[i],[0,255]))
}
v[3] = clip(v[3] != undefined ? v[3] : 1,[0,1])
this.value = v
this.widget[0].style.setProperty('--color-custom',`rgba(${v[0]}, ${v[1]}, ${v[2]}, ${v[3]})`)
this.widget[0].style.setProperty('--color-custom', c)
}