root: add traversing option (#400)

This commit is contained in:
jean-emmanuel 2018-10-23 08:56:13 +02:00
parent 7e43cab6f1
commit 8b8864cd6a

View file

@ -1,6 +1,7 @@
var Panel = require('./panel'),
Widget = require('../common/widget'),
{iconify} = require('../../ui/utils')
{iconify} = require('../../ui/utils'),
{enableTraversingGestures, disableTraversingGestures} = require('../../events/drag')
module.exports = class Root extends Panel {
@ -10,6 +11,7 @@ module.exports = class Root extends Panel {
_children:'children',
traversing: {type: 'boolean', value: false, help: 'Set to `true` to enable traversing gestures in this widget. Set to `smart` or `auto` to limit affected widgets by the type of the first touched widget'},
variables: {type: '*', value: {}, help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object'},
id: {type: 'string', value: 'root', help: 'Widgets sharing the same id will act as clones and update each other\'s value(s) without sending extra osc messages' },
@ -40,6 +42,8 @@ module.exports = class Root extends Panel {
el.classList.add('main')
})
this.setTraversing()
}
createNavigation() {
@ -54,4 +58,34 @@ module.exports = class Root extends Panel {
}
setTraversing(update) {
var traversing = this.getProp('traversing')
if (this._traversing) {
disableTraversingGestures(this.widget)
this._traversing = false
}
if (traversing && !this._traversing) {
this._traversing = true
enableTraversingGestures(this.widget, {smart: typeof traversing === 'string' && traversing.match(/smart|auto/)})
}
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true
switch (propName) {
case 'traversing':
this.setTraversing()
return
}
}
}