From 49ac867c636a3be7423d60d826cbd3e7448c9087 Mon Sep 17 00:00:00 2001 From: bordun Date: Fri, 6 Mar 2020 15:42:23 +0100 Subject: [PATCH] be4 copy paste any widget --- src/client/dom.js | 4 +- src/client/editor/context-menu.js | 64 +-------- src/client/editor/index.js | 6 +- src/client/locales/en.js | 1 + src/client/remote-control.js | 23 ++-- src/client/ui/notifications.js | 7 +- src/client/ui/ui-tree.js | 16 +++ src/client/widgets/buttons/switch.js | 11 +- src/client/widgets/common/widget.js | 10 +- src/client/widgets/containers/clone.js | 2 +- src/client/widgets/containers/panel.js | 23 +++- src/client/widgets/containers/root.js | 2 + src/client/widgets/containers/tab.js | 2 + src/client/widgets/sliders/fader.js | 11 +- src/client/widgets/sliders/knob.js | 153 +++++++++++++++------- src/client/widgets/sliders/range.js | 171 +++++++++++++++++++------ src/client/widgets/sliders/slider.js | 2 + src/scss/index.scss | 1 - src/scss/sidepanel.scss | 148 --------------------- src/scss/ui/contextmenu.scss | 4 +- src/scss/ui/notifications.scss | 2 +- src/scss/ui/workspaces.scss | 5 + src/scss/widgets.old.scss | 4 +- src/scss/widgets.old/inputs.scss | 2 +- src/scss/widgets.old/matrices.scss | 2 +- src/scss/widgets.old/panel.scss | 2 +- src/scss/widgets.old/plots.scss | 2 +- src/scss/widgets.old/switch.scss | 4 +- src/scss/widgets.scss | 2 +- src/scss/widgets/buttons.scss | 9 +- src/scss/widgets/containers.scss | 67 ++++++++-- src/scss/widgets/sliders.scss | 6 + 32 files changed, 412 insertions(+), 356 deletions(-) delete mode 100644 src/scss/sidepanel.scss diff --git a/src/client/dom.js b/src/client/dom.js index 4466bb4b..cb455cfe 100644 --- a/src/client/dom.js +++ b/src/client/dom.js @@ -82,7 +82,7 @@ module.exports = { return parent ? Array.prototype.indexOf.call(parent.children, element) : -1 }, - offset: function(element) { + offset: function(element, container) { var offsetLeft = 0, offsetTop = 0 @@ -95,7 +95,7 @@ module.exports = { if (!isNaN(element.offsetTop)) { offsetTop += element.offsetTop - element.scrollTop } - } while ((element = element.offsetParent)) + } while ((element = element.offsetParent) && element !== container) } return { diff --git a/src/client/editor/context-menu.js b/src/client/editor/context-menu.js index 8f8fc0d1..d069492b 100644 --- a/src/client/editor/context-menu.js +++ b/src/client/editor/context-menu.js @@ -52,23 +52,6 @@ var handleClick = function(event) { parent = editor.selectedWidgets[0].parent, actions = [] - // case root: only "add tab" option - // if (parent === widgetManager) { - // actions.push({ - // label: icon('plus') + ' ' + locales('editor_addtab'), - // action: ()=>{ - // data[0].tabs.push({}) - // - // var indexes = {addedIndexes: [data[0].tabs.length -1]} - // updateWidget(editor.selectedWidgets[0], indexes) - // editor.pushHistory(indexes) - // } - // }) - // contextMenu.open(eventData, actions) - // - // return - // } - // case !root var clickX = Math.round((eventData.offsetX + eventData.target.scrollLeft) / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH, @@ -76,6 +59,13 @@ var handleClick = function(event) { if (type === 'widget' && parent !== widgetManager) { + if (event.target.tagName !== 'LI') actions.push({ + label: icon('project-diagram') + ' ' + locales('editor_show_in_tree'), + action: ()=>{ + editor.widgetTree.showWidget(editor.selectedWidgets[0]) + } + }) + actions.push({ label: icon('copy') + ' ' + locales('editor_copy'), action: editor.copyWidget.bind(editor) @@ -86,46 +76,6 @@ var handleClick = function(event) { action: editor.cutWidget.bind(editor) }) - // var wrapActions = [] - // for (let c of categories.Containers) { - // if (c === 'clone') continue - // wrapActions.push({ - // label: c, - // action: ()=>{ - // var wrap = {type: c, widgets:[], label: c === 'modal' ? 'auto' : false} - // - // wrap.widgets = data - // - // var minTop = Math.min(...data.map(x=>isNaN(x.top) ? x.top == 'auto' ? 0 : Infinity : x.top)) - // var minLeft = Math.min(...data.map(x=>isNaN(x.left) ? x.left == 'auto' ? 0 : Infinity : x.left)) - // - // wrap.top = minTop === Infinity ? data[0].top : minTop - // wrap.left= minLeft === Infinity ? data[0].left : minLeft - // - // for (var w of wrap.widgets) { - // if (!isNaN(w.top)) w.top = Math.max(w.top - minTop, 0) - // if (!isNaN(w.left)) w.left = Math.max(w.left - minLeft, 0) - // } - // - // var i - // for (i of index) { - // parent.props.widgets.splice(i,1) - // } - // - // parent.props.widgets = parent.props.widgets.slice(0, i).concat(wrap, parent.props.widgets.slice(i, parent.props.widgets.length)) - // - // editor.select(updateWidget(parent, {preventSelect: true, removedIndexes: index, addedIndexes: [i]})) - // editor.pushHistory({removedIndexes: index, addedIndexes: [i]}) - // - // } - // }) - // } - // - // actions.push({ - // label: icon('layer-group') + ' ' + locales('editor_wrap'), - // action: wrapActions - // }) - } diff --git a/src/client/editor/index.js b/src/client/editor/index.js index 0372c35d..b904d497 100644 --- a/src/client/editor/index.js +++ b/src/client/editor/index.js @@ -9,6 +9,7 @@ var {updateWidget, incrementWidget} = require('./data-workers'), UiInspector = require('../ui/ui-inspector'), UiTree = require('../ui/ui-tree'), UiDragResize = require('../ui/ui-dragresize'), + Panel = require('../widgets/containers/panel'), sidepanel = require('../ui/ui-sidepanel'), html = require('nanohtml'), sessionManager @@ -500,6 +501,7 @@ var Editor = class Editor { pasteWidget(x, y, increment) { if (!this.selectedWidgets.length || this.clipboard === null) return + if (!(this.selectedWidgets[0] instanceof Panel)) return var data = this.selectedWidgets.map((w)=>w.props) @@ -618,7 +620,7 @@ var Editor = class Editor { nH = w.container.offsetHeight + deltaH } - if (w.props.width !== undefined) { + if (w.props.width !== undefined && w.parent.getProp('layout') !== 'vertical') { var newWidth = Math.max(nW, GRIDWIDTH) / PXSCALE if (typeof w.props.width === 'string' && w.props.width.indexOf('%') > -1) { w.props.width = (100 * PXSCALE * newWidth / w.container.parentNode.offsetWidth).toFixed(2) + '%' @@ -627,7 +629,7 @@ var Editor = class Editor { } } - if (w.props.height !== undefined) { + if (w.props.height !== undefined && w.parent.getProp('layout') !== 'horizontal') { var newHeight = Math.max(nH, GRIDWIDTH) / PXSCALE if (typeof w.props.height === 'string' && w.props.height.indexOf('%') > -1) { w.props.height = (100 * PXSCALE * newHeight / w.container.parentNode.offsetHeight).toFixed(2) + '%' diff --git a/src/client/locales/en.js b/src/client/locales/en.js index bbd4c4f0..1386923e 100644 --- a/src/client/locales/en.js +++ b/src/client/locales/en.js @@ -8,6 +8,7 @@ module.exports = { editor_inspector: 'Inspector', // editor context-menu + editor_show_in_tree: 'Show in tree', editor_copy: 'Copy', editor_cut: 'Cut', editor_wrap: 'Wrap in', diff --git a/src/client/remote-control.js b/src/client/remote-control.js index 70db4bb4..fa9afd9c 100644 --- a/src/client/remote-control.js +++ b/src/client/remote-control.js @@ -2,7 +2,8 @@ var {updateWidget} = require('./editor/data-workers'), editor = require('./editor'), widgetManager = require('./managers/widgets'), stateManager = require('./managers/state'), - deepExtend = require('deep-extend') + deepExtend = require('deep-extend'), + notifications = require('./ui/notifications') var callbacks = { '/EDIT': function(args) { @@ -213,26 +214,18 @@ var callbacks = { stateManager.quickLoad() }, - '/TABS': function(args) { + '/NOTIFY': function(args) { if (!Array.isArray(args)) args = [args] + console.log(args) + notifications.add({ + message: args.join('\n') + }) - for (let id of args) { - let ws = widgetManager.getWidgetById(id) - for (let w of ws) { - if (w.getProp('type') === 'tab') { - var index = w.parent.children.indexOf(w) - w.parent.setValue(index, {sync: true, send: false}) - } - } - } + }, - } } -// backward-compatibility -callbacks['/EDIT_SOFT'] = callbacks['/EDIT/MERGE'] - module.exports = { exec: function(name, args){ if (callbacks[name]) { diff --git a/src/client/ui/notifications.js b/src/client/ui/notifications.js index 37e91168..6557b6ec 100644 --- a/src/client/ui/notifications.js +++ b/src/client/ui/notifications.js @@ -20,11 +20,12 @@ class Toast { var toast = html`
-
- ${data.message} -
+
` + + DOM.get(toast, '.content')[0].textContent = data.message + if (this.html) { this.html = morph(this.html, toast) } else { diff --git a/src/client/ui/ui-tree.js b/src/client/ui/ui-tree.js index 0ecdb5d3..1d6eac1e 100644 --- a/src/client/ui/ui-tree.js +++ b/src/client/ui/ui-tree.js @@ -118,6 +118,22 @@ class UiTree extends UiWidget { } + showWidget(widget) { + + var node = DOM.get(this.list, `[data-widget="${widget.hash}"]`) + if (node) { + var parent = node[0].parentNode + while (parent !== this.list) { + if (parent.classList.contains('container')) { + parent.classList.add('expanded') + } + parent = parent.parentNode + } + node[0].scrollIntoView({block: 'center'}) + } + + } + select() { // hint selection in folded containers diff --git a/src/client/widgets/buttons/switch.js b/src/client/widgets/buttons/switch.js index bda1b39e..769de3f9 100644 --- a/src/client/widgets/buttons/switch.js +++ b/src/client/widgets/buttons/switch.js @@ -17,7 +17,8 @@ class Switch extends Widget { _switch:'switch', - horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display values horizontally'}, + layout: {type: 'string', value: 'vertical', choices: ['vertical', 'horizontal', 'grid'], help:''}, + gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns of a value css grid-template definition.'}, showValues: {type: 'boolean', value: false, help: 'If values is an object, set to `true` to display both values and labels instead of labels only'}, values: {type: 'array|object', value: {'Value 1':1,'Value 2':2}, help: [ '`Array` of possible values to switch between : `[1,2,3]`', @@ -39,7 +40,13 @@ class Switch extends Widget { super({...options, html: html``}) - if (this.getProp('horizontal')) this.container.classList.add('horizontal') + this.container.classList.add('layout-' + this.getProp('layout')) + + if (this.getProp('layout') === 'grid') { + var template = this.getProp('gridTemplate') || 2 + this.widget.style.gridTemplate = template === parseInt(template) ? `none / repeat(${template}, 1fr)` : template + } + this.values = [] this.stringValues = [] diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 626713cd..d9737300 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -68,6 +68,7 @@ class Widget extends EventEmitter { ]}, width: {type: 'number|percentage', value: 'auto', help: ''}, height: {type: 'number|percentage', value: 'auto', help: ''}, + expand: {type: 'boolean|number', value: 'false', help: 'If parent\'s layout is `vertical` or `horizontal`, set this to `true` to stretch the widget to use available space automatically.'}, _style:'style', @@ -756,6 +757,7 @@ class Widget extends EventEmitter { case 'height': case 'width': + case 'expand': this.setContainerStyles(['geometry']) var container = this.parent !== widgetManager && this.parent.getProp('layout') !== 'default' ? this.parent.container : this.container resize.check(container) @@ -851,6 +853,7 @@ class Widget extends EventEmitter { } } this.container.classList.toggle('absolute-position', absolutePos) + this.container.classList.toggle('flex-expand', this.getProp('expand')) } @@ -859,13 +862,13 @@ class Widget extends EventEmitter { // label if (this.getProp('label') === false) { - this.container.classList.add('nolabel') + this.container.classList.add('no-label') this.label.innerHTML = '' } else { - this.container.classList.remove('nolabel') + this.container.classList.remove('no-label') var label = this.getProp('label') == 'auto'? this.getProp('id'): - iconify(this.getProp('label')) + iconify(this.getProp('label').replace(/`) + this.navigation = this.widget.appendChild(html``) this.children = options.children || new Array(this.getProp('tabs').length) for (let i = 0; i < this.children.length; i++) { @@ -156,11 +168,12 @@ class Panel extends Container() { if (!widget.getProp('visible')) style += 'display:none;' this.tabs.push(widget) - this.navigation.appendChild(html` + var label = html` - `) + ` + label.innerHTML = widget.label.innerHTML + this.navigation.appendChild(label) }) diff --git a/src/client/widgets/containers/root.js b/src/client/widgets/containers/root.js index 43eb07ab..0ff173a1 100644 --- a/src/client/widgets/containers/root.js +++ b/src/client/widgets/containers/root.js @@ -22,7 +22,9 @@ class Root extends StaticProperties(Panel, {scroll: false, label: false, id: 'ro colorPanel: {type: 'string', value: 'auto', help:''}, layout: {type: 'string', value: 'default', choices: ['default', 'vertical', 'horizontal', 'grid'], help:''}, + justify: {type: 'string', value: 'start', choices: ['start', 'end', 'center', 'space-around', 'space-between'], help:'If `layout` is `vertical` or `horizontal`, defines how widgets should be justified.'}, gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns of a value css grid-template definition.'}, + verticalTabs: {type: 'boolean', value: false, help: 'Set to `true` to display for vertical tab layout'}, 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'}, diff --git a/src/client/widgets/containers/tab.js b/src/client/widgets/containers/tab.js index fb9c1651..f8b75263 100644 --- a/src/client/widgets/containers/tab.js +++ b/src/client/widgets/containers/tab.js @@ -18,7 +18,9 @@ module.exports = class Tab extends Panel { // 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', 'grid'], help:''}, + justify: {type: 'string', value: 'start', choices: ['start', 'end', 'center', 'space-around', 'space-between'], help:'If `layout` is `vertical` or `horizontal`, defines how widgets should be justified.'}, gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns of a value css grid-template definition.'}, + verticalTabs: {type: 'boolean', value: false, help: 'Set to `true` to display for vertical tab layout'}, 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'}, scroll: {type: 'boolean', value: true, help: 'Set to `false` to disable scrollbars'}, 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/sliders/fader.js b/src/client/widgets/sliders/fader.js index 7fdd472a..c39e7455 100644 --- a/src/client/widgets/sliders/fader.js +++ b/src/client/widgets/sliders/fader.js @@ -17,9 +17,8 @@ module.exports = class Fader extends Slider { _fader:'fader', - mode: {type: 'string', value: 'compact', choices: ['compact', 'classic', 'round'], help: 'Design style'}, + design: {type: 'string', value: 'compact', choices: ['compact', 'classic', 'round'], help: 'Design style'}, horizontal: {type: 'boolean', value: false, help: 'Set to `true` to display the fader horizontally'}, - alignRight: {type: 'boolean', value: false, help: 'Set to `true` to invert the pip\'s and fader\'s position'}, pips: {type: 'boolean', value: false, help: 'Set to `true` to show range breakpoints'}, dashed: {type: 'boolean', value: false, help: 'Set to `true` to display a dashed gauge'}, gradient: {type: 'array|object', value: [], help: [ @@ -65,8 +64,6 @@ module.exports = class Fader extends Slider { this.gaugeGradient = null - this.container.classList.add('design-' + this.getProp('mode')) - } draginitHandle(e) { @@ -180,7 +177,7 @@ module.exports = class Fader extends Slider { o = Math.round(this.percentToCoord(this.valueToPercent(this.originValue))), m = this.getProp('horizontal') ? this.height / 2 : this.width / 2, dashed = this.getProp('dashed'), - compact = this.getProp('mode') === 'compact' + compact = this.getProp('design') === 'compact' this.clear() @@ -256,7 +253,7 @@ module.exports = class Fader extends Slider { this.clearRect = [0, 0, width, height] - } else if (this.getProp('mode') === 'classic') { + } else if (this.getProp('design') === 'classic') { if (this.cssVars.alphaStroke) { @@ -342,7 +339,7 @@ module.exports = class Fader extends Slider { var width = this.getProp('horizontal') ? this.height : this.width, height = !this.getProp('horizontal') ? this.height : this.width, m = this.getProp('horizontal') ? this.height / 2 : this.width / 2, - compact = this.getProp('mode') === 'compact' + compact = this.getProp('design') === 'compact' if (width % 2 && parseInt(m) !== m) m -= 0.5 diff --git a/src/client/widgets/sliders/knob.js b/src/client/widgets/sliders/knob.js index fd027fc5..2c91d32b 100644 --- a/src/client/widgets/sliders/knob.js +++ b/src/client/widgets/sliders/knob.js @@ -15,6 +15,7 @@ module.exports = class Knob extends Slider { _knob:'knob', + design: {type: 'string', value: 'default', choices: ['default', 'classic'], help: 'Design style'}, mode: {type: 'string', value: 'vertical', choices: ['vertical', 'circular', 'snap'], help: [ '- `circular`: relative move in circular motion', '- `snap`: snap to touch position and move in vertical motion', @@ -181,58 +182,118 @@ module.exports = class Knob extends Slider { this.clear() - // fill - this.ctx.strokeStyle = this.cssVars.colorFill - this.ctx.lineWidth = gaugeWidth - this.gaugePadding * 2 + if (this.getProp('design') === 'default') { + + // fill + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = gaugeWidth - this.gaugePadding * 2 + + if (this.cssVars.alphaFillOff) { + this.ctx.globalAlpha = this.cssVars.alphaFillOff + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min, max) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash([1.5 * PXSCALE, 1.5 * PXSCALE]) + + if (this.cssVars.alphaFillOn) { + this.ctx.globalAlpha = this.cssVars.alphaFillOn + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, o, d, o > d) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash([]) + + + // stroke + + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.strokeStyle = this.cssVars.colorStroke + this.ctx.lineWidth = PXSCALE - if (this.cssVars.alphaFillOff) { - this.ctx.globalAlpha = this.cssVars.alphaFillOff this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min, max) + this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI) this.ctx.stroke() + + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI) + this.ctx.stroke() + + + // knob + + this.ctx.globalAlpha = 1 + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = 1.5 * PXSCALE + + let r1 = minRadius + this.gaugePadding, + r2 = maxRadius - this.gaugePadding, + a = 2 * Math.PI - d + + this.ctx.beginPath() + this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a)) + this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a)) + this.ctx.stroke() + + } else { + + // fill + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = 2 * PXSCALE + + if (this.cssVars.alphaFillOff) { + this.ctx.globalAlpha = this.cssVars.alphaFillOff + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, min, max) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash([1.5 * PXSCALE, 1.5 * PXSCALE]) + + if (this.cssVars.alphaFillOn) { + this.ctx.globalAlpha = this.cssVars.alphaFillOn + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, o, d, o > d) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash([]) + + + + // center + this.ctx.fillStyle = this.cssVars.colorPanel + this.ctx.strokeStyle = this.cssVars.colorStroke + this.ctx.lineWidth = 1 * PXSCALE + + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius - (2 + this.cssVars.padding) * PXSCALE, 0, 2 * Math.PI) + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.stroke() + this.ctx.globalAlpha = 1 + // this.ctx.fill() + + + + // knob + this.ctx.globalAlpha = 1 + this.ctx.fillStyle = this.cssVars.colorFill + this.ctx.lineWidth = 1.5 * PXSCALE + + let r1 = maxRadius - (8 + this.cssVars.padding) * PXSCALE, + r2 = maxRadius / 3 , + a = 2 * Math.PI - d + + this.ctx.beginPath() + this.ctx.arc(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a), 1.5 * PXSCALE, 0, 2*Math.PI) + this.ctx.fill() + + } - if (dashed) this.ctx.setLineDash([1.5 * PXSCALE, 1.5 * PXSCALE]) - if (this.cssVars.alphaFillOn) { - this.ctx.globalAlpha = this.cssVars.alphaFillOn - this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, o, d, o > d) - this.ctx.stroke() - } - - if (dashed) this.ctx.setLineDash([]) - - - // stroke - - this.ctx.globalAlpha = this.cssVars.alphaStroke - this.ctx.strokeStyle = this.cssVars.colorStroke - this.ctx.lineWidth = PXSCALE - - this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI) - this.ctx.stroke() - - this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI) - this.ctx.stroke() - - - // knob - - this.ctx.globalAlpha = 1 - this.ctx.strokeStyle = this.cssVars.colorFill - this.ctx.lineWidth = 1.5 * PXSCALE - - let r1 = minRadius + this.gaugePadding, - r2 = maxRadius - this.gaugePadding, - a = 2 * Math.PI - d - - this.ctx.beginPath() - this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a)) - this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a)) - this.ctx.stroke() // pips diff --git a/src/client/widgets/sliders/range.js b/src/client/widgets/sliders/range.js index dfa7d20b..b49f3dbf 100644 --- a/src/client/widgets/sliders/range.js +++ b/src/client/widgets/sliders/range.js @@ -3,12 +3,11 @@ var {clip} = require('../utils'), Fader = require('./fader'), Input = require('../inputs/input'), touchstate = require('../mixins/touch_state'), - html = require('nanohtml'), - StaticProperties = require('../mixins/static_properties') + html = require('nanohtml') var faderDefaults = Fader.defaults()._props() -class Range extends StaticProperties(Fader, {mode: 'compact'}) { +class Range extends Fader { static description() { @@ -16,15 +15,6 @@ class Range extends StaticProperties(Fader, {mode: 'compact'}) { } - static defaults() { - - var defaults = super.defaults() - delete defaults.mode - - return defaults - - } - constructor(options) { options.multitouch = true @@ -209,19 +199,36 @@ class Range extends StaticProperties(Fader, {mode: 'compact'}) { var d = Math.round(fader.percentToCoord(fader.valueToPercent(this.faders[this.getProp('horizontal')?0:1].value))), d2 = Math.round(fader.percentToCoord(fader.valueToPercent(this.faders[this.getProp('horizontal')?1:0].value))), - m = Math.round(this.getProp('horizontal') ? this.height / 2 : this.width / 2) - - // sharp border trick - if (width % 2 && parseInt(m) === m) m -= 0.5 - - var dashed = this.getProp('dashed') + m = this.getProp('horizontal') ? this.height / 2 : this.width / 2, + dashed = this.getProp('dashed'), + compact = this.getProp('design') === 'compact' this.clear() + if (this.getProp('pips') && !compact) m -= 10 * PXSCALE + + // sharp border trick + if (compact) { + if (width % 2 && parseInt(m) === m) m -= 0.5 + } else { + if (width % 2 && parseInt(m) !== m) m -= 0.5 + } + + this.ctx.strokeStyle = this.gaugeGradient || this.cssVars.colorFill - this.ctx.lineWidth = Math.round(width - this.gaugePadding * 2) + + if (compact) { + this.ctx.lineWidth = Math.round(width - this.gaugePadding * 2) + } else { + this.ctx.lineWidth = 2 * PXSCALE + } + + + if (dashed) this.ctx.setLineDash([PXSCALE, PXSCALE]) + if (this.cssVars.alphaFillOff) { + // gaugo off this.ctx.globalAlpha = this.cssVars.alphaFillOff this.ctx.beginPath() this.ctx.moveTo(m, height - this.gaugePadding) @@ -229,12 +236,9 @@ class Range extends StaticProperties(Fader, {mode: 'compact'}) { this.ctx.stroke() } - if (dashed) { - this.ctx.lineDashOffset = d % 2 ? PXSCALE : 0 // avoid flickering - this.ctx.setLineDash([PXSCALE, PXSCALE]) - } if (this.cssVars.alphaFillOn) { + // gaugo on this.ctx.globalAlpha = this.cssVars.alphaFillOn this.ctx.beginPath() this.ctx.moveTo(m, d) @@ -244,31 +248,114 @@ class Range extends StaticProperties(Fader, {mode: 'compact'}) { if (dashed) this.ctx.setLineDash([]) - this.ctx.globalAlpha = this.cssVars.alphaStroke - this.ctx.strokeStyle = this.cssVars.colorStroke + if (compact) { - this.ctx.beginPath() - this.ctx.moveTo(0, 0) - this.ctx.lineTo(width, 0) - this.ctx.lineTo(width, height) - this.ctx.lineTo(0, height) - this.ctx.closePath() - this.ctx.lineWidth = 2 * PXSCALE - this.ctx.stroke() + // stroke + + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.strokeStyle = this.cssVars.colorStroke + + this.ctx.beginPath() + this.ctx.moveTo(0, 0) + this.ctx.lineTo(width, 0) + this.ctx.lineTo(width, height) + this.ctx.lineTo(0, height) + this.ctx.closePath() + this.ctx.lineWidth = 2 * PXSCALE + this.ctx.stroke() - this.ctx.globalAlpha = 1 - this.ctx.fillStyle = this.cssVars.colorFill + // flat knob - this.ctx.beginPath() - this.ctx.rect(this.gaugePadding, Math.min(d, height - 3 * PXSCALE), width - this.gaugePadding * 2, PXSCALE) - this.ctx.fill() + this.ctx.globalAlpha = 1 + this.ctx.fillStyle = this.cssVars.colorFill - this.ctx.beginPath() - this.ctx.rect(this.gaugePadding, Math.min(d2, height - 3 * PXSCALE), width - this.gaugePadding * 2, PXSCALE) - this.ctx.fill() + this.ctx.beginPath() + this.ctx.rect(this.gaugePadding, Math.min(d, height - this.gaugePadding - PXSCALE), width - this.gaugePadding * 2, PXSCALE) + this.ctx.fill() + + // extra knob + this.ctx.beginPath() + this.ctx.rect(this.gaugePadding, Math.min(d2, height - this.gaugePadding - PXSCALE), width - this.gaugePadding * 2, PXSCALE) + this.ctx.fill() + + + this.clearRect = [0, 0, width, height] + + + } else if (this.getProp('design') === 'classic') { + + for (let _d of [d, d2]) { + + if (this.cssVars.alphaStroke) { + + this.ctx.globalAlpha = 1 + this.ctx.fillStyle = this.cssVars.colorPanel + + this.ctx.beginPath() + this.ctx.rect(m - 6 * PXSCALE, _d - 10 * PXSCALE, 12 * PXSCALE, 20 * PXSCALE) + this.ctx.fill() + + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.strokeStyle = this.cssVars.colorStroke + this.ctx.lineWidth = PXSCALE + + this.ctx.beginPath() + this.ctx.rect(m - 5.5 * PXSCALE, _d - 9.5 * PXSCALE, 11 * PXSCALE, 19 * PXSCALE) + this.ctx.stroke() + + } + + this.ctx.globalAlpha = 1 + this.ctx.fillStyle = this.cssVars.colorWidget + + this.ctx.beginPath() + this.ctx.rect(m - 3 * PXSCALE, _d, 6 * PXSCALE, PXSCALE) + this.ctx.fill() + + } + + this.clearRect = [m - 10 * PXSCALE, this.gaugePadding - 10 * PXSCALE, 20 * PXSCALE, height - 2 * this.gaugePadding + 20 * PXSCALE] + + } else { + + this.ctx.globalAlpha = 1 + this.ctx.fillStyle = this.cssVars.colorFill + + this.ctx.beginPath() + this.ctx.arc(m, d, 3 * PXSCALE, 0, 2 * Math.PI) + this.ctx.fill() + + // extra knob + this.ctx.beginPath() + this.ctx.arc(m, d2, 3 * PXSCALE, 0, 2 * Math.PI) + this.ctx.fill() + + + if (this.cssVars.alphaStroke) { + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.fillStyle = this.cssVars.colorFill + + this.ctx.beginPath() + this.ctx.arc(m, d, 10 * PXSCALE, 0, 2 * Math.PI) + this.ctx.fill() + + // extra knob + this.ctx.beginPath() + this.ctx.arc(m, d2, 10 * PXSCALE, 0, 2 * Math.PI) + this.ctx.fill() + } + + this.clearRect = [m - 11 * PXSCALE, this.gaugePadding - 11 * PXSCALE, 22 * PXSCALE, height - 2 * this.gaugePadding + 22 * PXSCALE] + + } + + if (this.getProp('pips')) { + this.ctx.globalAlpha = 1 + this.ctx.drawImage(this.pips, 0, 0); + if (!compact) this.clearRect = [this.clearRect, [m + 10 * PXSCALE, 0, 10 * PXSCALE + this.pipsTextSize, height]] + } - this.clearRect = [0, 0, width, height] } diff --git a/src/client/widgets/sliders/slider.js b/src/client/widgets/sliders/slider.js index 39181b18..27b6172b 100644 --- a/src/client/widgets/sliders/slider.js +++ b/src/client/widgets/sliders/slider.js @@ -12,6 +12,8 @@ class Slider extends Canvas { `}) + this.container.classList.add('design-' + this.getProp('design')) + this.value = undefined this.percent = 0 diff --git a/src/scss/index.scss b/src/scss/index.scss index a97afd52..f5c020bd 100644 --- a/src/scss/index.scss +++ b/src/scss/index.scss @@ -5,7 +5,6 @@ @import 'ui'; @import 'editor'; -@import 'sidepanel'; @import 'widgets'; input, diff --git a/src/scss/sidepanel.scss b/src/scss/sidepanel.scss deleted file mode 100644 index a11de6fb..00000000 --- a/src/scss/sidepanel.scss +++ /dev/null @@ -1,148 +0,0 @@ -// -// #sidepanel { -// position:absolute; -// z-index: 999999; -// width:var(--sidepanel-size); -// max-width: calc(100% - 45rem); -// min-width: 300rem; -// border-top: 2rem solid var(--color-bg); -// border-bottom: 2rem solid var(--color-bg); -// border-right: 2rem solid var(--color-bg); -// top:0; -// right:0; -// bottom:0; -// margin-right:calc(-1 * var(--sidepanel-size)); -// background:var(--color-bg); -// transition:transform .25s, opacity .25s; -// transform: translate3d(0,0,0); -// opacity: 0; -// box-shadow: 0 0 15rem 0 rgba(black, 0.3); -// display: flex; -// flex-direction: column; -// -// #sidepanel-wrapper { -// overflow-y: auto; -// overflow-x: visible; -// display: flex; -// flex-direction: column; -// flex:1; -// } -// -// &.sidepanel-open { -// transform: translate3d(calc(-1 * var(--sidepanel-size)),0,0); -// opacity: 1; -// } -// -// &.hide { -// z-index: -1; -// pointer-events: none; -// margin-right: 0; -// } - // - // .navigation { - // margin-bottom:2rem; - // margin-left: 0; - // li { - // cursor:default; - // } - // a { - // text-transform: none; - // color: var(--color-accent); - // justify-content: center; - // } - // } - - // #options { - // box-shadow: 0 0 0 1rem var(--color-light) inset; - // background: var(--color-fg); - // padding: 8rem; - // flex: 1 1 auto; - // flex-shrink:0; - // - // li { - // display: block; - // margin-bottom: 8rem; - // &:last-child { - // margin-bottom:0; - // } - // } - // } - -// } -// .actions { -// padding:0.5rem; -// background:var(--color-bg); -// display: flex; -// align-items: stretch; -// flex-wrap:wrap; -// .title { -// flex: 1 1 100%; -// background: var(--color-fg); -// box-shadow: 0 0 0 1rem var(--color-light) inset; -// padding: 13rem 10rem; -// position: relative; -// margin: 0.5rem; -// &.disabled { -// color:var(--color-text-fade); -// } -// &:before { -// content:""; -// position: absolute; -// top:0; -// left:0; -// right:0; -// bottom:0; -// box-shadow: 0 0 0 1rem; -// color:var(--color-bg); -// } -// -// } -// a { -// // flex: 4 1 32%; -// flex:1; -// min-width: 32%; -// padding:13rem 10rem; -// display: block; -// text-align: center; -// position: relative; -// color:var(--color-text); -// overflow: visible; -// margin: 0.5rem; -// &.narrow { -// width: auto; -// min-width: 40rem; -// flex:0; -// } -// -// -// &.on { -// z-index: 0; -// color: var(--color-custom); -// &:not(.toggle) { -// pointer-events: none; -// } -// &:after { -// content: ""; -// position: absolute; -// top:0; -// left: 0; -// right: 0; -// bottom: 0; -// opacity: 0.4; -// background: radial-gradient( ellipse at center, transparent, var(--color-bg)); -// } -// &:before { -// content:""; -// position: absolute; -// top:0; -// left: 0; -// right: 0; -// bottom: 0; -// opacity: 0.3; -// box-shadow: 0 0 0 1rem var(--color-custom) inset; -// border-radius: inherit; -// } -// } -// -// } -// } diff --git a/src/scss/ui/contextmenu.scss b/src/scss/ui/contextmenu.scss index bd35fcf7..f09c6ad9 100644 --- a/src/scss/ui/contextmenu.scss +++ b/src/scss/ui/contextmenu.scss @@ -42,7 +42,8 @@ $line-height: 30rem; width: 10rem; text-align: center; line-height: $line-height - 2; - font-size: 90%; + font-size: 9rem; + pointer-events: none; } &.focus { > .context-menu { @@ -95,6 +96,7 @@ $line-height: 30rem; flex: 1; text-transform: capitalize; opacity: 0.5; + pointer-events: none; } } .separator{ diff --git a/src/scss/ui/notifications.scss b/src/scss/ui/notifications.scss index ef0a26d6..b9393516 100644 --- a/src/scss/ui/notifications.scss +++ b/src/scss/ui/notifications.scss @@ -38,7 +38,7 @@ } .content { padding: 10rem; - white-space: normal; + white-space: pre-line; text-transform: none; line-height: normal; } diff --git a/src/scss/ui/workspaces.scss b/src/scss/ui/workspaces.scss index 35084fd3..895b145e 100644 --- a/src/scss/ui/workspaces.scss +++ b/src/scss/ui/workspaces.scss @@ -12,6 +12,11 @@ osc-workspace { flex-direction: row; overflow: hidden; + background-image: url(../assets/logo.png); + background-size: 80rem; + background-position: center; + background-repeat: no-repeat; + } osc-panel-container { diff --git a/src/scss/widgets.old.scss b/src/scss/widgets.old.scss index d3c00933..14177e44 100644 --- a/src/scss/widgets.old.scss +++ b/src/scss/widgets.old.scss @@ -28,7 +28,7 @@ z-index: 10; } - &.nolabel { + &.no-label { > .label { display:none; } @@ -41,7 +41,7 @@ border-bottom-left-radius:inherit; min-height: 0; } - &.nolabel > .label ~ div { + &.no-label > .label ~ div { border-radius: inherit; } diff --git a/src/scss/widgets.old/inputs.scss b/src/scss/widgets.old/inputs.scss index 38398ef9..8ac0666f 100644 --- a/src/scss/widgets.old/inputs.scss +++ b/src/scss/widgets.old/inputs.scss @@ -210,7 +210,7 @@ width: 100rem; height:60rem; padding:1rem; - &.nolabel { + &.no-label { --color-border:var(--color-bg); padding: 0; .file { diff --git a/src/scss/widgets.old/matrices.scss b/src/scss/widgets.old/matrices.scss index 71abc769..e5ff4cda 100644 --- a/src/scss/widgets.old/matrices.scss +++ b/src/scss/widgets.old/matrices.scss @@ -8,7 +8,7 @@ } height:200rem; width:200rem; - &.nolabel .matrix { + &.no-label .matrix { top:0; } diff --git a/src/scss/widgets.old/panel.scss b/src/scss/widgets.old/panel.scss index f06c7ea7..d65ac90b 100644 --- a/src/scss/widgets.old/panel.scss +++ b/src/scss/widgets.old/panel.scss @@ -81,7 +81,7 @@ } } - &.nolabel { + &.no-label { > .panel { top:-1rem; } diff --git a/src/scss/widgets.old/plots.scss b/src/scss/widgets.old/plots.scss index a0ec1fb1..b321498b 100644 --- a/src/scss/widgets.old/plots.scss +++ b/src/scss/widgets.old/plots.scss @@ -234,7 +234,7 @@ } } } -.editor-enabled .frame-container.nolabel iframe { +.editor-enabled .frame-container.no-label iframe { pointer-events: none; } diff --git a/src/scss/widgets.old/switch.scss b/src/scss/widgets.old/switch.scss index 87a37867..c74b08ec 100644 --- a/src/scss/widgets.old/switch.scss +++ b/src/scss/widgets.old/switch.scss @@ -4,7 +4,7 @@ height:100rem; padding:1rem; - &.nolabel { + &.no-label { --color-border:var(--color-bg); padding: 0; .switch, .switcher { @@ -147,7 +147,7 @@ width:100rem; height: 60rem; padding:1rem; - &.nolabel { + &.no-label { --color-border:var(--color-bg); padding: 0; .select { diff --git a/src/scss/widgets.scss b/src/scss/widgets.scss index 64d20799..c175969e 100644 --- a/src/scss/widgets.scss +++ b/src/scss/widgets.scss @@ -45,7 +45,7 @@ z-index: 10; } - &.nolabel { + &.no-label { > label { display:none; } diff --git a/src/scss/widgets/buttons.scss b/src/scss/widgets/buttons.scss index 9a27f544..d181d16b 100644 --- a/src/scss/widgets/buttons.scss +++ b/src/scss/widgets/buttons.scss @@ -66,12 +66,19 @@ } - &.horizontal inner { + &.layout-horizontal inner { flex-direction: row; } + &.layout-grid inner { + + display:grid; + + } + + value { position: relative; diff --git a/src/scss/widgets/containers.scss b/src/scss/widgets/containers.scss index 02847038..f48d9fd3 100644 --- a/src/scss/widgets/containers.scss +++ b/src/scss/widgets/containers.scss @@ -40,6 +40,9 @@ max-height: 100%; max-width: 100%; } + > .flex-expand { + flex: 1 + } } &.layout-vertical > inner { display: flex; @@ -55,7 +58,9 @@ max-height: 100%; max-width: 100%; } - + > .flex-expand { + flex: 1 + } } &.layout-grid > inner { display: grid; @@ -92,6 +97,14 @@ padding: 0; } } + + &.vertical-tabs { + + > inner { + flex-direction: row; + } + + } } } @@ -139,12 +152,15 @@ } } - &.contains-widgets.nolabel > inner { + &.contains-widgets.no-label > inner { border-top: 1rem solid var(--color-background); } &.contains-tabs > inner > .navigation { margin: 0 1rem; + &.vertical { + margin: 1rem 0; + } } @@ -154,7 +170,6 @@ @extend .widget-panel-base; - --widget-padding: 1rem; --alpha-fill-on: 0.75; width: 100%; @@ -209,6 +224,8 @@ text-overflow: ellipsis; padding: 0 8rem; overflow: hidden!important; + white-space: pre-wrap; + text-align: center; i { pointer-events: none; @@ -228,13 +245,6 @@ background: var(--color-fill); z-index: 101; } - &:last-child { - margin-right:0; - margin-left: auto; - i { - font-size: 14rem; - } - } &:first-child:before { margin-left: 1rem; } @@ -244,6 +254,43 @@ } } + + &.vertical { + flex-direction: column; + height: 100%; + padding-bottom: 0; + padding-right: 1rem; + + div { + height: 100%; + padding: 0 12rem; + line-height: normal; + // justify-content: flex-start; + // text-align: left; + + &.on:before { + content: ""; + position: absolute; + left: auto; + top: 0rem; + right: 0rem; + bottom: 0rem; + opacity: var(--alpha-fill-on); + width: 4rem; + height: auto; + background: var(--color-fill); + z-index: 101; + } + &:first-child:before { + margin-top: 1rem; + margin-left: 0; + } + &:last-child:before { + margin-bottom: 1rem; + margin-right: 0; + } + } + } } diff --git a/src/scss/widgets/sliders.scss b/src/scss/widgets/sliders.scss index f125d77f..6d1995c9 100644 --- a/src/scss/widgets/sliders.scss +++ b/src/scss/widgets/sliders.scss @@ -52,4 +52,10 @@ --widget-padding: 1rem; --alpha-stroke: 0.75; + &.design-classic { + --alpha-stroke: 0.5; + --alpha-fill-off: 0.25; + --alpha-fill-on: 1; + } + }