ui: fader style big clean + many small enhancements

This commit is contained in:
jean-emmanuel 2017-06-21 00:36:03 +02:00
parent c8bbd7cd58
commit 1790bf3d79
13 changed files with 274 additions and 231 deletions

View file

@ -146,7 +146,7 @@ var callbacks = module.exports = {
$('canvas').trigger('resize',[0,0,true])
},100)
window.GRIDWIDTH = getComputedStyle(document.documentElement).getPropertyValue("--grid-width")
window.PXSCALE_RESET()
// window.PXSCALE_RESET()
},
readOnly: function(){
window.READ_ONLY = true

View file

@ -80,6 +80,7 @@ module.exports = class Rgb extends _pads_base {
...faderDefaults,
id:'s',
compact:true,
pips:false,
horizontal:true,
snap:this.getProp('snap'),
range:{min:0,max:100},
@ -89,6 +90,7 @@ module.exports = class Rgb extends _pads_base {
...faderDefaults,
id:'b',
compact:true,
pips:false,
horizontal:false,
snap:this.getProp('snap'),
range:{min:0,max:100},

View file

@ -73,6 +73,7 @@ module.exports = class Xy extends _pads_base {
...faderDefaults,
id:0,
compact:true,
pips:false,
horizontal:true,
height:'100%',
width:'100%',
@ -87,6 +88,7 @@ module.exports = class Xy extends _pads_base {
...faderDefaults,
id:1,
compact:true,
pips:false,
horizontal:false,
height:'100%',
width:'100%',

View file

@ -19,7 +19,8 @@ module.exports = class Meter extends Fader {
width:'auto',
height:'auto',
horizontal:false,
pips:true,
pips:false,
dashed:false,
color:'auto',
css:'',

View file

@ -69,12 +69,12 @@ module.exports = class _sliders_base extends _canvas_base {
}.bind(this))
if (this.getProp('touchAddress') && this.getProp('touchAddress').length)
osctouchstate(this, this.canvas)
osctouchstate(this, this.wrapper)
this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
this.canvas.on('drag',this.dragHandleProxy.bind(this))
this.canvas.on('dragend',this.dragendHandleProxy.bind(this))
this.wrapper.on('mousewheel',this.mousewheelHandleProxy.bind(this))
this.wrapper.on('draginit',this.draginitHandleProxy.bind(this))
this.wrapper.on('drag',this.dragHandleProxy.bind(this))
this.wrapper.on('dragend',this.dragendHandleProxy.bind(this))
this.input.change(()=>{

View file

@ -23,6 +23,7 @@ module.exports = class Fader extends _sliders_base {
horizontal:false,
pips:true,
compact:false,
dashed:false,
color:'auto',
css:'',
@ -77,7 +78,27 @@ module.exports = class Fader extends _sliders_base {
this.widget.addClass('align-right')
}
if (this.getProp('pips') && !this.getProp('compact')) {
if (this.getProp('meter')) {
var parsewidgets = require('../../parser').widgets
var data = {
type:'meter',
id: this.getProp('id') + '/meter',
label:false,
horizontal:this.getProp('horizontal'),
range:this.getProp('range'),
logScale:this.getProp('logScale'),
address:this.getProp('meterAddress') || this.getProp('address') + '/meter',
preArgs:this.getProp('preArgs'),
color:this.getProp('color'),
pips:false,
dashed:true
}
var element = parsewidgets([data],this.wrapper, this.parent)
element[0].classList.add('not-editable')
this.widget[0].classList.add('has-meter')
}
if (this.getProp('pips')) {
this.widget.addClass('has-pips')
@ -104,25 +125,6 @@ module.exports = class Fader extends _sliders_base {
}
if (this.getProp('meter')) {
var parsewidgets = require('../../parser').widgets
var data = {
type:'meter',
id: this.getProp('id') + '/meter',
label:false,
horizontal:this.getProp('horizontal'),
range:this.getProp('range'),
logScale:this.getProp('logScale'),
address:this.getProp('meterAddress') || this.getProp('address') + '/meter',
preArgs:this.getProp('preArgs'),
color:this.getProp('color'),
pips:this.getProp('pips')
}
var element = parsewidgets([data],this.wrapper, this.parent)
element[0].classList.add('not-editable')
this.widget[0].classList.add('has-meter')
}
}
draginitHandle(e, data, traversing) {
@ -176,7 +178,8 @@ module.exports = class Fader extends _sliders_base {
}
}
if (this.getProp('horizontal')) {
if (this.getProp('horizontal')){
this.ctx.setTransform(1, 0, 0, 1, 0, 0)
this.ctx.rotate(-Math.PI/2)
this.ctx.translate(-this.height, 0)
}
@ -195,39 +198,21 @@ module.exports = class Fader extends _sliders_base {
o = Math.round(this.percentToCoord(this.valueToPercent(this.originValue))),
m = Math.round(this.getProp('horizontal') ? this.height / 2 : this.width / 2)
var dashed = this.getProp('dashed')
this.clear()
if (this.getProp('compact')) {
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o:height-o)
this.ctx.globalAlpha = 0.4//0.2 + 0.2 * Math.abs(d-o) / (d<o?o:height-o)
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.moveTo(m, o)
this.ctx.lineTo(m, d)
this.ctx.lineWidth = width + 2 * PXSCALE
if (dashed) this.ctx.setLineDash([PXSCALE, PXSCALE])
this.ctx.stroke()
if (this.getProp('pips') && this.rangeKeys.length > 2) {
this.ctx.globalAlpha = 1
var y,
min = Math.min(d,o),
max = Math.max(d,o)
this.ctx.beginPath()
for (var i = 1;i < this.rangeKeys.length - 1;i++) {
y = this.percentToCoord(this.rangeKeys[i])
this.ctx.rect(0, y - PXSCALE, 4.5 * PXSCALE, 2 * PXSCALE)
this.ctx.rect(width - 4.5 * PXSCALE, y - PXSCALE, 4.5 * PXSCALE, 2 * PXSCALE)
}
this.ctx.fillStyle = this.colors.pips
this.ctx.fill()
this.ctx.fillStyle = this.colors.light
this.ctx.fill()
this.ctx.lineWidth = 1 * PXSCALE
this.ctx.strokeStyle = this.colors.track
this.ctx.stroke()
}
if (dashed) this.ctx.setLineDash([])
this.ctx.globalAlpha = 1
this.ctx.beginPath()
@ -268,10 +253,11 @@ module.exports = class Fader extends _sliders_base {
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.moveTo(m, o)
this.ctx.lineTo(m, d)
if (dashed) this.ctx.setLineDash([PXSCALE, PXSCALE])
this.ctx.stroke()
if (dashed) this.ctx.setLineDash([])
this.ctx.globalAlpha = 1

View file

@ -20,6 +20,7 @@ module.exports = class Knob extends _sliders_base {
height:'auto',
color:'auto',
pips:true,
dashed:false,
angle:270,
css:'',
@ -149,7 +150,9 @@ module.exports = class Knob extends _sliders_base {
var o = this.percentToAngle(this.valueToPercent(this.originValue)),
d = this.percentToAngle(this.percent),
min = this.percentToAngle(0),
max = this.percentToAngle(100)
max = this.percentToAngle(100),
dashed = this.getProp('dashed')
this.ctx.clearRect(0,0,this.width,this.height)
@ -177,7 +180,10 @@ module.exports = class Knob extends _sliders_base {
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth - this.margin * PXSCALE, Math.min(o,d), Math.max(o,d))
if (dashed) this.ctx.setLineDash([1.5, 1.5])
this.ctx.stroke()
if (dashed) this.ctx.setLineDash([])
if (this.getProp('pips')) {
this.ctx.globalAlpha = 1

View file

@ -38,6 +38,11 @@
self.fontSize = parseFloat(getComputedStyle(canvas[0]).getPropertyValue("font-size"))
}
ctx.font = self.fontSize + 'px Droid Sans'
ctx.textBaseline = "middle"
ctx.fillStyle = self.color
ctx.textAlign = settings.align
self.val(self.value)
})
@ -51,15 +56,13 @@
if (!self.height || !self.width || (self.height==100 && self.width==100)) return
ctx.clearRect(0,0,self.width,self.height)
ctx.font = self.fontSize + 'px Droid Sans'
ctx.textBaseline = "middle"
ctx.fillStyle = self.color
if (self.center) {
ctx.textAlign = settings.align
if (settings.align == 'center') {
ctx.fillText(newVal,self.width/2,this.height/2)
} else {
} else if (settings.align == 'left') {
ctx.fillText(newVal,0,this.height/2)
} else if (settings.align == 'right') {
ctx.fillText(newVal,this.width,this.height/2)
}
}

View file

@ -49,7 +49,7 @@
}
}
.input {
width:100%;
width:auto;
height:24rem;
border:0;
background:transparent;
@ -58,6 +58,8 @@
padding:4rem 5rem;
position: relative;
display: var(--display-input);
// background: var(--color-track);
// border: 1rem solid var(--color-bg);
input {
position: absolute;
@ -74,6 +76,7 @@
color:var(--color-accent);
border-radius: 0;
-webkit-appearance:none;
// font-weight: bold;
}
canvas {
width:100%;

View file

@ -2,7 +2,7 @@
--color-pips: var(--color-text-fade);
--color-gauge: var(--color-custom);
--color-knob: var(--color-custom);
padding: 1rem;
width:100rem;
height:100%;
&.horizontal {
@ -27,59 +27,39 @@
width: 100%;
position: relative;
display: flex;
justify-content: center;
canvas {
width: 100%;
}
.meter-container {
> * {
pointer-events: none;
position: absolute;
top:14rem;
bottom:15rem;
left:50%;
height: auto;
width:3rem;
min-width: 3rem;
}
}
&:not(.has-pips):not(.compact):not(.horizontal) {
> canvas {
width: 20rem;
image-rendering:pixelated;
}
.meter-container {
margin-left: 14rem;
}
&.align-right {
.meter-container {
margin-left: -18rem;
}
}
}
&.has-pips {
> .wrapper > canvas {
padding-right: 28rem;
height: auto;
width:6rem!important;
min-width: auto;
flex-grow: 0;
--color-border:transparent;
border:0;
margin: 14rem 0 14rem 5rem;
}
.pips {
pointer-events: none;
position: absolute;
top:16rem;
bottom:16rem;
left:50%;
z-index: 0;
width: 4rem;
margin-left: 7rem;
background: linear-gradient(to bottom, transparent 0, transparent 2px, var(--color-pips) 2px, var(--color-pips) 3px, transparent 3px, transparent 5px);
background-size: 100% 5px;
background-repeat: repeat-y;
width: 3rem;
background-color: var(--color-raised);
position: relative;
margin: 16rem 12rem 16rem 5rem;
.pip {
height:1px;
background: var(--color-pips);
color:var(--color-fg);
position: absolute;
width:8rem;
width:5rem;
left:0;
&:before {
content:"";
@ -105,21 +85,18 @@
}
}
&.align-right {
> .wrapper > canvas {
padding-right: 0;
padding-left: 28rem;
}
.wrapper .meter-container {
left: auto;
right:50%;
margin-left: 0;
}
&.align-right {
.wrapper {
flex-direction: row-reverse;
.meter-container {
margin: 14rem 5rem 14rem 12rem;
}
.pips {
margin-left: 0;
margin-right: 7rem;
left:auto;
right:50%;
margin: 16rem 5rem 16rem 0;
background-position: top right;
.pip {
right:0;
left:auto;
@ -131,110 +108,171 @@
}
}
}
&.horizontal {
&:not(.compact).has-pips .wrapper canvas, &:not(.compact).has-meter .wrapper canvas {
padding-right:0;
padding-bottom: 20rem;
}
.wrapper .meter-container {
left:14rem;
right:15rem;
height: 3rem;
min-height: 3rem;
width: auto;
top:50%;
margin-top: 3rem;
canvas {
padding:0!important;
}
}
.pips {
top:50%;
left:16rem;
right:16rem;
font-size: 0;
height:4rem;
width:auto;
margin:0;
margin-top: 10rem;
background: linear-gradient(to right, transparent 0, transparent 2px, var(--color-pips) 2px, var(--color-pips) 3px, transparent 3px, transparent 5px);
background-size: 5px 100%;
background-repeat: repeat-x;
.pip {
width:1px;
height:6rem;
margin: 0;
&:before {
top:0;
bottom:0;
left:-4px;
right:-4px;
}
span {
top:15rem;
left:-15rem!important;
right:auto;
}
}
}
}
&.compact {
--color-pips: var(--color-raised);
border:1rem solid var(--color-light);
.wrapper > canvas {
border:1rem solid var(--color-bg);
}
.wrapper {
canvas {
background: var(--color-track);
}
}
.input {
overflow: hidden;
position: absolute;
top:50%;
transform: rotate(-90deg);
pointer-events: none;
width: 100rem;
margin-left: -50rem;
left:50%;
z-index: 3;
margin-top: -12rem;
}
.meter-container {
top: -1rem;
bottom: 0;
left: auto;
right:0;
border-right-width: 0;
border-bottom-width: 0;
}
&.align-right {
.meter-container {
right: auto;
left:0;
border-right-width: 1rem;
box-shadow: none;
}
}
&.horizontal {
.meter-container {
top: auto;
bottom: 0;
left: -1rem;
right:0;
height: 3rem;
min-height: 3rem;
flex-direction: column;
> canvas {
width: auto;
height: 20rem;
}
.input {
transform: none;
top:50%;
.meter-container {
width: auto!important;
height:6rem;
min-height: auto;
margin: 5rem 14rem 0 14rem;
}
.pips {
width:auto;
height: 3rem;
margin: 5rem 16rem 12rem 16rem;
.pip {
width:1px;
height:5rem;
margin: 0;
&:before {
top:0;
bottom:0;
left:-4px;
right:-4px;
}
span {
top:15rem;
left:-15rem!important;
right:auto;
}
}
}
}
}
&.compact {
.wrapper {
border: 1rem solid var(--color-bg);
> canvas {
flex:1;
background: var(--color-track);
order:1;
}
.meter-container {
order:3;
margin: 0;
border: 0;
box-shadow: none;
padding: 0;
.fader {
border: 0;
border-left: 1rem solid var(--color-bg);
.wrapper {
border: 0;
}
}
.pips {
display: none;
}
}
> .pips {
overflow: hidden;
margin: 0;
order:2;
background: var(--color-fg);
border:0;
border-left: 1rem solid var(--color-bg);
.pip {
span {
display: none;
}
}
}
}
&.align-right {
.wrapper {
.meter-container {
.fader {
border: 0;
border-right: 1rem solid var(--color-bg);
}
}
.pips {
border:0;
border-right: 1rem solid var(--color-bg);
}
}
}
--input-margin:0rem;
&.has-meter {
--input-margin:-3rem;
}
.input {
pointer-events: none;
position: absolute;
border:0;
background:transparent;
}
&.horizontal {
position:relative;
.wrapper {
.meter-container {
.fader {
border: 0;
border-top: 1rem solid var(--color-bg);
}
}
}
.input {
top:50%;
margin-top: calc(var(--input-margin) - 12rem );
}
.pips {
border:0;
border-top: 1rem solid var(--color-bg);
.pip:last-child {
left:auto!important;
right:0;
}
}
}
&:not(.horizontal) {
.input {
overflow: hidden;
position: absolute;
top:50%;
transform: rotate(-90deg);
width: 100rem;
margin-top: -12rem;
margin-left: calc(-1 * 50rem + var(--input-margin));
left:50%;
z-index: 3;
}
&.align-right {
.input {
margin-left: calc(-1 * 50rem - var(--input-margin));
}
}
.pips {
.pip:last-child {
top:0;
}
}
}
}
}

View file

@ -2,6 +2,7 @@
--color-pips: var(--color-text-fade);
--color-gauge: var(--color-custom);
--color-knob: var(--color-custom);
padding: 1rem;
width: 100rem;
height: 120rem;

View file

@ -18,12 +18,16 @@
display: flex;
text-align: center;
flex-shrink: 0;
.input {
flex:1;
}
}
> .wrapper {
position: relative;
height: 100%;
width: 100%;
background:var(--color-track);
border: 1rem solid var(--color-bg);
> canvas {
width:100%;
@ -31,7 +35,6 @@
position: absolute;
pointer-events: none;
z-index: 1;
border: 1rem solid var(--color-bg);
}
.fader {
pointer-events: none;
@ -47,7 +50,7 @@
background: transparent!important;
}
canvas {
.wrapper {
border:none;
}
.input {
@ -87,8 +90,7 @@
z-index: 1;
.fader {
position: relative;
border-radius: 3rem;
box-shadow: 0 0 0 1rem var(--color-light);
&:after {
content:"";
position: absolute;
@ -99,18 +101,10 @@
background:transparent linear-gradient(to left, #F00, #FF0080, #F0F, #8000FF, #00F, #0080FF, #0FF, #00FF80, #0F0, #80FF00, #FF0, #FF8000, #F00) repeat scroll 0% 0%;
z-index: -1;
opacity: 0.7;
border-radius: inherit;
}
--color-knob:white;
--color-gauge:transparent;
--color-track:transparent;
.wrapper {
border-radius: inherit;
}
canvas {
background: transparent;
border-radius: inherit;
}
}
.input {
display: none;
@ -156,10 +150,11 @@
width:calc(100% - 2 * var(--point-size) - 2rem);
height:calc(100% - 2 * var(--point-size) - 2rem);
.wrapper {
background: transparent;
border:0;
}
canvas {
border:none;
border:0;
background: transparent;
}
.row {
display: none;

View file

@ -53,11 +53,17 @@
--color-custom:var(--color-accent);
--color-gauge: var(--color-custom);
--color-knob: transparent;
// background: var(--color-faded);
width:100rem;
padding:1rem;
&.horizontal {
height: 130rem;
}
.fader {
border:1rem solid var(--color-bg);
}
canvas {
image-rendering:pixelated;
}
}
.text-container {