From cead37dadee1100a5c550f280c862297bea16621 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 18 Apr 2019 16:52:27 +0200 Subject: [PATCH] knob: compact mode --- CHANGELOG.md | 1 + src/client/app/widgets/sliders/fader.js | 11 +--------- src/client/app/widgets/sliders/knob.js | 27 +++++++++++++++++++++--- src/client/app/widgets/sliders/slider.js | 12 +++++++++++ src/scss/widgets/knob.scss | 18 ++++++++++++++++ 5 files changed, 56 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4df3afeb..a7631995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - bottom horizontal scrollbar not responding on small screens - widgets - `logScale` can be set to a number to use a logarithm base different from the default + - knob: `compact` mode is back ## 0.45.5 diff --git a/src/client/app/widgets/sliders/fader.js b/src/client/app/widgets/sliders/fader.js index 39cf37ee..f5c18a2c 100644 --- a/src/client/app/widgets/sliders/fader.js +++ b/src/client/app/widgets/sliders/fader.js @@ -20,7 +20,7 @@ module.exports = class Fader extends Slider { '- the meter\'s `id` will be the same as the widget\'s with `/meter` appended to it', '- the meter\'s `address` will be the same as the widget\'s with `/meter` appended to it' ]}, - compact: {type: 'boolean', value: false, help: 'Set to `true` to display a compact alternative for the widget. Disables default mouse/touch focusing on the value display.'}, + compact: {type: 'boolean', value: false, help: 'Set to `true` to display a compact alternative for the widget. If `input` is `true`, the input can be focused with a right-click (mouse only). Disables `pips` when enabled.'}, dashed: {type: 'boolean', value: false, help: 'Set to `true` to display a dashed gauge'}, snap: {type: 'boolean', value: false, help: 'By default, dragging the widget will modify it\'s value starting from its last value. Setting this to `true` will make it snap directly to the mouse/touch position'}, spring: {type: 'boolean', value: false, help: 'When set to `true`, the widget will go back to its `default` value when released'}, @@ -73,16 +73,7 @@ module.exports = class Fader extends Slider { } if (this.getProp('compact')) { - this.widget.classList.add('compact') this.margin = 0 - if (this.getProp('input')) { - this.widget.addEventListener('fast-right-click', (e)=>{ - if (e.detail.button == 2 && !EDITING) { - // Mouse only - this.input.focus() - } - }) - } } if (this.getProp('alignRight') && !this.getProp('horizontal')) { diff --git a/src/client/app/widgets/sliders/knob.js b/src/client/app/widgets/sliders/knob.js index a885431f..f9fc5c17 100644 --- a/src/client/app/widgets/sliders/knob.js +++ b/src/client/app/widgets/sliders/knob.js @@ -9,8 +9,9 @@ module.exports = class Knob extends Slider { _knob:'knob', - pips: {type: 'boolean', value: true, help: 'Set to `false` to hide the scale'}, + pips: {type: 'boolean', value: false, help: 'Set to `true` to show the scale\'s breakpoints'}, input: {type: 'boolean', value: true, help: 'Set to `false` to hide the built-in input'}, + compact: {type: 'boolean', value: false, help: 'Set to `true` to display a compact alternative for the widget. If `input` is `true`, the input can be focused with a right-click (mouse only). Disables `pips` when enabled.'}, dashed: {type: 'boolean', value: false, help: 'Set to `true` to display a dashed gauge'}, angle: {type: 'number', value: 270, help: 'Defines the angle\'s width of the knob, in degrees'}, snap: {type: 'boolean', value: false, help: 'By default, dragging the widget will modify it\'s value starting from its last value. Setting this to `true` will make it snap directly to the mouse/touch position'}, @@ -55,8 +56,6 @@ module.exports = class Knob extends Slider { this.widget.classList.add('knob') - this.widget.classList.add('compact') - this.lastOffsetX = 0 this.lastOffsetY = 0 this.minDimension = 0 @@ -177,6 +176,13 @@ module.exports = class Knob extends Slider { rad = PXSCALE / gaugeRadius / 2 + if (this.getProp('compact')) { + pips = false + gaugeWidth = this.minDimension / 4 + gaugeRadius = this.minDimension / 2 - gaugeWidth / 2 + } + + this.ctx.clearRect(0,0,this.width,this.height) this.ctx.globalAlpha = 1 @@ -211,6 +217,21 @@ module.exports = class Knob extends Slider { if (dashed) this.ctx.setLineDash([]) + if (this.getProp('compact')) { + this.ctx.globalAlpha = 1 + let r1 = gaugeRadius - gaugeWidth / 2 + 2 * PXSCALE, + r2 = gaugeRadius + gaugeWidth / 2 - 2 * PXSCALE, + 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.lineWidth = PXSCALE + this.ctx.strokeStyle = this.colors.knob + this.ctx.stroke() + return + } if (pips) { diff --git a/src/client/app/widgets/sliders/slider.js b/src/client/app/widgets/sliders/slider.js index 9794ca68..c11526bd 100644 --- a/src/client/app/widgets/sliders/slider.js +++ b/src/client/app/widgets/sliders/slider.js @@ -101,6 +101,18 @@ class Slider extends Canvas { } + if (this.getProp('compact')) { + this.widget.classList.add('compact') + if (this.getProp('input')) { + this.widget.addEventListener('fast-right-click', (e)=>{ + if (e.detail.button == 2 && !EDITING) { + // Mouse only + this.input.focus() + } + }) + } + } + this.setSteps() this.setValue(this.springValue) diff --git a/src/scss/widgets/knob.scss b/src/scss/widgets/knob.scss index 0f28ec69..67cc7923 100644 --- a/src/scss/widgets/knob.scss +++ b/src/scss/widgets/knob.scss @@ -30,6 +30,24 @@ border: 0!important; } + &.compact { + > .input { + pointer-events: none; + position: absolute; + border:0; + background:transparent; + overflow: hidden; + position: absolute; + top:50%; + left:50%; + z-index: 1; + width: 100rem; + height: 30rem; + margin-left:-50rem; + margin-top:-15rem; + } + } + .wrapper { overflow: hidden; flex: 1 1 100%;