widgets: expose stroke width (wip)

This commit is contained in:
bordun 2020-09-06 15:41:56 +02:00
parent 7fb857e670
commit 3041c4e9e3
15 changed files with 67 additions and 50 deletions

View file

@ -80,6 +80,7 @@ class Widget extends EventEmitter {
alphaFillOff: {type: 'number', value: 'auto', help: 'Fill color opacity (off).'},
alphaFillOn: {type: 'number', value: 'auto', help: 'Fill color opacity (on).'},
strokeWidth: {type: 'number', value: 'auto', help: 'Stroke width.'},
padding: {type: 'number', value: 'auto', help: 'Inner spacing.'},
@ -1038,6 +1039,7 @@ Widget.cssVariables = [
{js: 'colorStroke', css: '--color-stroke'},
{js: 'colorText', css: '--color-text'},
{js: 'padding', css: '--widget-padding', toCss: x=>parseFloat(x) + 'rem', toJs: x=>parseFloat(x) * PXSCALE},
{js: 'strokeWidth', css: '--stroke-width', toCss: x=>parseFloat(x) + 'rem', toJs: x=>parseFloat(x) * PXSCALE},
{js: 'alphaFillOn', css: '--alpha-fill-on', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)},
{js: 'alphaFillOff', css: '--alpha-fill-off', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)},
{js: 'alphaStroke', css: '--alpha-stroke', toCss: x=>parseFloat(x), toJs: x=>parseFloat(x)},

View file

@ -88,7 +88,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, inte
this.ctx.fillStyle = this.cssVars.colorText
this.ctx.globalAlpha = this.cssVars.alphaPips
var margin = this.cssVars.padding
var margin = this.cssVars.padding + this.cssVars.strokeWidth
if (margin < this.fontSize * 1.5) return
@ -114,7 +114,7 @@ module.exports = class Plot extends StaticProperties(Canvas, {bypass: true, inte
draw_line() {
var points = [],
padding = this.cssVars.padding + PXSCALE,
padding = this.cssVars.padding + this.cssVars.strokeWidth,
decimals = this.getProp('smooth') ? 1 : 0,
length = this.value.length,
x, y, i, previousValue, nx, ny

View file

@ -22,7 +22,7 @@ class Pad extends Canvas {
super.cacheCanvasStyle(style)
this.pointSize = parseFloat(style.getPropertyValue('--pointSize')) * PXSCALE
this.padPadding = (this.cssVars.padding + PXSCALE)
this.padPadding = (this.cssVars.padding + this.cssVars.strokeWidth)
}

View file

@ -213,7 +213,7 @@ module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range
min = this.percentToAngle(0),
max = this.percentToAngle(100),
minRadius = this.minDimension / 6,
maxRadius = this.minDimension / 2 - PXSCALE,
maxRadius = this.minDimension / 2 - this.cssVars.strokeWidth,
gaugeWidth = maxRadius - minRadius,
gaugeRadius = maxRadius - gaugeWidth / 2
@ -245,20 +245,23 @@ module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range
}
// stroke
if (this.cssVars.strokeWidth) {
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.lineWidth = PXSCALE
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.lineWidth = this.cssVars.strokeWidth
if (this.minDimension > 40) {
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI)
this.ctx.stroke()
}
if (this.minDimension > 40) {
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI)
this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 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()
}

View file

@ -91,7 +91,7 @@ class Fader extends Slider {
super.dragHandle(...arguments)
var padding = this.gaugePadding
if (this.getProp('design') === 'compact') padding += this.cssVars.knobSize * PXSCALE / 2
if (this.getProp('design') === 'compact') padding += this.cssVars.knobSize / 2
this.percent = this.getProp('horizontal')?
this.percent + ( e.movementX / (this.width - padding * 2)) * 100 / e.inertia * this.getProp('sensitivity'):
@ -235,18 +235,21 @@ class Fader extends Slider {
if (compact) {
// stroke
if (this.cssVars.strokeWidth) {
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.strokeStyle = this.cssVars.colorStroke
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.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 * this.cssVars.strokeWidth
this.ctx.stroke()
}
// flat knob

View file

@ -176,8 +176,8 @@ module.exports = class Knob extends Slider {
max = this.percentToAngle(100),
dashed = this.getProp('dashed'),
pips = this.getProp('pips'),
minRadius = this.minDimension / 6 - (pips ? this.fontSize * 0.75 : PXSCALE),
maxRadius = this.minDimension / 2 - (pips ? this.fontSize * 2 : PXSCALE)
minRadius = this.minDimension / 6 - (pips ? this.fontSize * 0.75 : 0) - this.cssVars.strokeWidth / 2,
maxRadius = this.minDimension / 2 - (pips ? this.fontSize * 2 : 0) - this.cssVars.strokeWidth / 2
if (dashed) dashed = Array.isArray(dashed) ? dashed.map(x=>parseFloat(x)) : [1.5, 1.5]
@ -218,14 +218,15 @@ module.exports = class Knob extends Slider {
// stroke
if (this.cssVars.strokeWidth) {
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.strokeStyle = this.cssVars.colorStroke
this.ctx.lineWidth = this.cssVars.strokeWidth
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, maxRadius, 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

View file

@ -275,7 +275,7 @@ class Range extends Fader {
this.ctx.lineTo(width, height)
this.ctx.lineTo(0, height)
this.ctx.closePath()
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.lineWidth = 2 * this.cssVars.strokeWidth
this.ctx.stroke()

View file

@ -144,7 +144,7 @@ class Slider extends Canvas {
super.cacheCanvasStyle(style)
this.gaugePadding = this.cssVars.padding + PXSCALE
this.gaugePadding = this.cssVars.padding + this.cssVars.strokeWidth
}