From 216951a6ea8296eed86bb99d55aafa72e8805f19 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 24 Feb 2020 19:14:07 +0100 Subject: [PATCH] v1 on fire --- src/client/editor/index.js | 2 + src/client/ui/ui-inspector-field.js | 28 +++--- src/client/ui/ui-inspector.js | 38 +++++++- src/client/widgets/buttons/dropdown.js | 10 +- src/client/widgets/buttons/menu.js | 7 +- src/client/widgets/buttons/toggle.js | 12 +-- src/client/widgets/common/canvas.js | 44 ++++----- src/client/widgets/common/widget.js | 28 +++--- src/client/widgets/containers/tab.js | 2 +- src/client/widgets/frames/frame.js | 6 +- src/client/widgets/frames/html.js | 1 - src/client/widgets/frames/image.js | 1 - src/client/widgets/frames/svg.js | 2 - src/client/widgets/graphs/eq.js | 7 +- src/client/widgets/graphs/plot.js | 8 +- src/client/widgets/graphs/visualizer.js | 4 +- src/client/widgets/indicators/led.js | 4 +- src/client/widgets/indicators/text.js | 4 +- src/client/widgets/inputs/input.js | 17 ++-- src/client/widgets/pads/multixy.js | 4 +- src/client/widgets/pads/xy.js | 4 +- src/client/widgets/sliders/knob.js | 15 +-- src/scss/ui/inspector.scss | 11 +++ src/scss/widgets.scss | 10 ++ src/scss/widgets/buttons.scss | 118 ++++++++++++++++++++++-- src/scss/widgets/frames.scss | 2 + src/scss/widgets/indicators.scss | 5 + 27 files changed, 279 insertions(+), 115 deletions(-) diff --git a/src/client/editor/index.js b/src/client/editor/index.js index 838c7aff..a27e50b7 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -30,6 +30,8 @@ var Editor = class Editor { if (propName === 'address' && value === '') { // special case w.props[propName] = '/' + w.props.id + } else if (propName === 'label' && value === true) { + w.props[propName] = 'auto' } else { w.props[propName] = value !== '' ? value : deepCopy(defaults[w.props.type][propName].value) } diff --git a/src/client/ui/ui-inspector-field.js b/src/client/ui/ui-inspector-field.js index 53f72559..dc002475 100644 --- a/src/client/ui/ui-inspector-field.js +++ b/src/client/ui/ui-inspector-field.js @@ -2,7 +2,8 @@ var UiWidget = require('./ui-widget'), {categories} = require('../widgets/'), html = require('nanohtml'), raw = require('nanohtml/raw'), - {icon, Popup} = require('../ui/utils') + {icon, Popup} = require('../ui/utils'), + chroma = require('chroma-js') class UiInspectorField extends UiWidget { @@ -15,6 +16,7 @@ class UiInspectorField extends UiWidget { this.widget = options.widget this.value = options.value this.default = options.default + this.tabIndex = options.tabIndex this.container = html`` this.label = this.container.appendChild(html``) @@ -29,14 +31,14 @@ class UiInspectorField extends UiWidget { if (this.widget.props.type == 'tab' || this.widget.props.type == 'root') { this.container.appendChild(html` - + `) return } this.createInput() - var select = html`` for (let cname in categories) { @@ -63,7 +65,7 @@ class UiInspectorField extends UiWidget { JSON.stringify(this.value, null, ' ').replace(/\n\s\s\s\s/g, ' ').replace(/\n\s\s(\}|\])/g, ' $1') : this.value - var input = html`` + var input = html`` this.container.appendChild(input) @@ -83,7 +85,10 @@ class UiInspectorField extends UiWidget { if (this.name.includes('color')) { - let picker = html`` + 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) @@ -92,22 +97,11 @@ class UiInspectorField extends UiWidget { if (this.default.type.includes('boolean')) { let toggle = html` - + ${raw(icon('check'))} ` - toggle.addEventListener('click', ()=>{ - if (this.name === 'label' && !this.widget.getProp(this.name) === true) { - // special case - input.value = 'auto' - } else { - input.value = !this.widget.getProp(this.name) - } - DOM.dispatchEvent(input, 'change') - }) - - this.container.appendChild(toggle) } diff --git a/src/client/ui/ui-inspector.js b/src/client/ui/ui-inspector.js index 22262e6e..ea97e6fa 100644 --- a/src/client/ui/ui-inspector.js +++ b/src/client/ui/ui-inspector.js @@ -31,6 +31,25 @@ class UiInspector extends UiWidget { }) + this.container.addEventListener('click', (e)=>{ + + var node = e.target + + if (node.tagName === 'OSC-INSPECTOR-CHECKBOX') { + + var name = node.getAttribute('name') + + var textarea = DOM.get(this.container, `textarea[name="${name}"]`) + if (textarea) { + textarea[0].value = !node.classList.contains('on') + DOM.dispatchEvent(textarea[0], 'change') + } + + } + + }) + + this.container.addEventListener('change', this.onChange.bind(this)) this.container.addEventListener('keydown', this.onKeydown.bind(this)) this.container.addEventListener('input', this.textAutoHeight.bind(this)) @@ -38,23 +57,33 @@ class UiInspector extends UiWidget { this.lock = false + this.clearTimeout = null } clear() { - this.container.innerHTML = '' - this.mounted = false + this.clearTimeout = setTimeout(()=>{ + this.container.innerHTML = '' + this.mounted = false + this.clearTimeout = null + }) } inspect(widgets) { + if (this.clearTimeout) { + clearTimeout(this.clearTimeout) + this.clearTimeout = null + } + var content = html`
` var widget = widgets[0], props = defaults[widget.props.type], - multi = widgets.length > 1 + multi = widgets.length > 1, + tabIndex = 1000 // this.form.appendChild(html` //
@@ -105,7 +134,8 @@ class UiInspector extends UiWidget { widget: widget, name: propName, value: widget.props[propName], - default: defaults[w.props.type][propName] + default: defaults[w.props.type][propName], + tabIndex: tabIndex++ }).container if (!field) continue diff --git a/src/client/widgets/buttons/dropdown.js b/src/client/widgets/buttons/dropdown.js index f796e4ba..123b9315 100644 --- a/src/client/widgets/buttons/dropdown.js +++ b/src/client/widgets/buttons/dropdown.js @@ -21,7 +21,6 @@ class Dropdown extends Widget { values: {type: 'array|object', value: {'Value 1':1,'Value 2':2}, help: [ '`Array` of possible values to switch between : `[1,2,3]`', '`Object` of label:value pairs. Numeric labels must be prepended or appended with a white space (or any other non-numeric character) otherwise the order of the values won\'t be kept', - 'An empty option will always be prepended to values (sends an osc message without any value); it can be hidden by adding `option:first-child{display:none}` to the widget\'s `css`' ]} }) @@ -30,9 +29,15 @@ class Dropdown extends Widget { constructor(options) { - super({...options, html: html`
`}) + super({...options, html: html` + +
+
+
+ `}) this.select = this.widget.appendChild(html``) + this.text = DOM.get(this.widget, '.text')[0] this.values = [] this.keys = [] @@ -80,6 +85,7 @@ class Dropdown extends Widget { var i = this.values.indexOf(v) this.value = this.values[i] + this.text.textContent = this.value if (!options.fromLocal) this.select.selectedIndex = i + 1 diff --git a/src/client/widgets/buttons/menu.js b/src/client/widgets/buttons/menu.js index fe3804b2..e8821dbe 100644 --- a/src/client/widgets/buttons/menu.js +++ b/src/client/widgets/buttons/menu.js @@ -47,11 +47,14 @@ class Menu extends Widget { super({...options, html: html` +
+
`}) this.menu = html`` + this.text = DOM.get(this.widget, '.text')[0] this.opened = false @@ -222,6 +225,8 @@ class Menu extends Widget { } + if (circular) this.menu.appendChild(html`
`) + this.setValue(this.value) @@ -267,7 +272,7 @@ class Menu extends Widget { DOM.each(this.menu, '.on', (el)=>{el.classList.remove('on')}) if (i > -1) DOM.get(this.menu, '.item')[i].classList.add('on') - this.widget.textContent = this.stringValues[i] || this.value + this.text.textContent = this.stringValues[i] || this.value if (options.send) this.sendValue() if (options.sync) this.changed(options) diff --git a/src/client/widgets/buttons/toggle.js b/src/client/widgets/buttons/toggle.js index 0c1b79b7..4d3c7698 100644 --- a/src/client/widgets/buttons/toggle.js +++ b/src/client/widgets/buttons/toggle.js @@ -52,7 +52,7 @@ class Toggle extends Widget { if (this.getProp('doubleTap')) { - doubletab(this.container, ()=>{ + doubletab(this.widget, ()=>{ this.setValue(this.getProp('on'), {sync: true, send: true}) @@ -67,7 +67,7 @@ class Toggle extends Widget { this.active = true this.setValue(this.getProp('on'), {sync: true, send: true}) - }, {element: this.container}) + }, {element: this.widget}) } @@ -76,13 +76,13 @@ class Toggle extends Widget { this.active = false this.setValue(this.getProp('off'), {sync: true, send: !tap}) - }, {element: this.container}) + }, {element: this.widget}) } else { if (this.getProp('doubleTap')) { - doubletab(this.container, ()=>{ + doubletab(this.widget, ()=>{ this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true}) @@ -97,13 +97,13 @@ class Toggle extends Widget { this.active = true this.setValue(this.state ? this.getProp('off') : this.getProp('on'), {sync: true, send: true}) - }, {element: this.container}) + }, {element: this.widget}) this.on('dragend',()=>{ this.active = false - }, {element: this.container}) + }, {element: this.widget}) } diff --git a/src/client/widgets/common/canvas.js b/src/client/widgets/common/canvas.js index 16b1ea2a..4f4cb24e 100644 --- a/src/client/widgets/common/canvas.js +++ b/src/client/widgets/common/canvas.js @@ -135,32 +135,22 @@ class Canvas extends Widget { this.cssVars.padding = parseFloat(style.getPropertyValue('--widget-padding')) * PXSCALE // rem unit - this.cssVars.colorWidget = style.getPropertyValue('--color-widget') - this.cssVars.colorFill = style.getPropertyValue('--color-fill') - this.cssVars.colorStroke = style.getPropertyValue('--color-stroke') - this.cssVars.colorForeground = style.getPropertyValue('--color-foreground') - - this.cssVars.alphaStroke = parseFloat(style.getPropertyValue('--alpha-stroke')) - this.cssVars.alphaFillOff = parseFloat(style.getPropertyValue('--alpha-fill-off')) - this.cssVars.alphaFillOn = parseFloat(style.getPropertyValue('--alpha-fill-on')) + 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() + 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.colors.custom = style.getPropertyValue('--color-custom') - this.colors.track = style.getPropertyValue('--color-track') - this.colors.text = style.getPropertyValue('--color-text') - this.colors.textFade = style.getPropertyValue('--color-text-fade') - this.colors.raised = style.getPropertyValue('--color-raised') - this.colors.bg = style.getPropertyValue('--color-bg') - this.colors.fg = style.getPropertyValue('--color-fg') - this.colors.faded = style.getPropertyValue('--color-faded') - this.colors.light = style.getPropertyValue('--color-light') - - this.fontFamily = style.getPropertyValue('font-family') - this.textAlign = style.getPropertyValue('text-align') - this.fontSize = parseFloat(style.getPropertyValue('font-size')) - this.fontWeight = parseFloat(style.getPropertyValue('font-weight')) + this.fontFamily = style.getPropertyValue('font-family').trim() + this.textAlign = style.getPropertyValue('text-align').trim() + this.fontSize = parseFloat(style.getPropertyValue('font-size').trim()) + this.fontWeight = parseFloat(style.getPropertyValue('font-weight').trim()) this.ctx.font = this.fontWeight + ' ' + this.fontSize + 'px ' + this.fontFamily this.ctx.textBaseline = 'middle' @@ -207,6 +197,7 @@ class Canvas extends Widget { switch (propName) { case 'css': + case 'colorText': case 'colorWidget': case 'colorFill': case 'colorStroke': @@ -219,7 +210,12 @@ class Canvas extends Widget { },10) return case 'padding': - resize.check(this.widget) + resize.check(this.canvas, true) + setTimeout(()=>{ + this.cacheCanvasStyle() + this.batchDraw() + },10) + return } return ret diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 12ad15f3..8f4f77ab 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -54,7 +54,7 @@ class Widget extends EventEmitter { '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)' ]}, 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.'}, + interaction: {type: 'boolean', value: true, help: 'Set to `false` to disable pointer interactions.'}, _geometry:'geometry', @@ -78,6 +78,7 @@ class Widget extends EventEmitter { 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.'}, @@ -87,8 +88,8 @@ class Widget extends EventEmitter { _value: 'value', - default: {type: '*', value: '', help: 'If set, the widget will be initialized with this value when the session is loaded.'}, value: {type: '*', value: '', help: 'Define the widget\'s value depending on other widget\'s values / properties using the advanced property syntax'}, + default: {type: '*', value: '', help: 'If set, the widget will be initialized with this value when the session is loaded.'}, linkId: {type: 'string|array', value: '', help: [ 'Widgets sharing the same `linkId` update each other\'s value(s) AND send their respective osc messages.', 'When prefixed with >>, the `linkId` will make the widget act as a master (sending but not receiving)', @@ -192,6 +193,8 @@ class Widget extends EventEmitter { this.container._widget_instance = this this.setContainerStyles() + this.container.classList.toggle('no-interaction', !this.getProp('interaction')) + } contains(widget) { @@ -596,7 +599,7 @@ class Widget extends EventEmitter { // one bracket nesting allowed, if we need two: #\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\} var code = m.substr(2, m.length - 3).trim() - + if (!this.parsers[code]) this.parsers[code] = evaljs('return ' + code, defaultScope) let r = this.parsers[code](jsScope) @@ -755,6 +758,10 @@ class Widget extends EventEmitter { resize.check(this.container) return + case 'interaction': + this.container.classList.toggle('no-interaction', !this.getProp('interaction')) + return + case 'label': this.setContainerStyles(['label']) if (oldPropValue === false || this.getProp('label') === false) { @@ -771,6 +778,7 @@ class Widget extends EventEmitter { } return + case 'colorText': case 'colorWidget': case 'colorFill': case 'colorStroke': @@ -785,7 +793,6 @@ class Widget extends EventEmitter { case 'address': case 'preArgs': case 'target': - case 'noSync': if (propName === 'address') { for (var k in this.oscReceivers) { var receiver = this.oscReceivers[k] @@ -935,21 +942,12 @@ class Widget extends EventEmitter { if (styles.includes('color')) { // color - for (var cssvar of ['color-widget', 'color-fill', 'color-stroke', 'alpha-stroke', 'alpha-fill-on', 'alpha-fill-off']) { + 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' : '') - - // this.container.style.setProperty('--color-widget', this.getProp('colorWidget') && this.getProp('colorWidget') != 'auto' ? this.getProp('colorWidget') : '') - // this.container.style.setProperty('--color-fill', this.getProp('colorFill') != 'auto' ? this.getProp('colorFill') : '') - // this.container.style.setProperty('--color-stroke', this.getProp('colorStroke') != 'auto' ? this.getProp('colorStroke') : '') - // this.container.style.setProperty('--alpha-stroke', this.getProp('alphaStroke') != 'auto' ? parseFloat(this.getProp('alphaStroke')) : '') - // this.container.style.setProperty('--alpha-fill-on', this.getProp('alphaFillOn') != 'auto' ? parseFloat(this.getProp('alphaFillOn')) : '') - // this.container.style.setProperty('--alpha-fill-off', this.getProp('alphaFillOff') != 'auto' ? parseFloat(this.getProp('alphaFillOff')) : '') - // this.container.style.setProperty('--widget-padding', this.getProp('padding') != 'auto' ? parseFloat(this.getProp('padding')) + 'rem' : '') - } return style @@ -978,6 +976,7 @@ Widget.parsersContexts = {} Widget.dynamicProps = [ 'visible', 'label', + 'interaction', 'top', 'left', @@ -985,6 +984,7 @@ Widget.dynamicProps = [ 'width', + 'colorText', 'colorWidget', 'colorFill', 'colorStroke', diff --git a/src/client/widgets/containers/tab.js b/src/client/widgets/containers/tab.js index c624316b..a8974d87 100644 --- a/src/client/widgets/containers/tab.js +++ b/src/client/widgets/containers/tab.js @@ -17,7 +17,7 @@ module.exports = class Tab extends StaticProperties(Panel, {scroll: true}) { _tab:'tab', - detached: {type: 'boolean', value: true, help: 'Set to `false` if the tab contains `frame` widgets that should not be reloaded when the tab opens'}, + // detached: {type: 'boolean', value: true, help: 'Set to `false` if the tab contains `frame` widgets that should not be reloaded when the tab opens'}, layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal'], help:''}, 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'}, diff --git a/src/client/widgets/frames/frame.js b/src/client/widgets/frames/frame.js index 40d2f573..aa16c146 100644 --- a/src/client/widgets/frames/frame.js +++ b/src/client/widgets/frames/frame.js @@ -16,10 +16,6 @@ class Frame extends StaticProperties(Widget, {bypass: true}) { return super.defaults({ - _frame: 'frame', - - border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'}, - }, ['precision', 'bypass'], { label: {type: 'string|boolean', value: 'auto', help: [ @@ -39,7 +35,7 @@ class Frame extends StaticProperties(Widget, {bypass: true}) { super({...options, html: html` - + ` }) diff --git a/src/client/widgets/frames/html.js b/src/client/widgets/frames/html.js index 24c93506..743c83a7 100644 --- a/src/client/widgets/frames/html.js +++ b/src/client/widgets/frames/html.js @@ -29,7 +29,6 @@ class Html extends StaticProperties(Widget, {bypass: true}) { '  b, i, strong, em, strike, code, hr, br, div,', '  table, thead, img, caption, tbody, tr, th, td, pre' ]}, - border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'}, }, ['precision', 'bypass'], {}) diff --git a/src/client/widgets/frames/image.js b/src/client/widgets/frames/image.js index d764f0d3..55729261 100644 --- a/src/client/widgets/frames/image.js +++ b/src/client/widgets/frames/image.js @@ -21,7 +21,6 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) { size: {type: 'string', value: 'cover', help: 'CSS background-size'}, position: {type: 'string', value: 'center', help: 'CSS background-position'}, repeat: {type: 'string', value: 'no-repeat', help: 'CSS background-repeat'}, - border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'}, cache: {type: 'boolean', value: true, help: [ 'Set to false to disable image caching (forces file reload when updating or editing the widget).', 'When true, sending `reload` to the widget reloads its image without changing its value' diff --git a/src/client/widgets/frames/svg.js b/src/client/widgets/frames/svg.js index f51d5f10..50efb105 100644 --- a/src/client/widgets/frames/svg.js +++ b/src/client/widgets/frames/svg.js @@ -23,8 +23,6 @@ class Svg extends StaticProperties(Widget, {bypass: true}) { '- will be wrapped in a `< svg />` element', '- `` commands support a special percent notation (`%x` and `%y`)' ]}, - border: {type: 'boolean', value: true, help: 'Set to `false` to disable the borders and background-color'}, - }, ['precision', 'bypass'], {}) diff --git a/src/client/widgets/graphs/eq.js b/src/client/widgets/graphs/eq.js index dd68e0ee..c4447a4a 100644 --- a/src/client/widgets/graphs/eq.js +++ b/src/client/widgets/graphs/eq.js @@ -1,5 +1,6 @@ var {clip} = require('../utils'), - Plot = require('./plot') + Plot = require('./plot'), + Widget = require('../common/widget') module.exports = class Eq extends Plot { @@ -11,7 +12,7 @@ module.exports = class Eq extends Plot { static defaults() { - return super.defaults({ + return Widget.defaults({ _eq:'eq', @@ -22,7 +23,7 @@ module.exports = class Eq extends Plot { logScaleX: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the x axis (base 10). Set to a `number` to define the logarithm\'s base.'}, smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'}, - }, ['precision', 'bypass'], { + }, ['interaction', 'precision', 'bypass'], { value: {type: 'array', value: '', help: [ 'Each item must be an object with the following properties', diff --git a/src/client/widgets/graphs/plot.js b/src/client/widgets/graphs/plot.js index 1c6fa184..fa97b0e4 100644 --- a/src/client/widgets/graphs/plot.js +++ b/src/client/widgets/graphs/plot.js @@ -3,7 +3,7 @@ var {mapToScale} = require('../utils'), html = require('nanohtml'), StaticProperties = require('../mixins/static_properties') -module.exports = class Plot extends StaticProperties(Canvas, {bypass: true}) { +module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, interaction: false}) { static description() { @@ -28,7 +28,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true}) { smooth: {type: 'boolean|number', value: false, help: 'Set to `true` to make the line smooth. Float values are also acceptable (works fine between `0` and `0.5`)'}, pips:{type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, - }, ['precision', 'bypass'], { + }, ['interaction', 'precision', 'bypass'], { value: {type: 'array|string', value: '', help: [ '- `Array` of `y` values', @@ -87,8 +87,8 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true}) { draw_pips() { - this.ctx.globalAlpha = 1 - this.ctx.fillStyle = this.colors.textFade + this.ctx.fillStyle = this.cssVars.colorText + this.ctx.globalAlpha = this.cssVars.alphaPips var margin = this.cssVars.padding diff --git a/src/client/widgets/graphs/visualizer.js b/src/client/widgets/graphs/visualizer.js index 056173db..f263673f 100644 --- a/src/client/widgets/graphs/visualizer.js +++ b/src/client/widgets/graphs/visualizer.js @@ -4,7 +4,7 @@ var {clip} = require('../utils'), StaticProperties = require('../mixins/static_properties') -module.exports = class Visualizer extends StaticProperties(Plot, {rangeX: {min: '', max: ''}, dots: false, smooth: false}) { +module.exports = class Visualizer extends StaticProperties(Plot, {rangeX: {min: '', max: ''}, dots: false, smooth: false, interaction: false}) { static description() { @@ -24,7 +24,7 @@ module.exports = class Visualizer extends StaticProperties(Plot, {rangeX: {min: logScaleY: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale for the y axis (base 10). Set to a `number` to define the logarithm\'s base.'}, pips:{type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, - }, ['precision', 'bypass'], {}) + }, ['interaction', 'precision', 'bypass'], {}) } diff --git a/src/client/widgets/indicators/led.js b/src/client/widgets/indicators/led.js index 9918f62b..5c48dce3 100644 --- a/src/client/widgets/indicators/led.js +++ b/src/client/widgets/indicators/led.js @@ -3,7 +3,7 @@ var {mapToScale, clip} = require('../utils'), html = require('nanohtml'), StaticProperties = require('../mixins/static_properties') -module.exports = class Led extends StaticProperties(Widget, {bypass: true}) { +module.exports = class Led extends StaticProperties(Widget, {bypass: true, interaction: false}) { static description() { @@ -24,7 +24,7 @@ module.exports = class Led extends StaticProperties(Widget, {bypass: true}) { logScale: {type: 'boolean|number', value: false, help: 'Set to `true` to use logarithmic scale (base 10). Set to a `number` to define the logarithm\'s base.'}, borderRadius: {type: 'string', value: '', help: 'Css border-radius property.'}, - }, ['precision', 'bypass'], { + }, ['interaction', 'precision', 'bypass'], { value: {type: 'number|array|string', value: '', help: [ '- `Number`: if `mode` is set to `intensity`', diff --git a/src/client/widgets/indicators/text.js b/src/client/widgets/indicators/text.js index 031662c4..23be35b1 100644 --- a/src/client/widgets/indicators/text.js +++ b/src/client/widgets/indicators/text.js @@ -3,7 +3,7 @@ var {iconify} = require('../../ui/utils'), html = require('nanohtml'), StaticProperties = require('../mixins/static_properties') -module.exports = class Text extends StaticProperties(Widget, {bypass: true}) { +module.exports = class Text extends StaticProperties(Widget, {bypass: true, interaction: false}) { static description() { @@ -24,7 +24,7 @@ module.exports = class Text extends StaticProperties(Widget, {bypass: true}) { ]}, align: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Css text-align property.'}, - }, ['precision', 'bypass'], {}) + }, ['interaction', 'precision', 'bypass'], {}) } diff --git a/src/client/widgets/inputs/input.js b/src/client/widgets/inputs/input.js index 6d452e67..0df11596 100644 --- a/src/client/widgets/inputs/input.js +++ b/src/client/widgets/inputs/input.js @@ -2,7 +2,7 @@ var Canvas = require('../common/canvas'), {deepCopy} = require('../../utils'), html = require('nanohtml') -module.exports = class Input extends Canvas { +class Input extends Canvas { static description() { @@ -18,7 +18,6 @@ module.exports = class Input extends Canvas { align: {type: 'string', value: 'center', choices: ['center', 'left', 'right'], help: 'Set to `left` or `right` to change text alignment (otherwise center)'}, unit: {type: 'string', value: '', help: 'Unit will be appended to the displayed widget\'s value (it doesn\'t affect osc messages)'}, - editable: {type: 'boolean', value: true, help: 'Set to `false` to make the input non-editable'}, asYouType: {type: 'boolean', value: false, help: 'Set to `true` to make the input send its value at each keystroke'} }) @@ -43,7 +42,8 @@ module.exports = class Input extends Canvas { if (this.getProp('align') === 'right') this.widget.classList.add('right') - if (this.getProp('editable')) { + if (this.getProp('interaction')) { + this.canvas.setAttribute('tabindex', 0) this.canvas.addEventListener('focus', this.focus.bind(this)) this.input = html`` @@ -62,8 +62,7 @@ module.exports = class Input extends Canvas { }) } }) - } else { - this.widget.classList.add('not-editable') + } } @@ -144,7 +143,7 @@ module.exports = class Input extends Canvas { this.clear() - this.ctx.fillStyle = this.colors.text + this.ctx.fillStyle = this.cssVars.colorText if (this.textAlign == 'center') { this.ctx.fillText(v, Math.round(width/2), Math.round(height/2)) @@ -166,3 +165,9 @@ module.exports = class Input extends Canvas { } } + +Input.dynamicProps = Input.prototype.constructor.dynamicProps + .filter(x=>x !== 'interaction') + + +module.exports = Input diff --git a/src/client/widgets/pads/multixy.js b/src/client/widgets/pads/multixy.js index 8fd8feb7..1162d6d2 100644 --- a/src/client/widgets/pads/multixy.js +++ b/src/client/widgets/pads/multixy.js @@ -199,8 +199,8 @@ module.exports = class MultiXy extends Pad { t = (this.labels ? this.getProp('points')[i] : i) + '', length = this.fontSize * t.length - this.ctx.globalAlpha = 1 - this.ctx.fillStyle = this.pads[i].colors.text + this.ctx.fillStyle = this.pads[i].cssVars.colorText + this.ctx.globalAlpha = this.cssVars.alphaPips this.ctx.fillText(t, x + 0.5 * PXSCALE, y + PXSCALE) this.clearRect[i] = [x - length / 2, y - this.fontSize / 2, length, this.fontSize + 2 * PXSCALE] diff --git a/src/client/widgets/pads/xy.js b/src/client/widgets/pads/xy.js index 1beb4b75..1a0d1303 100644 --- a/src/client/widgets/pads/xy.js +++ b/src/client/widgets/pads/xy.js @@ -213,9 +213,9 @@ module.exports = class Xy extends Pad { var pipTexts = margin >= this.fontSize * 1.5 this.ctx.lineWidth = PXSCALE - this.ctx.fillStyle = this.colors.textFade + this.ctx.fillStyle = this.cssVars.colorText this.ctx.strokeStyle = this.cssVars.colorStroke - this.ctx.globalAlpha = 1 + this.ctx.globalAlpha = this.cssVars.alphaPips this.ctx.beginPath() for (let i in this.faders.x.rangeKeys) { diff --git a/src/client/widgets/sliders/knob.js b/src/client/widgets/sliders/knob.js index f0179926..5ecdf966 100644 --- a/src/client/widgets/sliders/knob.js +++ b/src/client/widgets/sliders/knob.js @@ -107,8 +107,8 @@ module.exports = class Knob extends Slider { if (e.traversing || this.getProp('mode') === 'circular') { // circular - var diff = this.angleToPercent(this.coordsToAngle(offsetX, offsetY)) - this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY)) - if (Math.abs(diff) < 50 && diff !== 0) this.percent += diff + var diff = this.angleToPercent(this.coordsToAngle(offsetX, offsetY), true) - this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY), true) + if (Math.abs(diff) < 50 && diff !== 0) this.percent += diff * 360 / this.maxAngle } else { @@ -139,9 +139,11 @@ module.exports = class Knob extends Slider { } - angleToPercent(angle) { + angleToPercent(angle, ignoreMaxAngle=false) { - return clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100 + return ignoreMaxAngle ? + clip(angle, [0, 360]) / 360 * 100 + : clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100 } @@ -238,9 +240,9 @@ module.exports = class Knob extends Slider { if (pips) { - this.ctx.globalAlpha = 1 this.ctx.lineWidth = 1.5 * PXSCALE this.ctx.strokeStyle = this.cssVars.colorStroke + this.ctx.globalAlpha = this.cssVars.alphaStroke for (var pip of this.rangeKeys.concat(this.valueToPercent(this.originValue))) { @@ -257,7 +259,8 @@ module.exports = class Knob extends Slider { } var radius = maxRadius + this.fontSize * 1.5 - this.ctx.fillStyle = this.colors.textFade + this.ctx.fillStyle = this.cssVars.colorText + this.ctx.globalAlpha = this.cssVars.alphaPips for (var p in this.pipTexts) { if (this.pipTexts[p] == undefined) continue var angle = this.percentToAngle(p), diff --git a/src/scss/ui/inspector.scss b/src/scss/ui/inspector.scss index c015c7bf..02cb44d8 100644 --- a/src/scss/ui/inspector.scss +++ b/src/scss/ui/inspector.scss @@ -143,6 +143,7 @@ osc-inspector-checkbox { color: transparent; margin-top: -1rem; margin-left: 1rem; + pointer-events: none; } &.on { position: relative; @@ -220,7 +221,17 @@ osc-inspector-select { width: $field-height; background: var(--color-foreground); margin-left: 4rem; + + cursor: pointer; + -webkit-appearance:none; -moz-appearance:none; appearance:none; + + &::-webkit-color-swatch { + border: none; + } + &::-webkit-color-swatch-wrapper { + padding: 0; + } } diff --git a/src/scss/widgets.scss b/src/scss/widgets.scss index 7e40774c..d274baae 100644 --- a/src/scss/widgets.scss +++ b/src/scss/widgets.scss @@ -25,6 +25,9 @@ --alpha-fill-on: 0.25; --alpha-fill: var(--alpha-fill-off); + --alpha-pips: 0.7; + + color: var(--color-text); @@ -66,6 +69,13 @@ flex: 1; } + &.no-interaction { + pointer-events: none; + > * { + pointer-events: none + } + } + } diff --git a/src/scss/widgets/buttons.scss b/src/scss/widgets/buttons.scss index b319478f..1f0365af 100644 --- a/src/scss/widgets/buttons.scss +++ b/src/scss/widgets/buttons.scss @@ -90,6 +90,15 @@ } +// @keyframes menu-widget-fade { +// 0% { +// transform: scale(0) +// } +// 100% { +// transform: scale(1) +// } +// } + .menu-container { --alpha-fill: 0.75; @@ -114,25 +123,41 @@ inner { flex:1; display: flex; - flex-direction: column; + flex-direction: row; justify-content: center; align-items: center; position: relative; @include pseudo-stroke(); + } - padding: 4rem; + .text { + flex: 1; + text-align: center; + display: flex; + justify-content: center; + align-items: center; + } + .icon { + order: 1; + display: block; + display: flex; + justify-content: center; + align-items: center; + width: 30rem; + height: calc(100% - 2rem); + font-family: FontAwesome; + color: var(--color-stroke); + font-size: 120%; + border-left: 1rem solid var(--color-stroke); + opacity: var(--alpha-stroke); + margin: 1rem 0; &:after { content:"\f0d7"; - font-family: FontAwesome; - position: absolute; - color: var(--color-stroke); - right: calc(var(--widget-padding) + 8rem); margin-top: -1rem; - font-size: 120%; - opacity: var(--alpha-fill) } } + menu { // animation: menu-widget-fade .1s forwards; @@ -305,3 +330,80 @@ } } + + +.dropdown-container { + + --alpha-fill: 0.75; + --widget-padding: 1rem; + + border-radius: 0!important; // border radius breaks it somehow + z-index: initial!important; + // contain: style size; + + --size: 300rem; + --grid-columns: 2; + overflow: hidden; + + + &.on { + z-index: 9999999999999!important; + contain: layout; + overflow: visible; + } + + + inner { + flex:1; + display: flex; + flex-direction: row; + justify-content: center; + align-items: stretch; + position: relative; + @include pseudo-stroke(); + } + + .text { + flex: 1; + text-align: center; + display: flex; + justify-content: center; + align-items: center; + } + .icon { + order: 1; + display: block; + display: flex; + justify-content: center; + align-items: center; + width: 30rem; + font-family: FontAwesome; + color: var(--color-stroke); + font-size: 120%; + border-left: 1rem solid var(--color-stroke); + opacity: var(--alpha-stroke); + &:after { + content:"\f0d7"; + margin-top: -1rem; + } + } + + select { + position: absolute; + top:0; + left:0; + right:0; + bottom:0; + width: 100%; + -webkit-appearance:none; + -moz-appearance:none; + appearance:none; + background: var(--color-foreground); + opacity: 0; + } + + option:first-child{ + display:none + } + +} diff --git a/src/scss/widgets/frames.scss b/src/scss/widgets/frames.scss index 8619d12e..48267ca5 100644 --- a/src/scss/widgets/frames.scss +++ b/src/scss/widgets/frames.scss @@ -14,6 +14,8 @@ } .frame { + position: relative; + width: 100%; flex: 1; } diff --git a/src/scss/widgets/indicators.scss b/src/scss/widgets/indicators.scss index d33f5be0..86addc76 100644 --- a/src/scss/widgets/indicators.scss +++ b/src/scss/widgets/indicators.scss @@ -4,7 +4,11 @@ --alpha-fill-off: 0; --alpha-fill-on: 1; + will-change: --opacity; + inner { + + --color-fill: var(--color-led); --alpha-fill: calc(var(--alpha-fill-off) + var(--opacity) * (var(--alpha-fill-on) - var(--alpha-fill-off))); @@ -17,6 +21,7 @@ &:before, &:after { border-radius: var(--border-radius); + will-change: opacity; } }