meter: add gradient property (#201)
This commit is contained in:
parent
e44e4d0f72
commit
09aedf526b
4 changed files with 24 additions and 1 deletions
|
|
@ -10,6 +10,7 @@
|
|||
- editor: wrap/cut/delete multiple widget not working properly
|
||||
- widgets
|
||||
- text: set line-height relative to font size
|
||||
- meter: added `gradient` feature
|
||||
|
||||
## 0.26.1
|
||||
|
||||
|
|
|
|||
|
|
@ -229,6 +229,11 @@ Meter displays incoming numerical values (via osc) as a gauge level
|
|||
### `logScale`
|
||||
- see fader's [`logScale`](sliders/#fader)
|
||||
|
||||
### `gradient`
|
||||
- type: `array`
|
||||
- default: `[]`
|
||||
- usage: when set, the meter's gauge will be filled with a linear color gradient : each item must be a color string. Example: `["blue", "red"]`
|
||||
|
||||
|
||||
## Image
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ module.exports = class Meter extends Fader {
|
|||
horizontal:false,
|
||||
pips:false,
|
||||
dashed:false,
|
||||
gradient:[],
|
||||
|
||||
_value: 'value',
|
||||
default: '',
|
||||
|
|
|
|||
|
|
@ -191,6 +191,21 @@ module.exports = class Fader extends Slider {
|
|||
if (ratio != 1) this.ctx.scale(ratio, ratio)
|
||||
}
|
||||
|
||||
if (this.getProp('gradient')) {
|
||||
var colors = this.getProp('gradient')
|
||||
if (Array.isArray(colors) && colors.length > 1) {
|
||||
try {
|
||||
var grad = this.ctx.createLinearGradient(0, this.getProp('horizontal') ? 0 : this.height, 0, this.getProp('horizontal') ? this.width : 0)
|
||||
for (var i in colors) {
|
||||
grad.addColorStop(i / (colors.length - 1), colors[i])
|
||||
}
|
||||
this.colors.gradient = grad
|
||||
} catch(err) {
|
||||
this.errors.gradient = err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -211,7 +226,8 @@ module.exports = class Fader extends Slider {
|
|||
if (this.getProp('compact')) {
|
||||
|
||||
this.ctx.globalAlpha = (dashed ? .3 : .2) + 0.2 * Math.abs(d-o) / (d<o?o:height-o)
|
||||
this.ctx.strokeStyle = this.colors.gauge
|
||||
|
||||
this.ctx.strokeStyle = this.colors.gradient || this.colors.gauge
|
||||
this.ctx.beginPath()
|
||||
this.ctx.moveTo(m, o)
|
||||
this.ctx.lineTo(m, d)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue