matrix/keyboard: id variable in script is now the id of the child widget that triggered the event

This commit is contained in:
bordun 2020-11-03 10:01:14 +01:00
parent 42f316cf81
commit cfcf22b9dd
5 changed files with 25 additions and 19 deletions

View file

@ -8,6 +8,7 @@
- widgets
- keyboard: make `on` and `off` properties dynamic
- script: add `getIndex` function
- matrix/keyboard: `id` variable in script is now the `id` of the child widget that triggered the event
## 1.6.0

View file

@ -17,6 +17,9 @@ Depending on what triggered the script's execution, a few variables are availabl
- `value`: widget's value
- `touch`: see [Touch state](#touch-state)
??? infos "Keyboard & Matrix"
In keyboards and matrices, `id` is the id of the child widget that triggered the event.
**Event: keyboard** (script widget only)
- `type` (`string`): `keydown` or `keyup`

View file

@ -216,7 +216,9 @@ class Widget extends EventEmitter {
event: 'value'
}, builtIn: true, parent: this})
this.on('change', (e)=>{
if (e.widget === this && this.mounted && !e.options.fromEdit) this.script.setValue(this.value, {...e.options, id: e.options.id || e.id})
if (e.widget === this && this.mounted && !e.options.fromEdit) {
this.script.setValue(e.options.widget ? e.options.widget.value : this.value, {...e.options, id: e.options.id || e.id})
}
})
if (String(this.getProp('script')).includes('touch')) {
this.on('touch', (e)=>{

View file

@ -51,21 +51,27 @@ class Keyboard extends Panel {
this.childrenType = undefined
this.value = []
this.on('change',(e)=>{
if (e.widget === this) return
var widget = e.widget
this.value[e.widget._index] = e.widget.getValue()
if (widget === this) return
this.value[widget._index] = 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')]
v: [e.widget._index + start, widget.getValue() ? this.getProp('on') : this.getProp('off')]
})
}
this.changed(e.options)
this.changed({
...e.options,
id: widget.getProp('id')
})
})

View file

@ -44,22 +44,16 @@ class Matrix extends Panel {
if (e.widget === this) return
if (this.getProp('widgetType') === 'clone') {
var widget = this.getProp('widgetType') === 'clone' ? e.widget.parent : e.widget
if (e.widget.parent.parent !== this) return
if (widget.parent !== this) return
this.value[e.widget.parent._index] = e.widget.getValue()
this.value[widget._index] = e.widget.getValue()
} else {
if (e.widget.parent !== this) return
this.value[e.widget._index] = e.widget.getValue()
}
this.changed(e.options)
this.changed({
...e.options,
id: widget.getProp('id')
})
})