From e6e39a9fd190a528c099a590fdcc306a6bcd76d1 Mon Sep 17 00:00:00 2001 From: bordun Date: Tue, 3 Nov 2020 08:32:26 +0100 Subject: [PATCH] keyboard: make `on` and `off` properties dynamic --- CHANGELOG.md | 5 +++ src/client/widgets/containers/keyboard.js | 37 +++++++++++++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c69e9437..947b3c15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.6.1 + +- widgets + - keyboard: make `on` and `off` properties dynamic + ## 1.6.0 - bug fixes diff --git a/src/client/widgets/containers/keyboard.js b/src/client/widgets/containers/keyboard.js index 01cfa1fe..e5b9e3b6 100644 --- a/src/client/widgets/containers/keyboard.js +++ b/src/client/widgets/containers/keyboard.js @@ -57,6 +57,14 @@ class Keyboard extends Panel { if (e.widget === this) return this.value[e.widget._index] = e.widget.getValue() + + if (e.options.send) { + var start = parseInt(this.getProp('start')) + this.sendValue({ + v: [e.widget._index + start, e.widget.getValue() ? this.getProp('on') : this.getProp('off')] + }) + } + this.changed(e.options) }) @@ -84,16 +92,9 @@ class Keyboard extends Panel { data.id = this.getProp('id') + '/' + i data.label = false data.css = '' - - data.target = '@{parent.target}' - data.decimals = '@{parent.decimals}' - - data.address = '@{parent.address}' - data.preArgs = `JS{{ - var a = @{parent.preArgs}; - var b = typeof a === 'string' && a === '' ? [] : Array.isArray(a) ? a : [a]; - return b.concat([${i}]) - }}` + data.bypass = true + data.on = 1 + data.off = 0 var key = parser.parse({ data: data, @@ -119,8 +120,24 @@ class Keyboard extends Panel { } + setValue(v, options={}) { + + if (!Array.isArray(v) || v.length !== 2) return + if (v[1] !== this.getProp('on') && v[1] !== this.getProp('off')) return + + var start = parseInt(this.getProp('start')) + this.children[v[0] - start].setValue(v[1] === this.getProp('on') ? 1 : 0, options) + + } + } + +Keyboard.dynamicProps = Keyboard.prototype.constructor.dynamicProps.concat( + 'on', + 'off', +) + Keyboard.cssVariables = Keyboard.prototype.constructor.cssVariables.concat( {js: 'colorWhite', css: '--color-white-key'}, {js: 'colorBlack', css: '--color-black-key'}