matrices: add generic matrix widget (#320)

This commit is contained in:
jean-emmanuel 2018-06-28 08:58:52 +02:00
parent efbfa4aa33
commit e1195a123c
9 changed files with 146 additions and 25 deletions

View file

@ -242,14 +242,14 @@ class Widget extends EventEmitter {
}
resolveProp(propName, propValue, storeLinks=true, originalWidget, originalPropName) {
resolveProp(propName, propValue, storeLinks=true, originalWidget, originalPropName, context) {
propValue = propValue !== undefined ? propValue : Widget.deepCopy(this.props[propName])
originalWidget = originalWidget || this
originalPropName = originalPropName || propName
var variables = {},
mathscope = {},
mathscope = context || {},
varnumber = 0
if (typeof propValue == 'string') {
@ -405,7 +405,7 @@ class Widget extends EventEmitter {
} else if (propValue != null && typeof propValue == 'object') {
for (let k in propValue) {
propValue[k] = this.resolveProp(propName, propValue[k], storeLinks, originalWidget, originalPropName)
propValue[k] = this.resolveProp(propName, propValue[k], storeLinks, originalWidget, originalPropName, context)
}
}

View file

@ -21,6 +21,7 @@ module.exports.widgets = {
multixy: require('./pads/multixy'),
// matrices
matrix: require('./matrices/matrix'),
multitoggle: require('./matrices/multitoggle'),
multipush: require('./matrices/multipush'),
multifader: require('./matrices/multifader'),
@ -60,7 +61,7 @@ module.exports.categories = {
'Sliders':['fader','knob', 'encoder', 'range'],
'Buttons':['toggle','push','switch', 'dropdown'],
'Pads':['xy','rgb','multixy'],
'Matrices':['multifader','multitoggle','multipush', 'keyboard'],
'Matrices':['matrix', 'multifader','multitoggle','multipush', 'keyboard'],
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg'],
'Containers':['panel','strip','modal', 'clone'],
'Switchers':['switcher','crossfader'],

View file

@ -0,0 +1,28 @@
var Widget = require('../common/widget'),
{enableTraversingGestures} = require('../../events/drag')
module.exports = class _matrix_base extends Widget {
constructor(options) {
super({...options, html: '<div class="matrix"></div>'})
this.value = []
this.start = parseInt(this.getProp('start'))
this.on('change',(e)=>{
if (e.widget == this) return
this.value[DOM.index(e.widget.container)] = e.widget.getValue()
this.changed(e.options)
})
if (this.getProp('traversing')) enableTraversingGestures(this.widget)
}
}

View file

@ -1,8 +1,8 @@
var Matrix = require('./matrix'),
var _matrix_base = require('./_matrix_base'),
parser = require('../../parser')
module.exports = class Keyboard extends Matrix {
module.exports = class Keyboard extends _matrix_base {
static defaults() {

View file

@ -1,30 +1,119 @@
var Widget = require('../common/widget'),
{enableTraversingGestures} = require('../../events/drag')
var _matrix_base = require('./_matrix_base'),
parser = require('../../parser'),
widgetManager = require('../../managers/widgets')
class Matrix extends _matrix_base {
class Matrix extends Widget {
static defaults() {
return {
type:'multiwidget',
id:'auto',
_geometry:'geometry',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
_style:'style',
label:'auto',
color:'auto',
css:'',
_matrix: 'Matrix',
widgetType: 'toggle',
matrix: [2,2],
start:0,
spacing:0,
traversing:true,
props:{},
_value: 'value',
default: '',
value: '',
_osc:'osc',
precision:2,
address:'auto',
preArgs:[],
split:false,
target:[],
bypass:false
}
}
constructor(options) {
super({...options, html: '<div class="matrix"></div>'})
super(options)
this.value = []
this.widget.style.setProperty('--columns', this.getProp('matrix')[0])
this.widget.style.setProperty('--rows', this.getProp('matrix')[1])
this.widget.style.setProperty('--spacing', this.getProp('spacing') + 'rem')
this.start = parseInt(this.getProp('start'))
if (parser.widgets[this.getProp('widgetType')]) {
this.on('change',(e)=>{
for (var i = this.start; i < this.getProp('matrix')[0] * this.getProp('matrix')[1] + this.start; i++) {
if (e.widget == this) return
var data = {
type: this.getProp('widgetType'),
id: this.getProp('id') + '/' + i,
label: i,
top: 'auto',
left: 'auto',
height: 'auto',
width: 'auto',
...this.resolveProp('props', undefined, false, false, false, {'i':i})
}
this.value[DOM.index(e.widget.container)] = e.widget.getValue()
this.changed(e.options)
var widget = parser.parse([data], this.widget, this)
})
widget.container.classList.add('not-editable')
if (this.getProp('traversing')) enableTraversingGestures(this.widget)
}
} else {
this.errors.widgetType = this.getProp('widgetType') + ' is not a valid widget type'
}
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true
switch (propName) {
case 'props':
for (var i in this.childrenHashes) {
let widget = widgetManager.widgets[this.childrenHashes[i]],
data = this.resolveProp('props', undefined, false, false, false, {'i':i})
Object.assign(widget.props, data)
widget.updateProps(Object.keys(data), this)
}
return
}
}
}
Matrix.dynamicProps = Matrix.prototype.constructor.dynamicProps.concat(
'props'
)
module.exports = Matrix

View file

@ -1,8 +1,8 @@
var Matrix = require('./matrix'),
var _matrix_base = require('./_matrix_base'),
parser = require('../../parser'),
widgetManager = require('../../managers/widgets')
module.exports = class Multifader extends Matrix {
module.exports = class Multifader extends _matrix_base {
static defaults() {

View file

@ -1,7 +1,7 @@
var Matrix = require('./matrix'),
var _matrix_base = require('./_matrix_base'),
parser = require('../../parser')
module.exports = class Multipush extends Matrix {
module.exports = class Multipush extends _matrix_base {
static defaults() {

View file

@ -1,7 +1,7 @@
var Matrix = require('./matrix'),
var _matrix_base = require('./_matrix_base'),
parser = require('../../parser')
module.exports = class Multitoggle extends Matrix {
module.exports = class Multitoggle extends _matrix_base {
static defaults() {

View file

@ -1,5 +1,8 @@
/* Multiple widgets (push|toggle|fader) matrix */
.multitoggle-container, .multipush-container, .multifader-container {
.matrix-container,
.multitoggle-container,
.multipush-container,
.multifader-container {
&.editing {
overflow: hidden;
}