From 42c99aaeceee7a5b0982c328876ac0b3c6d7f21a Mon Sep 17 00:00:00 2001 From: bordun Date: Tue, 25 Feb 2020 12:31:22 +0100 Subject: [PATCH] nice editor there --- src/client/ui/ui-inspector-field.js | 39 ++++++++++++++-------- src/client/widgets/buttons/menu.js | 2 +- src/client/widgets/buttons/switch.js | 12 +++++-- src/client/widgets/buttons/toggle.js | 6 ++++ src/client/widgets/common/canvas.js | 18 +++++----- src/client/widgets/common/widget.js | 46 +++++++++++++++++--------- src/client/widgets/containers/clone.js | 2 +- src/client/widgets/containers/modal.js | 9 +++-- src/client/widgets/containers/panel.js | 13 +++----- src/client/widgets/containers/root.js | 6 +++- src/client/widgets/containers/tab.js | 6 +++- src/client/widgets/graphs/eq.js | 16 +++------ src/client/widgets/graphs/plot.js | 2 +- src/scss/themes/default.scss | 2 +- src/scss/ui/inspector.scss | 12 ++++++- src/scss/widgets/buttons.scss | 13 +++++--- src/scss/widgets/containers.scss | 6 ++-- 17 files changed, 130 insertions(+), 80 deletions(-) diff --git a/src/client/ui/ui-inspector-field.js b/src/client/ui/ui-inspector-field.js index dc002475..03238aa7 100644 --- a/src/client/ui/ui-inspector-field.js +++ b/src/client/ui/ui-inspector-field.js @@ -81,20 +81,7 @@ class UiInspectorField extends UiWidget { this.container.appendChild(wrapper) - } - - if (this.name.includes('color')) { - - let style = window.getComputedStyle(this.widget.container) - let val = chroma(style.getPropertyValue('--' + this.name.replace(/([A-Z])/g, (a,s)=>'-' + s.toLowerCase())).trim()).hex('rgb') - - let picker = html`` - - this.container.appendChild(picker) - - } - - if (this.default.type.includes('boolean')) { + } else if (this.default.type.includes('boolean')) { let toggle = html` @@ -104,6 +91,30 @@ class UiInspectorField extends UiWidget { this.container.appendChild(toggle) + } else if (this.name.includes('color')) { + + let style = window.getComputedStyle(this.widget.container), + cssName = this.widget.constructor.cssVariables.find(x=>x.js === this.name).css, + val = '#000' + + try { + val = chroma(style.getPropertyValue('--' + this.name.replace(/([A-Z])/g, (a,s)=>'-' + s.toLowerCase())).trim()).hex('rgb') + } catch(e) {console.log(e)} + + let picker = html`` + + this.container.appendChild(picker) + + } else if (stringValue === 'auto' && this.widget.constructor.cssVariables.some(x=>x.js === this.name)) { + + let style = window.getComputedStyle(this.widget.container), + data = this.widget.constructor.cssVariables.find(x=>x.js === this.name), + val = style.getPropertyValue(data.css).trim() + + if (data.toJs) val = data.toJs(val) + + this.container.appendChild(html`
${val}
`) + } diff --git a/src/client/widgets/buttons/menu.js b/src/client/widgets/buttons/menu.js index e8821dbe..c80913f2 100644 --- a/src/client/widgets/buttons/menu.js +++ b/src/client/widgets/buttons/menu.js @@ -36,7 +36,7 @@ class Menu extends Widget { ]}, weights: {type: 'array', value: '', help: [ '`Array` of `number` defining the weights of each value in `values`', - 'Ignored when `grid` is `true`' + 'Ignored when `mode` is `grid`' ]} }) diff --git a/src/client/widgets/buttons/switch.js b/src/client/widgets/buttons/switch.js index ef15392a..bda1b39e 100644 --- a/src/client/widgets/buttons/switch.js +++ b/src/client/widgets/buttons/switch.js @@ -3,7 +3,7 @@ var Widget = require('../common/widget'), html = require('nanohtml'), raw = require('nanohtml/raw') -module.exports = class Switch extends Widget { +class Switch extends Widget { static description() { @@ -29,6 +29,7 @@ module.exports = class Switch extends Widget { '- `slide`: same as `tap` but allows sliding between values', '- `click`: activates upon click only and allows further scrolling', ]}, + colorTextOn: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, }) @@ -126,4 +127,11 @@ module.exports = class Switch extends Widget { if (options.sync) this.changed(options) } - }} + } +} + +Switch.cssVariables = Switch.prototype.constructor.cssVariables.concat( + {js: 'colorTextOn', css: '--color-text-on'} +) + +module.exports = Switch diff --git a/src/client/widgets/buttons/toggle.js b/src/client/widgets/buttons/toggle.js index 4d3c7698..5a5857bf 100644 --- a/src/client/widgets/buttons/toggle.js +++ b/src/client/widgets/buttons/toggle.js @@ -14,6 +14,7 @@ class Toggle extends Widget { return super.defaults({ + _toggle: 'toggle', on: {type: '*', value: 1, help: [ @@ -31,6 +32,7 @@ class Toggle extends Widget { '- `tap` (no release)' ]}, doubleTap: {type: 'boolean', value: false, help: 'Set to `true` to make the button require a double tap to be pushed instead of a single tap'}, + colorTextOn: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, }) @@ -149,6 +151,10 @@ class Toggle extends Widget { } +Toggle.cssVariables = Toggle.prototype.constructor.cssVariables.concat( + {js: 'colorTextOn', css: '--color-text-on'} +) + Toggle.dynamicProps = Toggle.prototype.constructor.dynamicProps.concat( 'on', 'off', diff --git a/src/client/widgets/common/canvas.js b/src/client/widgets/common/canvas.js index 4f4cb24e..5b0836d9 100644 --- a/src/client/widgets/common/canvas.js +++ b/src/client/widgets/common/canvas.js @@ -133,19 +133,13 @@ class Canvas extends Widget { style = style || window.getComputedStyle(this.canvas) - this.cssVars.padding = parseFloat(style.getPropertyValue('--widget-padding')) * PXSCALE // rem unit - this.cssVars.colorText = style.getPropertyValue('--color-text').trim() - this.cssVars.colorWidget = style.getPropertyValue('--color-widget').trim() - this.cssVars.colorFill = style.getPropertyValue('--color-fill').trim() - this.cssVars.colorStroke = style.getPropertyValue('--color-stroke').trim() - this.cssVars.colorForeground = style.getPropertyValue('--color-foreground').trim() + for (var data of this.constructor.cssVariables) { + var val = style.getPropertyValue(data.css).trim() + this.cssVars[data.js] = data.toJs ? data.toJs(val) : val - this.cssVars.alphaStroke = parseFloat(style.getPropertyValue('--alpha-stroke').trim()) - this.cssVars.alphaFillOff = parseFloat(style.getPropertyValue('--alpha-fill-off').trim()) - this.cssVars.alphaFillOn = parseFloat(style.getPropertyValue('--alpha-fill-on').trim()) - this.cssVars.alphaPips = parseFloat(style.getPropertyValue('--alpha-pips').trim()) + } this.fontFamily = style.getPropertyValue('font-family').trim() this.textAlign = style.getPropertyValue('text-align').trim() @@ -230,6 +224,10 @@ class Canvas extends Widget { } +Canvas.cssVariables = Canvas.prototype.constructor.cssVariables.concat( + {js: 'alphaPips', css: '--alpha-pips', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)} +) + Canvas.dynamicProps = Canvas.prototype.constructor.dynamicProps.concat( 'on', 'off' diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 8f4f77ab..f633eb63 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -72,13 +72,13 @@ class Widget extends EventEmitter { _style:'style', + colorText: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, colorWidget: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, colorStroke: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, colorFill: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, alphaStroke: {type: 'number', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, alphaFillOff: {type: 'number', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, alphaFillOn: {type: 'number', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, - colorText: {type: 'string', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, padding: {type: 'number', value: 'auto', help: 'Defines the widget\'s accent color (css variable `--custom-color`). Must be a valid CSS color. Set to "auto" to inherit from parent widget.'}, @@ -191,10 +191,14 @@ class Widget extends EventEmitter { if (this.getProp('label') !== false) this.container.appendChild(this.label) if (this.widget) this.container.appendChild(this.widget) this.container._widget_instance = this - this.setContainerStyles() + this.container.classList.toggle('no-interaction', !this.getProp('interaction')) + this.setContainerStyles() + this.setCssVariables() + + } contains(widget) { @@ -786,7 +790,7 @@ class Widget extends EventEmitter { case 'alphaFillOff': case 'alphaFillOn': case 'padding': - this.setContainerStyles(['color']) + this.setCssVariables() return case 'precision': @@ -815,7 +819,7 @@ class Widget extends EventEmitter { } - setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) { + setContainerStyles(styles = ['geometry', 'label', 'css', 'visibility']) { if (styles.includes('visibility')) { this.container.style.display = this.getProp('visible') ? '' : 'none' @@ -939,22 +943,23 @@ class Widget extends EventEmitter { } - if (styles.includes('color')) { - - // color - for (var cssvar of ['color-text', 'color-widget', 'color-fill', 'color-stroke', 'alpha-stroke', 'alpha-fill-on', 'alpha-fill-off']) { - var val = this.getProp(cssvar.replace(/\-([a-z])/g, (a,s)=>s.toUpperCase())) - this.container.style.setProperty('--' + cssvar, val !== undefined && val != 'auto' ? val : '') - } - this.container.style.setProperty('--widget-padding', this.getProp('padding') !== undefined && this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '') - - } - return style } + setCssVariables() { + + + for (var data of this.constructor.cssVariables) { + + var val = this.getProp(data.js) + this.container.style.setProperty(data.css, val !== undefined && val !== 'auto' ? data.toCss ? data.toCss(val) : val : '') + + } + + } + reCreateWidget(options={}){ if (!this.removed) return updateWidget(this, options) @@ -973,6 +978,17 @@ class Widget extends EventEmitter { Widget.parsersContexts = {} +Widget.cssVariables = [ + {js: 'colorWidget', css: '--color-widget'}, + {js: 'colorFill', css: '--color-fill'}, + {js: 'colorStroke', css: '--color-stroke'}, + {js: 'colorText', css: '--color-text'}, + {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)}, + {js: 'alphaStroke', css: '--alpha-stroke', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)} +] + Widget.dynamicProps = [ 'visible', 'label', diff --git a/src/client/widgets/containers/clone.js b/src/client/widgets/containers/clone.js index e08496a6..aeae23ac 100644 --- a/src/client/widgets/containers/clone.js +++ b/src/client/widgets/containers/clone.js @@ -29,7 +29,7 @@ class Clone extends Container() { props: {type: 'object', value: {}, help: 'Cloned widget\'s properties to override'}, }, [ - '_style', 'colorWidget', 'colorFill', 'colorStroke', 'alphaStroke', 'alphaFillOff', 'alphaFillOn', 'padding', + 'colorText', 'colorWidget', 'colorFill', 'colorStroke', 'alphaStroke', 'alphaFillOff', 'alphaFillOn', 'padding', 'label', 'color', 'linkId', '_value', 'default', 'value', '_osc', 'precision', 'address', 'preArgs', 'target', 'bypass' diff --git a/src/client/widgets/containers/modal.js b/src/client/widgets/containers/modal.js index 87ebe664..29e76e2f 100644 --- a/src/client/widgets/containers/modal.js +++ b/src/client/widgets/containers/modal.js @@ -192,15 +192,14 @@ class Modal extends Panel { } - setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) { - super.setContainerStyles(styles) + setCssVariables() { - if (styles.includes('color') && this.popupContent) { + super.setCssVariables() - this.popupContent.style.setProperty('--widget-padding', this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '') + if (!this.popupContent) return - } + this.popupContent.style.setProperty('--widget-padding', this.getProp('padding') !== 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '') } diff --git a/src/client/widgets/containers/panel.js b/src/client/widgets/containers/panel.js index 208617a9..efeb4477 100644 --- a/src/client/widgets/containers/panel.js +++ b/src/client/widgets/containers/panel.js @@ -144,6 +144,7 @@ class Panel extends Container() { style += widget.getProp('colorWidget') === 'auto' ? '' : `--color-widget:${widget.getProp('colorWidget')};` style += widget.getProp('colorFill') === 'auto' ? '' : `--color-fill:${widget.getProp('colorFill')};` + style += widget.getProp('colorText') === 'auto' ? '' : `--color-text:${widget.getProp('colorText')};` if (!widget.getProp('visible')) style += 'display:none;' @@ -200,6 +201,7 @@ class Panel extends Container() { this.setTraversing() return + case 'colorText': case 'colorWidget': case 'colorFill': case 'colorStroke': @@ -215,15 +217,10 @@ class Panel extends Container() { } - setContainerStyles(styles = ['geometry', 'label', 'css', 'color', 'visibility']) { + setCssVariables() { - super.setContainerStyles(styles) - - if (styles.includes('color') && this.getProp('scroll')) { - - setScrollbarColor(this.container) - - } + super.setCssVariables() + setScrollbarColor(this.container) } diff --git a/src/client/widgets/containers/root.js b/src/client/widgets/containers/root.js index 9f640225..c22fb771 100644 --- a/src/client/widgets/containers/root.js +++ b/src/client/widgets/containers/root.js @@ -23,7 +23,11 @@ class Root extends StaticProperties(Panel, {scroll: false, label: false, id: 'ro 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'}, variables: {type: '*', value: '', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'}, - }, ['label', '_geometry', 'left', 'top', 'width', 'height', 'scroll'], { + }, [ + 'label', + '_geometry', 'left', 'top', 'width', 'height', + 'colorFill', 'colorStroke', 'alphaStroke', 'alphaFillOff', 'padding' + ], { tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'}, diff --git a/src/client/widgets/containers/tab.js b/src/client/widgets/containers/tab.js index a8974d87..599fecd4 100644 --- a/src/client/widgets/containers/tab.js +++ b/src/client/widgets/containers/tab.js @@ -22,7 +22,10 @@ module.exports = class Tab extends StaticProperties(Panel, {scroll: true}) { 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'}, variables: {type: '*', value: '@{parent.variables}', help: 'Defines one or more arbitrary variables that can be inherited by children widgets'}, - }, ['_geometry', 'left', 'top', 'width', 'height', 'scroll'], { + }, [ + '_geometry', 'left', 'top', 'width', 'height', + 'colorStroke', 'alphaStroke', 'alphaFillOff', 'alphaFillOn' + ], { widgets: {type: 'array', value: [], help: 'Each element of the array must be a widget object. A panel cannot contain widgets and tabs simultaneously.'}, tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object. A panel cannot contain widgets and tabs simultaneously'}, @@ -69,6 +72,7 @@ module.exports = class Tab extends StaticProperties(Panel, {scroll: true}) { case 'visible': case 'label': + case 'colorText': case 'colorWidget': case 'colorFill': case 'colorStroke': diff --git a/src/client/widgets/graphs/eq.js b/src/client/widgets/graphs/eq.js index c4447a4a..6eb31b28 100644 --- a/src/client/widgets/graphs/eq.js +++ b/src/client/widgets/graphs/eq.js @@ -1,8 +1,10 @@ var {clip} = require('../utils'), Plot = require('./plot'), - Widget = require('../common/widget') + Widget = require('../common/widget'), + StaticProperties = require('../mixins/static_properties') -module.exports = class Eq extends Plot { + +module.exports = class Eq extends StaticProperties(Plot, {rangeX: {min: 20, max: 22050}}) { static description() { @@ -41,18 +43,8 @@ module.exports = class Eq extends Plot { constructor(options) { - // backward compat - if (options.props.filters && options.props.filters.length) { - options.props.value = options.props.filters - delete options.props.filters - } - super(options) - this.rangeX = {min:20,max:22050} - this.pips.x.min = '20' - this.pips.x.max = '22k' - this.resolution = clip(this.getProp('resolution'),[64,1024]) } diff --git a/src/client/widgets/graphs/plot.js b/src/client/widgets/graphs/plot.js index fa97b0e4..88ac2933 100644 --- a/src/client/widgets/graphs/plot.js +++ b/src/client/widgets/graphs/plot.js @@ -123,7 +123,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, inte if (this.value[i].length) { points.push(mapToScale(this.value[i][0], [this.rangeX.min, this.rangeX.max], [padding, this.width - padding], 0, this.logScaleX, true)) - points.push(mapToScale(this.value[i][1], [this.rangeY.min, this.rangeY.max], [this.height - 2 * PXSCALE, 2 * PXSCALE], 0, this.logScaleY, true)) + points.push(mapToScale(this.value[i][1], [this.rangeY.min, this.rangeY.max], [this.height - 2 * PXSCALE - padding, 2 * PXSCALE + padding], 0, this.logScaleY, true)) } else { let nx = mapToScale(i, [0, this.value.length - 1], [padding, this.width - padding], 0, this.logScaleX, true), ny = mapToScale(this.value[i], [this.rangeY.min, this.rangeY.max], [this.height - 2 * PXSCALE - padding, 2 * PXSCALE + padding], 0, this. logScaleY, true) diff --git a/src/scss/themes/default.scss b/src/scss/themes/default.scss index f9d54eef..337ecc03 100644 --- a/src/scss/themes/default.scss +++ b/src/scss/themes/default.scss @@ -53,7 +53,7 @@ $text: white; --alpha-scrollbar-on: 0.5; --scrollbar-size:12rem; - --color-text: #{transparentize($text, .4)}; + --color-text: #{mix($base, $text, 40)}; --color-widget: var(--color-accent); diff --git a/src/scss/ui/inspector.scss b/src/scss/ui/inspector.scss index 02cb44d8..dc1314b5 100644 --- a/src/scss/ui/inspector.scss +++ b/src/scss/ui/inspector.scss @@ -16,6 +16,7 @@ osc-inspector-field { flex-direction: row; line-height: $field-height; margin-top: 4rem; + position: relative; label { width: 90rem; @@ -53,6 +54,15 @@ osc-inspector-field { } + .computed-value { + position: absolute; + right: 94rem; + text-align: right; + pointer-events: none; + opacity: 0.5; + font-style: italic; + margin-top: 1rem; + } } @@ -215,7 +225,7 @@ osc-inspector-select { position: relative; font-family: mono; line-height: inherit; - padding: 0; + padding: 4rem; overflow: hidden; height: $field-height; width: $field-height; diff --git a/src/scss/widgets/buttons.scss b/src/scss/widgets/buttons.scss index 1f0365af..40e4324b 100644 --- a/src/scss/widgets/buttons.scss +++ b/src/scss/widgets/buttons.scss @@ -3,6 +3,7 @@ --alpha-fill-off: 0; --alpha-fill-on: .75; --widget-padding: -1rem; + --color-text-on: var(--color-foreground); inner { @@ -41,7 +42,7 @@ --alpha-fill:var(--alpha-fill-on); label { - color: var(--color-foreground) + color: var(--color-text-on) } } @@ -50,7 +51,9 @@ .switch-container { - --alpha-fill: 0.75; + --alpha-fill-on: 0.75; + --alpha-fill: var(--alpha-fill-off); + --color-text-on: var(--color-foreground); inner { @@ -80,10 +83,12 @@ justify-content: center; text-overflow: clip; overflow: hidden; + @include pseudo-fill($z: -1); &.on { - @include pseudo-fill($z: -1); - color: var(--color-foreground); + --alpha-fill: var(--alpha-fill-on); + + color: var(--color-text-on); } } diff --git a/src/scss/widgets/containers.scss b/src/scss/widgets/containers.scss index 9d24b44a..f478171f 100644 --- a/src/scss/widgets/containers.scss +++ b/src/scss/widgets/containers.scss @@ -167,8 +167,6 @@ padding-bottom: 1rem; position: relative; - color: var(--color-text); - &.main { :last-child, .tools { width:var(--nav-height); @@ -191,9 +189,11 @@ div { - --color-stroke:var(--color-widget); + // --color-stroke:var(--color-widget); --color-fill:var(--color-widget); + color: var(--color-text); + line-height:calc(var(--nav-height) - 1rem); display:flex; min-width:0;