From c72a1aacc5155d6d96cd6c93c05fa10362b328ec Mon Sep 17 00:00:00 2001 From: bordun Date: Thu, 23 Apr 2020 15:20:21 +0200 Subject: [PATCH] widgets: remove built-in label except for button, modal & tabs widgets: colorBg property for all; opaque background for all --- src/client/widgets/basics/button.js | 41 +++++++++++++++- src/client/widgets/common/canvas.js | 2 +- src/client/widgets/common/widget.js | 63 +++++++++++++------------ src/client/widgets/containers/matrix.js | 1 - src/client/widgets/containers/modal.js | 27 ++++++++++- src/client/widgets/containers/panel.js | 5 +- src/client/widgets/containers/root.js | 1 - src/client/widgets/containers/tab.js | 28 +++++++++-- src/client/widgets/indicators/text.js | 2 +- src/client/widgets/sliders/fader.js | 2 +- src/client/widgets/sliders/knob.js | 2 +- src/client/widgets/sliders/range.js | 2 +- src/scss/widgets.scss | 26 ++-------- src/scss/widgets/basics.scss | 40 ++++++++-------- src/scss/widgets/containers.scss | 50 ++++---------------- src/scss/widgets/indicators.scss | 16 +++++-- src/scss/widgets/sliders.scss | 4 -- 17 files changed, 171 insertions(+), 141 deletions(-) diff --git a/src/client/widgets/basics/button.js b/src/client/widgets/basics/button.js index ca21a4a6..73824d64 100644 --- a/src/client/widgets/basics/button.js +++ b/src/client/widgets/basics/button.js @@ -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`` + 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(/{ this.cacheCanvasStyle() this.batchDraw() diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index acce46a1..c34b2254 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -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`
` - this.label = html`` - if (this.getProp('label') !== false) this.container.appendChild(this.label) + // this.label = html`` + // 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(/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)}, diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index af570b77..2023b394 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -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'}, diff --git a/src/client/widgets/containers/modal.js b/src/client/widgets/containers/modal.js index 5cc17f4e..032c5c3c 100644 --- a/src/client/widgets/containers/modal.js +++ b/src/client/widgets/containers/modal.js @@ -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`` + 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(/ ` - 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) diff --git a/src/client/widgets/containers/root.js b/src/client/widgets/containers/root.js index 14ad43a1..76b14bc7 100644 --- a/src/client/widgets/containers/root.js +++ b/src/client/widgets/containers/root.js @@ -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'}, diff --git a/src/client/widgets/containers/tab.js b/src/client/widgets/containers/tab.js index 33e0bb3a..63493de1 100644 --- a/src/client/widgets/containers/tab.js +++ b/src/client/widgets/containers/tab.js @@ -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(/`}) - this.text = this.widget.appendChild(html`
`) + this.text = this.widget.appendChild(html``) if (this.getProp('vertical')) this.text.classList.add('vertical') if (this.getProp('align') === 'left') this.text.classList.add('left') diff --git a/src/client/widgets/sliders/fader.js b/src/client/widgets/sliders/fader.js index 4a7e1457..0f953a1a 100644 --- a/src/client/widgets/sliders/fader.js +++ b/src/client/widgets/sliders/fader.js @@ -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) diff --git a/src/client/widgets/sliders/knob.js b/src/client/widgets/sliders/knob.js index 64a75f8a..a1afde40 100644 --- a/src/client/widgets/sliders/knob.js +++ b/src/client/widgets/sliders/knob.js @@ -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 // diff --git a/src/client/widgets/sliders/range.js b/src/client/widgets/sliders/range.js index 262c2857..e123d1e2 100644 --- a/src/client/widgets/sliders/range.js +++ b/src/client/widgets/sliders/range.js @@ -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) diff --git a/src/scss/widgets.scss b/src/scss/widgets.scss index 56060e58..1e884667 100644 --- a/src/scss/widgets.scss +++ b/src/scss/widgets.scss @@ -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; diff --git a/src/scss/widgets/basics.scss b/src/scss/widgets/basics.scss index bb7022af..98662cc3 100644 --- a/src/scss/widgets/basics.scss +++ b/src/scss/widgets/basics.scss @@ -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); } diff --git a/src/scss/widgets/containers.scss b/src/scss/widgets/containers.scss index e88af8b2..997b89f5 100644 --- a/src/scss/widgets/containers.scss +++ b/src/scss/widgets/containers.scss @@ -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 { diff --git a/src/scss/widgets/indicators.scss b/src/scss/widgets/indicators.scss index 57710ede..5da1a234 100644 --- a/src/scss/widgets/indicators.scss +++ b/src/scss/widgets/indicators.scss @@ -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; diff --git a/src/scss/widgets/sliders.scss b/src/scss/widgets/sliders.scss index 07e10d34..315e7043 100644 --- a/src/scss/widgets/sliders.scss +++ b/src/scss/widgets/sliders.scss @@ -3,10 +3,6 @@ .encoder-container, .range-container { - inner { - flex: 1; - } - canvas { image-rendering: pixelated; width: 100%;