multixy: add smart snap option

This commit is contained in:
jean-emmanuel 2016-11-17 20:33:45 +01:00
parent f75b5cc17d
commit 33e4e3f3c6
4 changed files with 39 additions and 3 deletions

View file

@ -5,7 +5,7 @@
- widgets
- fader: display pips to `compact` mode when `range` has multiple breakpoints
- pads: display pips when `range` has multiple breakpoints
- multixy: style update (stroked dots, bold number font)
- multixy: style update (stroked dots, bold number font); `snap` option added.
## 0.11.1

View file

@ -102,6 +102,11 @@ Pads are multidimensional widgets that output multiple values.
- can be set as an object to specify a different `address` : `{0:'/osc_address/0', 1:'/osc_address_/1'}` (each address will be appended `/x` or `y`)
- note: the widget will only respond to its original osc address, not to the splitted version
#### `snap`
- type: `boolean`
- default: `false`
- usage: by default, the points must be touched directy to be dragged; if set to `true`, touching anywhere on the widget's surface will assign the points to the touching fingers one by one.
----
## RGB

View file

@ -11,6 +11,7 @@ module.exports.options = {
points: 2,
pointSize: 15,
snap:false,
separator2:'style',
@ -58,7 +59,7 @@ var MultiXy = module.exports.MultiXy = function(widgetData) {
this.handles = []
this.pads = []
for (var i=0;i<this.widgetData.points;i++) {
for (var i=this.widgetData.points-1;i>=0;i--) {
this.pads[i] = new Xy({
snap:widgetData.snap,
rangeX:widgetData.rangeX,
@ -72,13 +73,32 @@ var MultiXy = module.exports.MultiXy = function(widgetData) {
this.handles[i] = $(`<div class="handle">${i}</div>`)
this.wrapper.append(this.handles[i])
if (this.widgetData.snap) {
let pad = this.pads[i]
pad.wrapper.on('draginit',(e)=>{
pad.widget.addClass('active')
})
pad.wrapper.on('dragend',(e)=>{
pad.widget.removeClass('active')
})
}
}
if (this.widgetData.snap) {
this.wrapper.addClass('snap')
}
this.value = []
this.handles.forEach((handle, i)=>{
handle.on('draginit drag',(e, data, traversing)=>{
handle.on('draginit drag dragend',(e, data, traversing)=>{
if (this.widgetData.snap && e.type == 'draginit') {
e.type = 'drag'
this.pads[i].widget.addClass('active')
}
this.pads[i].wrapper.trigger(e.type, [data, traversing])
var v = this.pads[i].widget.getValue()
if (v < [this.value[i*2], this.value[i*2+1]] || v > [this.value[i*2], this.value[i*2+1]]) {
@ -91,6 +111,9 @@ var MultiXy = module.exports.MultiXy = function(widgetData) {
this.wrapper.on('sync',(e)=>{
e.stopPropagation()
if (this.widgetData.snap) {
this.setValue(this.widget.getValue(), e.options)
}
})
this.widget.getValue = () => {

View file

@ -122,6 +122,9 @@
width:calc(100% - calc(var(--point-size) * 2 + 2rem));
height:calc(100% - calc(var(--point-size) * 2 + 2rem));
pointer-events: none;
&.active {
pointer-events: none!important;
}
.wrapper {
background: transparent;
}
@ -144,7 +147,12 @@
border-radius: calc(var(--point-size) * 2 + 4rem);
cursor: -webkit-grab;
opacity: 0;
z-index: 1;
}
&.snap > .pad {
pointer-events: auto;
}
}
}
}