push: add doubleTap option (#447)

This commit is contained in:
jean-emmanuel 2018-12-28 14:05:32 +01:00
parent 0841499c40
commit ed1336e8d2
2 changed files with 21 additions and 5 deletions

View file

@ -5,7 +5,9 @@
- bug fixes
- editor: widgets/tabs not properly reordered when changing a widget or tab's index by more than 1
- main: `--no-gui` switch not working when running the app from a different directory
- widgets
- push: add `doubleTap` option
## 0.40.3
- bug fixes

View file

@ -1,4 +1,5 @@
var Widget = require('../common/widget'),
doubletab = require('../mixins/double_tap'),
osc = require('../../osc'),
html = require('nanohtml')
@ -11,6 +12,7 @@ class Push extends Widget {
_push: 'push',
doubleTap: {type: 'boolean', value: false, help: 'Set to `true` to make the button require a double tap to be pushed instead of a single tap'},
on: {type: '*', value: 1, help: [
'Set to `null` to send send no argument in the osc message',
'Can be an `object` if the type needs to be specified (see preArgs)'
@ -33,12 +35,24 @@ class Push extends Widget {
this.active = 0
this.lastChanged = 'state'
this.on('draginit',()=>{
if (this.active) return
this.setValuePrivate(this.getProp('on'),{send:true,sync:true})
}, {element: this.widget})
if (this.getProp('doubleTap')) {
doubletab(this.widget, ()=>{
if (this.active) return
this.setValuePrivate(this.getProp('on'),{send:true,sync:true})
})
} else {
this.on('draginit',()=>{
if (this.active) return
this.setValuePrivate(this.getProp('on'),{send:true,sync:true})
}, {element: this.widget})
}
this.on('dragend',()=>{
if (!this.active) return
this.setValuePrivate(this.getProp('off'),{send:true,sync:true})
}, {element: this.widget})