widgets: knobs compact mode, default widgets input's height reduced
This commit is contained in:
parent
4def266315
commit
2407e37922
8 changed files with 177 additions and 53 deletions
|
|
@ -20,6 +20,8 @@ var _sliders_base = module.exports = function(){
|
|||
this.value = undefined
|
||||
this.percent = 0
|
||||
|
||||
this.unit = this.widgetData.unit ? ' ' + this.widgetData.unit : ''
|
||||
|
||||
|
||||
this.rangeKeys = []
|
||||
this.rangeVals = []
|
||||
|
|
@ -170,5 +172,5 @@ _sliders_base.prototype.sendValue = function(value) {
|
|||
}
|
||||
|
||||
_sliders_base.prototype.showValue = function() {
|
||||
this.input.val(this.value + ' ' + this.widgetData.unit)
|
||||
this.input.val(this.value + this.unit)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,13 @@ Knob = function(widgetData) {
|
|||
|
||||
this.widget.addClass('knob')
|
||||
|
||||
this.margin = 5
|
||||
|
||||
if (widgetData.compact) {
|
||||
this.widget.addClass('compact')
|
||||
this.margin = 0
|
||||
}
|
||||
|
||||
this.lastOffsetX = 0
|
||||
this.lastOffsetY = 0
|
||||
this.minDimension = 0
|
||||
|
|
@ -121,6 +128,10 @@ Knob.prototype.resizeHandle = function() {
|
|||
_sliders_base.prototype.resizeHandle.call(this)
|
||||
this.minDimension = Math.min(this.width, this.height)
|
||||
this.canvas[0].style.top = (this.minDimension / 2 - 15) * this.lostHeightFactor + 'px'
|
||||
if (this.widgetData.compact) {
|
||||
this.input[0].style.marginTop = (this.minDimension / 2 - 15) * this.lostHeightFactor + 'px'
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -133,37 +144,81 @@ Knob.prototype.draw = function(){
|
|||
|
||||
this.ctx.clearRect(0,0,this.width,this.height)
|
||||
|
||||
this.ctx.lineWidth = 2 * PXSCALE
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.track
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - 15 * PXSCALE, min, max)
|
||||
this.ctx.stroke()
|
||||
if (this.widgetData.compact) {
|
||||
|
||||
this.ctx.lineWidth = 10 * PXSCALE
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.track
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (10 + this.margin) * PXSCALE, min, max)
|
||||
this.ctx.stroke()
|
||||
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.5
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.gauge
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (10 + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
|
||||
this.ctx.stroke()
|
||||
this.ctx.restore()
|
||||
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.custom
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - 15 * PXSCALE, Math.min(o,d), Math.max(o,d))
|
||||
this.ctx.stroke()
|
||||
this.ctx.save()
|
||||
|
||||
this.ctx.translate(this.width / 2, this.height / 2)
|
||||
this.ctx.rotate(d)
|
||||
this.ctx.translate(-this.width / 2, -this.height / 2)
|
||||
|
||||
this.ctx.beginPath()
|
||||
|
||||
this.ctx.strokeStyle = this.colors.knob
|
||||
this.ctx.lineWidth = 1 * PXSCALE
|
||||
this.ctx.moveTo(this.width / 2 + this.minDimension / 2 - (10 + this.margin - 5) * PXSCALE, this.height / 2)
|
||||
this.ctx.lineTo(this.width / 2 + this.minDimension / 2 - (10 + this.margin + 5) * PXSCALE, this.height / 2)
|
||||
this.ctx.stroke()
|
||||
|
||||
this.ctx.restore()
|
||||
|
||||
|
||||
this.ctx.save()
|
||||
} else {
|
||||
|
||||
this.ctx.translate(this.width / 2, this.height / 2)
|
||||
this.ctx.rotate(d)
|
||||
this.ctx.translate(-this.width / 2, -this.height / 2)
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.raised
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (30 + this.margin), 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.lineWidth = 2 * PXSCALE
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.track
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (10 + this.margin) * PXSCALE, min, max)
|
||||
this.ctx.stroke()
|
||||
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.gauge
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (10 + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
|
||||
this.ctx.stroke()
|
||||
|
||||
this.ctx.save()
|
||||
|
||||
this.ctx.translate(this.width / 2, this.height / 2)
|
||||
this.ctx.rotate(d)
|
||||
this.ctx.translate(-this.width / 2, -this.height / 2)
|
||||
|
||||
this.ctx.beginPath()
|
||||
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.arc(this.width / 2 + this.minDimension / 2 - (10 + this.margin) * PXSCALE, this.height / 2, 4 * PXSCALE, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.arc(this.width / 2 + this.minDimension / 2 - (10 + this.margin) * PXSCALE, this.height / 2, 10 * PXSCALE, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.restore()
|
||||
}
|
||||
|
||||
this.ctx.fillStyle = this.colors.gauge
|
||||
this.ctx.arc(this.width / 2 + this.minDimension / 2 - 15 * PXSCALE, this.height / 2, 4 * PXSCALE, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.arc(this.width / 2 + this.minDimension / 2 - 15 * PXSCALE, this.height / 2, 10 * PXSCALE, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.restore()
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue