sliders: knob color property ok

This commit is contained in:
jean-emmanuel 2024-02-18 15:29:38 +01:00
parent ebd14015de
commit 476f07ec60
4 changed files with 19 additions and 5 deletions

View file

@ -192,6 +192,7 @@ class Canvas extends Widget {
case 'colorWidget':
case 'colorFill':
case 'colorStroke':
case 'colorKnob':
case 'alphaStroke':
case 'alphaFillOff':
case 'alphaFillOn':

View file

@ -1,7 +1,7 @@
var {clip} = require('../utils'),
Slider = require('./slider')
module.exports = class Knob extends Slider {
class Knob extends Slider {
static description() {
@ -18,6 +18,7 @@ module.exports = class Knob extends Slider {
'Design style',
'Note: "solid" design uses "colorStroke" for the central knob color.'
]},
colorKnob: {type: 'string', value: 'auto', help: 'Knob color'},
pips: {type: 'boolean', value: false, help: 'Set to `true` to show the scale\'s breakpoints'},
dashed: {type: 'boolean|array', value: false, help: 'Set to `true` to display a dashed gauge. Can be set as an `array` of two numbers : `[dash_size, gap_size]`'},
angle: {type: 'number', value: 270, help: 'Defines the angle\'s width of the knob, in degrees'},
@ -229,7 +230,7 @@ module.exports = class Knob extends Slider {
// knob
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.cssVars.colorFill
this.ctx.strokeStyle = this.cssVars.colorKnob
this.ctx.lineWidth = this.cssVars.lineWidth + .5 * PXSCALE
let r1 = minRadius + this.gaugePadding,
@ -246,7 +247,7 @@ module.exports = class Knob extends Slider {
// center
this.ctx.globalAlpha = this.cssVars.alphaStroke
this.ctx.fillStyle = this.cssVars.colorStroke
this.ctx.fillStyle = this.cssVars.colorKnob
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, maxRadius / 1.25, 0, 2 * Math.PI)
@ -318,7 +319,7 @@ module.exports = class Knob extends Slider {
// knob
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.cssVars.colorFill
this.ctx.strokeStyle = this.cssVars.colorKnob
this.ctx.lineWidth = this.cssVars.lineWidth
let r1 = minRadius * 1.5,
@ -371,3 +372,9 @@ module.exports = class Knob extends Slider {
}
}
Knob.cssVariables = Knob.prototype.constructor.cssVariables.concat(
{js: 'colorKnob', css: '--color-knob'}
)
module.exports = Knob

View file

@ -265,6 +265,9 @@ class Slider extends Canvas {
case 'spring':
if (this.getProp('spring') && !this.touched) this.setValue(this.getSpringValue(), {...options})
return
case 'colorKnob':
this.setCssVariables()
return
}
@ -284,6 +287,7 @@ Slider.dynamicProps = Slider.prototype.constructor.dynamicProps
'spring',
'sensitivity',
'default',
'colorKnob'
])
module.exports = Slider

View file

@ -2,6 +2,9 @@
.knob-container,
.encoder-container,
.range-container {
--color-knob: var(--color-fill);
canvas {
image-rendering: pixelated;
width: 100%;
@ -19,7 +22,6 @@
--widget-padding: 1rem;
--knob-size: 1rem;
--line-width: 1rem;
--color-knob: var(--color-fill);
canvas {
text-align: left;