widgets: remove built-in label except for button, modal & tabs

widgets: colorBg property for all; opaque background  for all
This commit is contained in:
bordun 2020-04-23 15:20:21 +02:00
parent 7c63979db9
commit c72a1aacc5
17 changed files with 171 additions and 141 deletions

View file

@ -1,7 +1,8 @@
var Widget = require('../common/widget'),
doubletab = require('../mixins/double_tap'),
html = require('nanohtml'),
{deepEqual, isJSON} = require('../../utils')
{deepEqual, isJSON} = require('../../utils'),
{iconify} = require('../../ui/utils')
class Button extends Widget {
@ -18,6 +19,11 @@ class Button extends Widget {
_button: 'button',
label: {type: 'string|boolean', value: 'auto', help: [
'Set to `false` to hide completely',
'- Insert icons using the prefix ^ followed by the icon\'s name : `^play`, `^pause`, etc (see https://fontawesome.com/icons?d=gallery&s=solid&m=free)',
'- Icons can be transformed with the following suffixes: `.flip-[horizontal|vertical|both]`, `.rotate-[90|180|270]`, `.spin`, `.pulse`. Example: `^play.flip-horizontal`',
]},
on: {type: '*', value: 1, help: [
'Set to `null` to send send no argument in the osc message',
]},
@ -125,6 +131,9 @@ class Button extends Widget {
this.value = this.getProp('off')
this.label = html`<label></label>`
this.updateLabel()
}
@ -166,6 +175,36 @@ class Button extends Widget {
}
updateLabel() {
if (this.getProp('label') === false) {
if (this.widget.contains(this.label)) this.widget.removeChild(this.label)
} else {
this.label.innerHTML = this.getProp('label') == 'auto'?
this.getProp('id'):
iconify(String(this.getProp('label')).replace(/</g, '&lt;'))
if (!this.widget.contains(this.label)) this.widget.appendChild(this.label)
}
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return
switch (propName) {
case 'label':
this.updateLabel()
return
}
}
onRemove() {

View file

@ -144,7 +144,7 @@ class Canvas extends Widget {
case 'alphaStroke':
case 'alphaFillOff':
case 'alphaFillOn':
case 'colorPanel':
case 'colorBg':
setTimeout(()=>{
this.cacheCanvasStyle()
this.batchDraw()

View file

@ -52,11 +52,11 @@ class Widget extends EventEmitter {
type: {type: 'string', value: 'auto', help: ''},
id: {type: 'string', value: 'auto', help: 'Widgets sharing the same `id` will act as clones and update each other\'s value(s) without sending extra osc messages.' },
label: {type: 'string|boolean', value: 'auto', help: [
'Set to `false` to hide completely',
'- Insert icons using the prefix ^ followed by the icon\'s name : `^play`, `^pause`, etc (see https://fontawesome.com/icons?d=gallery&s=solid&m=free)',
'- Icons can be transformed with the following suffixes: `.flip-[horizontal|vertical|both]`, `.rotate-[90|180|270]`, `.spin`, `.pulse`. Example: `^play.flip-horizontal`',
]},
// label: {type: 'string|boolean', value: 'auto', help: [
// 'Set to `false` to hide completely',
// '- Insert icons using the prefix ^ followed by the icon\'s name : `^play`, `^pause`, etc (see https://fontawesome.com/icons?d=gallery&s=solid&m=free)',
// '- Icons can be transformed with the following suffixes: `.flip-[horizontal|vertical|both]`, `.rotate-[90|180|270]`, `.spin`, `.pulse`. Example: `^play.flip-horizontal`',
// ]},
visible: {type: 'boolean', value: true, help: 'Set to `false` to hide the widget.'},
interaction: {type: 'boolean', value: true, help: 'Set to `false` to disable pointer interactions.'},
@ -77,6 +77,7 @@ class Widget extends EventEmitter {
_style:'style',
colorBg: {type: 'string', value: 'auto', help: 'Panel background color. Set to "auto" to inherit from parent widget.'},
colorText: {type: 'string', value: 'auto', help: 'Text color. Set to "auto" to inherit from parent widget.'},
colorWidget: {type: 'string', value: 'auto', help: 'Widget\'s default accent color. Set to "auto" to inherit from parent widget.'},
colorStroke: {type: 'string', value: 'auto', help: 'Stroke color. Set to "auto" to use `colorWidget`.'},
@ -213,8 +214,8 @@ class Widget extends EventEmitter {
this.container = html`
<div class="widget ${options.props.type}-container" id="${this.hash}" data-widget="${this.hash}"></div>
`
this.label = html`<label></label>`
if (this.getProp('label') !== false) this.container.appendChild(this.label)
// this.label = html`<label></label>`
// if (this.getProp('label') !== false) this.container.appendChild(this.label)
if (this.widget) this.container.appendChild(this.widget)
this.container._widget_instance = this
@ -796,12 +797,12 @@ class Widget extends EventEmitter {
this.container.classList.toggle('no-interaction', !this.getProp('interaction'))
return
case 'label':
this.setContainerStyles(['label'])
if (oldPropValue === false || this.getProp('label') === false) {
resize.check(this.container)
}
return
// case 'label':
// this.setContainerStyles(['label'])
// if (oldPropValue === false || this.getProp('label') === false) {
// resize.check(this.container)
// }
// return
case 'css': {
this.setContainerStyles(['css'])
@ -883,23 +884,23 @@ class Widget extends EventEmitter {
}
if (styles.includes('label')) {
// label
if (this.getProp('label') === false) {
this.container.classList.add('no-label')
this.label.innerHTML = ''
} else {
this.container.classList.remove('no-label')
var label = this.getProp('label') == 'auto'?
this.getProp('id'):
iconify(String(this.getProp('label')).replace(/</g, '&lt;'))
this.label.innerHTML = label
this.container.appendChild(this.label)
}
}
// if (styles.includes('label')) {
//
// // label
// if (this.getProp('label') === false) {
// this.container.classList.add('no-label')
// this.label.innerHTML = ''
// } else {
// this.container.classList.remove('no-label')
// var label = this.getProp('label') == 'auto'?
// this.getProp('id'):
// iconify(String(this.getProp('label')).replace(/</g, '&lt;'))
//
// this.label.innerHTML = label
// this.container.appendChild(this.label)
// }
//
// }
if (styles.includes('css')) {
@ -1049,11 +1050,11 @@ class Widget extends EventEmitter {
Widget.parsersContexts = {}
Widget.cssVariables = [
{js: 'colorBg', css: '--color-background'},
{js: 'colorWidget', css: '--color-widget'},
{js: 'colorFill', css: '--color-fill'},
{js: 'colorStroke', css: '--color-stroke'},
{js: 'colorText', css: '--color-text'},
{js: 'colorPanel', css: '--color-background'},
{js: 'padding', css: '--widget-padding', toCss: x=>parseFloat(x) + 'rem', toJs: x=>parseFloat(x) * PXSCALE},
{js: 'alphaFillOn', css: '--alpha-fill-on', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)},
{js: 'alphaFillOff', css: '--alpha-fill-off', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)},

View file

@ -30,7 +30,6 @@ class Matrix extends StaticProperties(Panel, {scroll: false}) {
_matrixLayout: 'matrix: layout',
colorPanel: {type: 'string', value: 'auto', help: 'Panel background color. Set to "auto" to inherit from parent widget.'},
layout: {type: 'string', value: 'horizontal', choices: ['horizontal', 'vertical', 'grid'], help: 'Defines how children are laid out.'},
gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns of a value css grid-template definition.'},
traversing: {type: 'boolean', value: true, help: 'Set to `false` to disable traversing gestures'},

View file

@ -20,6 +20,11 @@ class Modal extends Panel {
_modal: 'modal',
label: {type: 'string|boolean', value: 'auto', help: [
'Set to `false` to hide completely',
'- Insert icons using the prefix ^ followed by the icon\'s name : `^play`, `^pause`, etc (see https://fontawesome.com/icons?d=gallery&s=solid&m=free)',
'- Icons can be transformed with the following suffixes: `.flip-[horizontal|vertical|both]`, `.rotate-[90|180|270]`, `.spin`, `.pulse`. Example: `^play.flip-horizontal`',
]},
doubleTap: {type: 'boolean', value: false, help: 'Set to `true` to make the modal require a double tap to open instead of a single tap'},
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
@ -31,7 +36,6 @@ class Modal extends Panel {
popupLeft: {type: 'number|percentage', value: 'auto', help: 'Modal popup\'s position'},
popupTop: {type: 'number|percentage', value: 'auto', help: 'Modal popup\'s position'},
colorPanel: {type: 'string', value: 'auto', help: 'Panel background color. Set to "auto" to inherit from parent widget.'},
layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal', 'grid'], help: 'Defines how children are laid out.'},
gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns of a value css grid-template definition.'},
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'},
@ -120,6 +124,8 @@ class Modal extends Panel {
this.popupContent.classList.add('layout-' + this.getProp('layout'))
this.popupContent.style.setProperty('--widget-padding', this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '')
this.label = html`<label></label>`
this.updateLabel()
this.childrenType = 'widget'
@ -200,6 +206,22 @@ class Modal extends Panel {
super.onRemove()
}
updateLabel() {
if (this.getProp('label') === false) {
if (this.container.contains(this.label)) this.container.removeChild(this.label)
} else {
this.label.innerHTML = this.getProp('label') == 'auto'?
this.getProp('id'):
iconify(String(this.getProp('label')).replace(/</g, '&lt;'))
if (!this.container.contains(this.label)) this.container.appendChild(this.label)
}
}
updatePopupLabel() {
if (!this.popup) return
@ -216,8 +238,9 @@ class Modal extends Panel {
switch (propName) {
case 'popupLabel':
case 'label':
this.updateLabel()
case 'popupLabel':
if (this.value) {
this.updatePopupLabel()
} else {

View file

@ -19,7 +19,6 @@ class Panel extends Container() {
_panel: 'panel',
colorPanel: {type: 'string', value: 'auto', help: 'Panel background color. Set to "auto" to inherit from parent widget.'},
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
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'},
@ -189,7 +188,7 @@ class Panel extends Container() {
<div class="tablink" data-widget="${widget.hash}" style="${style}">
</div>
`
label.innerHTML = widget.label.innerHTML
label.innerHTML = widget.label
this.navigation.appendChild(label)
})
@ -245,7 +244,7 @@ class Panel extends Container() {
case 'alphaStroke':
case 'alphaFillOff':
case 'alphaFillOn':
case 'colorPanel':
case 'colorBg':
case 'padding':
for (var w of this.children) {
if (w) w.onPropChanged(propName)

View file

@ -16,7 +16,6 @@ class Root extends StaticProperties(Panel, {visible: true, label: false, id: 'ro
_panel: 'panel',
colorPanel: {type: 'string', value: 'auto', help: 'Panel background color. Set to "auto" to inherit from parent widget.'},
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
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'},

View file

@ -1,6 +1,8 @@
var Panel = require('./panel'),
Widget = require('../common/widget'),
resize = require('../../events/resize')
resize = require('../../events/resize'),
{iconify} = require('../../ui/utils'),
html = require('nanohtml')
module.exports = class Tab extends Panel {
@ -17,7 +19,11 @@ module.exports = class Tab extends Panel {
_panel: 'panel',
colorPanel: {type: 'string', value: 'auto', help: 'Panel background color. Set to "auto" to inherit from parent widget.'},
label: {type: 'string|boolean', value: 'auto', help: [
'Set to `false` to hide completely',
'- Insert icons using the prefix ^ followed by the icon\'s name : `^play`, `^pause`, etc (see https://fontawesome.com/icons?d=gallery&s=solid&m=free)',
'- Icons can be transformed with the following suffixes: `.flip-[horizontal|vertical|both]`, `.rotate-[90|180|270]`, `.spin`, `.pulse`. Example: `^play.flip-horizontal`',
]},
variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
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'},
// detached: {type: 'boolean', value: true, help: 'Set to `false` if the tab contains `frame` widgets that should not be reloaded when the tab opens'},
@ -61,6 +67,21 @@ module.exports = class Tab extends Panel {
this.detached = false
this.label = ''
this.updateLabel()
}
updateLabel() {
if (this.getProp('label') === false) {
this.label = ''
} else {
this.label = this.getProp('label') == 'auto'?
this.getProp('id'):
iconify(String(this.getProp('label')).replace(/</g, '&lt;'))
}
}
hide() {
@ -92,8 +113,9 @@ module.exports = class Tab extends Panel {
switch (propName) {
case 'visible':
case 'label':
this.updateLabel()
case 'visible':
case 'colorText':
case 'colorWidget':
case 'colorFill':

View file

@ -32,7 +32,7 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true, inte
super({...options, html: html`<inner></inner>`})
this.text = this.widget.appendChild(html`<div></div>`)
this.text = this.widget.appendChild(html`<label></label>`)
if (this.getProp('vertical')) this.text.classList.add('vertical')
if (this.getProp('align') === 'left') this.text.classList.add('left')

View file

@ -259,7 +259,7 @@ module.exports = class Fader extends Slider {
if (this.cssVars.alphaStroke) {
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.cssVars.colorPanel
this.ctx.fillStyle = this.cssVars.colorBg
this.ctx.beginPath()
this.ctx.rect(m - 6 * PXSCALE, d - 10 * PXSCALE, 12 * PXSCALE, 20 * PXSCALE)

View file

@ -272,7 +272,7 @@ module.exports = class Knob extends Slider {
//
//
// // center
// this.ctx.fillStyle = this.cssVars.colorPanel
// this.ctx.fillStyle = this.cssVars.colorBg
// this.ctx.strokeStyle = this.cssVars.colorStroke
// this.ctx.lineWidth = 1 * PXSCALE
//

View file

@ -303,7 +303,7 @@ class Range extends Fader {
if (this.cssVars.alphaStroke) {
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.cssVars.colorPanel
this.ctx.fillStyle = this.cssVars.colorBg
this.ctx.beginPath()
this.ctx.rect(m - 6 * PXSCALE, _d - 10 * PXSCALE, 12 * PXSCALE, 20 * PXSCALE)