prop inheritance: make @{id.value}, @{id} and @{id._value} refer to the same thing (current value)

This commit is contained in:
jean-emmanuel 2018-03-01 17:40:01 +01:00
parent 2f7768dc8b
commit 72e724aa85
3 changed files with 15 additions and 11 deletions

View file

@ -4,11 +4,12 @@
- bug fixes
- launcher: parse array options correctly when an item contains spaces,
- launcher: the terminal now grows and scrolls to bottom automatically
- launcher: the terminal now grows and scrolls to bottom automatically
- main
- add `--fullscreen` switch (default gui only, bypasses the sidepanel fullscreen button)
- widgets
- knob: big knobs design tweaks
- property inheritance: `@{widget_id.value}`, `@{widget_id}` and `@{widget_id._value}` now all refer to the widget's current value (the latter being kept for backward compatibility)
- editor
- allow selecting multiple widgets (`ctrl + click`) if they share the same parent. Context-menu and sidepanel editing actions apply to all selected widgets

View file

@ -21,11 +21,11 @@ If the retreived property is an object (`[] / {}`), a subset can be defined by a
!!! note ""
The root panel's `id` is `root`.
## Use dynamic value
## Using the value
The special property name `_value`<i class="md-icon" title="dynamic">flash_on</i> refers to a widget's value, as opposed to its `value` property.
The special property name `value`<i class="md-icon" title="dynamic">flash_on</i> refers to a widget's current value (which can be affected by its `value` *property*).
When omitted, the property name defaults to `_value` : `@{widgetId}` => `@{widgetId._value}`
When omitted, the property name defaults to `value` : `@{widgetId}` => `@{widgetId.value}`
## Dynamic properties
@ -37,4 +37,4 @@ Some properties have much cheaper update routines and can be considered as `dyna
## Circular references cases
- container widgets can inherit their children's properties only to define `dynamic` properties
- widgets can inherit their own `_value`<i class="md-icon" title="dynamic">flash_on</i> property only to define `dynamic` properties
- widgets can inherit their own `value`<i class="md-icon" title="dynamic">flash_on</i> property only to define `dynamic` properties

View file

@ -239,10 +239,13 @@ class Widget extends EventEmitter {
} else {
id = id[0]
k = '_value'
k = 'value'
}
// backward compat
if (k === '_value') k = 'value'
var widgets = id == 'parent' && this.parent ?
[this.parent] : id == 'this' ? [this] :
widgetManager.getWidgetById(id)
@ -260,7 +263,7 @@ class Widget extends EventEmitter {
if (storeLinks) {
if (k == '_value') {
if (k == 'value') {
if (!this.linkedPropsValue[id]) this.linkedPropsValue[id] = []
if (this.linkedPropsValue[id].indexOf(propName) == -1) this.linkedPropsValue[id].push(propName)
@ -276,13 +279,13 @@ class Widget extends EventEmitter {
for (var i in widgets) {
if (widgets[i].props.hasOwnProperty(k) || k == '_value') {
if (widgets[i].props.hasOwnProperty(k) || k == 'value') {
if (originalPropName == k && widgets[i].props.id == originalWidget.props.id) {
return undefined
}
var r = k == '_value' ?
var r = k == 'value' ?
widgets[i].getValue(true) :
widgets[i].resolveProp(k, undefined, storeLinks, originalWidget, originalPropName)
@ -352,7 +355,7 @@ class Widget extends EventEmitter {
return this.cachedProps[propName]
}
updateProps(propNames, widget, options, _value) {
updateProps(propNames, widget, options, value) {
if (propNames.indexOf('value') > 0) {
propNames.splice(propNames.indexOf('value'), 1)
@ -385,7 +388,7 @@ class Widget extends EventEmitter {
}
}
if (reCreate && this.childrenHashes.indexOf(widget.hash) == -1 && !(_value && widget == this)) {
if (reCreate && this.childrenHashes.indexOf(widget.hash) == -1 && !(value && widget == this)) {
this.reCreateWidget()
return true