v1 on fire

This commit is contained in:
bordun 2020-02-24 19:14:07 +01:00
parent be693864ab
commit 2edccfbb79
27 changed files with 279 additions and 115 deletions

View file

@ -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)
}

View file

@ -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`<osc-inspector-field></osc-inspector-field>`
this.label = this.container.appendChild(html`<label>${this.name}</label>`)
@ -29,14 +31,14 @@ class UiInspectorField extends UiWidget {
if (this.widget.props.type == 'tab' || this.widget.props.type == 'root') {
this.container.appendChild(html`
<textarea class="no-keybinding" name="${this.name}" rows="1" disabled>${this.value}</textarea>
<textarea tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}" rows="1" disabled>${this.value}</textarea>
`)
return
}
this.createInput()
var select = html`<select class="no-keybinding" name="${this.name}"/>`
var select = html`<select tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}"/>`
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`<textarea class="no-keybinding" name="${this.name}" rows="${stringValue.split('\n').length}">${stringValue}</textarea>`
var input = html`<textarea tabIndex="${this.tabIndex}" class="no-keybinding" name="${this.name}" rows="${stringValue.split('\n').length}">${stringValue}</textarea>`
this.container.appendChild(input)
@ -83,7 +85,10 @@ class UiInspectorField extends UiWidget {
if (this.name.includes('color')) {
let picker = html`<input class="osc-inspector-color" type="color" name="${this.name}" value="${this.value}"/>`
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`<input class="osc-inspector-color" type="color" name="${this.name}" value="${val}"/>`
this.container.appendChild(picker)
@ -92,22 +97,11 @@ class UiInspectorField extends UiWidget {
if (this.default.type.includes('boolean')) {
let toggle = html`
<osc-inspector-checkbox class="${this.widget.getProp(this.name) ? 'on' : ''}">
<osc-inspector-checkbox name="${this.name}" class="${this.widget.getProp(this.name) ? 'on' : ''}">
${raw(icon('check'))}
</osc-inspector-checkbox>
`
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)
}

View file

@ -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`<div></div>`
var widget = widgets[0],
props = defaults[widget.props.type],
multi = widgets.length > 1
multi = widgets.length > 1,
tabIndex = 1000
// this.form.appendChild(html`
// <div class="separator">
@ -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

View file

@ -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`<div class="select"></div>`})
super({...options, html: html`
<inner>
<div class="text"></div>
<div class="icon"></div>
</inner>
`})
this.select = this.widget.appendChild(html`<select class="no-keybinding"></select>`)
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

View file

@ -47,11 +47,14 @@ class Menu extends Widget {
super({...options, html: html`
<inner>
<div class="text"></div>
<div class="icon"></div>
</inner>
`})
this.menu = html`<menu></menu>`
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`<div class="center"></div>`)
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)

View file

@ -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})
}

View file

@ -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

View file

@ -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',

View file

@ -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'},

View file

@ -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`
<inner>
<iframe class="frame" src="" sandbox="allow-scripts"></iframe>
<iframe class="frame" src="" sandbox="allow-scripts allow-same-origin"></iframe>
</inner>`
})

View file

@ -29,7 +29,6 @@ class Html extends StaticProperties(Widget, {bypass: true}) {
'&nbsp;&nbsp;b, i, strong, em, strike, code, hr, br, div,',
'&nbsp;&nbsp;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'], {})

View file

@ -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'

View file

@ -23,8 +23,6 @@ class Svg extends StaticProperties(Widget, {bypass: true}) {
'- will be wrapped in a `< svg />` element',
'- `<path>` 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'], {})

View file

@ -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',

View file

@ -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

View file

@ -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'], {})
}

View file

@ -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`',

View file

@ -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'], {})
}

View file

@ -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`<input class="no-keybinding"></input>`
@ -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

View file

@ -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]

View file

@ -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) {

View file

@ -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),