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)

View file

@ -12,7 +12,6 @@
width: 100rem;
height: 100rem;
background-clip: content-box;
contain: strict;
@supports not (contain: strict) {
@ -39,34 +38,15 @@
color: var(--color-text);
background-color: var(--color-background);
background-clip: content-box;
&.absolute-position {
position: absolute;
z-index: 10;
}
&.no-label {
> label {
display:none;
}
}
label {
text-overflow:ellipsis;
overflow:hidden;
text-align:center;
height:30rem;
max-height:30rem;
padding:0 6rem;
width: 100%;
flex-shrink: 0;
display: flex;
justify-content: center;
white-space: pre;
align-items: center;
order: -1;
}
canvas {
flex: 1;
height: auto;

View file

@ -1,10 +1,13 @@
.button-container,
.button-container {
width: 90rem;
height: 60rem;
}
.menu-container,
.dropdown-container,
.input-container,
.file-container {
width: 90rem;
height: 60rem;
height: 30rem;
}
.button-container {
@ -22,37 +25,32 @@
right:0;
bottom:0;
margin: var(--widget-spacing);
flex: 1;
display: flex;
flex-direction: column;
z-index: -1;
padding: var(--widget-padding);
@include pseudo-stroke();
@include pseudo-fill();
@include pseudo-stroke($z: -1);
@include pseudo-fill($z: -1);
}
> label {
flex: 1;
max-height: initial;
text-align: center;
pointer-events:none;
label {
display: flex;
justify-content: center;
align-items: center;
color: var(--color-text);
white-space: pre;
line-height: 100%;
overflow: hidden;
text-align: center;
word-wrap: break-word;
height: 100%;
width: 100%;
border: 2rem solid transparent;
}
&.on, &.active {
--alpha-fill:var(--alpha-fill-on);
label {
color: var(--color-text-on)
}
color: var(--color-text-on);
}

View file

@ -39,15 +39,11 @@
> inner {
--widget-spacing: calc(var(--widget-padding) / 2);
margin: var(--widget-spacing)
calc(1rem + var(--widget-spacing))
calc(1rem + var(--widget-spacing));
margin: var(--widget-spacing);
}
&.no-inner-padding > inner {
margin: calc(-1rem + var(--widget-spacing) * -1)
calc(var(--widget-spacing) * -1)
calc(var(--widget-spacing) * -1);
margin: calc(var(--widget-spacing) * -1);
}
> inner > .widget {
@ -155,10 +151,6 @@
display:none
}
> label {
display: none;
}
}
.panel-container {
@ -172,21 +164,6 @@
margin: var(--widget-spacing);
}
> label {
position: relative;
// background-color: var(--color-background);
@include pseudo-stroke($z: 10);
&:before {
border-width: 0 0 1rem 0;
margin: 0 1rem;
}
}
&.contains-widgets.no-label > inner {
border-top: 1rem solid var(--color-background);
}
&.contains-tabs > inner > .navigation {
margin: 0 1rem;
&.vertical {
@ -352,11 +329,6 @@
content: none
}
> label {
display: none;
}
> .clone {
--widget-spacing: 0;
@ -410,7 +382,12 @@
> label {
flex: 1;
position: absolute;
top:0;
left:0;
right:0;
bottom:0;
max-height: initial;
text-align: center;
pointer-events:none;
@ -489,9 +466,7 @@
}
> inner {
margin: var(--widget-spacing)
var(--widget-spacing)
var(--widget-spacing);
margin: var(--widget-spacing);
}
}
}
@ -532,13 +507,6 @@
justify-content: center;
label {
flex: 1;
pointer-events: none;
display: flex;
}
}
.patchbay-container {

View file

@ -34,7 +34,11 @@
width: 90rem;
height: 60rem;
--alpha-fill-on: 75;
--alpha-stroke: 0;
--alpha-fill-off: 0.1;
--alpha-fill-on: 1;
--widget-padding: -1;
inner {
@include pseudo-stroke();
@ -47,11 +51,11 @@
}
div {
color: var(--color-fill);
label {
opacity: var(--alpha-fill-on);
flex: 1;
height: auto;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
@ -60,6 +64,8 @@
overflow: hidden;
text-align: center;
word-wrap: break-word;
border: 2rem solid transparent;
&.right {
text-align: right;
justify-content: flex-end;

View file

@ -3,10 +3,6 @@
.encoder-container,
.range-container {
inner {
flex: 1;
}
canvas {
image-rendering: pixelated;
width: 100%;