fastdom: canvas resize fix
This commit is contained in:
parent
87c4b9777b
commit
6b50e40aef
2 changed files with 60 additions and 53 deletions
|
|
@ -58,7 +58,9 @@ class Canvas extends Widget {
|
|||
|
||||
resizeHandleProxy() {
|
||||
|
||||
this.resizeHandle(...arguments)
|
||||
fastdom.measure(()=>{
|
||||
this.resizeHandle(...arguments)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -75,33 +77,32 @@ class Canvas extends Widget {
|
|||
|
||||
this.clearRect = []
|
||||
|
||||
if (ratio != 1) {
|
||||
this.ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||
this.ctx.scale(ratio, ratio)
|
||||
}
|
||||
this.cacheCanvasStyle(style)
|
||||
|
||||
fastdom.measure(()=>{
|
||||
this.cacheCanvasStyle(style)
|
||||
fastdom.mutate(()=>{
|
||||
fastdom.mutate(()=>{
|
||||
|
||||
this.canvas.setAttribute('width', width * ratio)
|
||||
this.canvas.setAttribute('height', height * ratio)
|
||||
this.container.style.setProperty('--widget-height', this.height + 'rem')
|
||||
this.container.style.setProperty('--widget-width', this.width + 'rem')
|
||||
this.canvas.setAttribute('width', width * ratio)
|
||||
this.canvas.setAttribute('height', height * ratio)
|
||||
this.container.style.setProperty('--widget-height', this.height + 'rem')
|
||||
this.container.style.setProperty('--widget-width', this.width + 'rem')
|
||||
|
||||
this.ctx.font = this.fontWeight + ' ' + this.fontSize + 'px ' + this.fontFamily
|
||||
this.ctx.textBaseline = 'middle'
|
||||
this.ctx.textAlign = this.textAlign
|
||||
this.ctx.font = this.fontWeight + ' ' + this.fontSize + 'px ' + this.fontFamily
|
||||
this.ctx.textBaseline = 'middle'
|
||||
this.ctx.textAlign = this.textAlign
|
||||
|
||||
if (!this.hasSize) {
|
||||
this.hasSize = true
|
||||
this.setVisibility()
|
||||
this.batchDraw()
|
||||
} else {
|
||||
this.draw()
|
||||
}
|
||||
if (ratio != 1) {
|
||||
this.ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||
this.ctx.scale(ratio, ratio)
|
||||
}
|
||||
|
||||
if (!this.hasSize) {
|
||||
this.hasSize = true
|
||||
this.setVisibility()
|
||||
this.batchDraw()
|
||||
} else {
|
||||
this.draw()
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
var {clip} = require('../utils'),
|
||||
Slider = require('./slider')
|
||||
Slider = require('./slider'),
|
||||
fastdom = require('fastdom')
|
||||
|
||||
class Fader extends Slider {
|
||||
|
||||
|
|
@ -118,50 +119,55 @@ class Fader extends Slider {
|
|||
|
||||
super.resizeHandle(event)
|
||||
|
||||
if (this.getProp('horizontal')){
|
||||
this.ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||
this.ctx.rotate(-Math.PI/2)
|
||||
this.ctx.translate(-this.height * ratio, 0)
|
||||
fastdom.mutate(()=>{
|
||||
|
||||
if (ratio != 1) this.ctx.scale(ratio, ratio)
|
||||
}
|
||||
if (this.getProp('horizontal')){
|
||||
this.ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||
this.ctx.rotate(-Math.PI/2)
|
||||
this.ctx.translate(-this.height * ratio, 0)
|
||||
|
||||
if (this.getProp('gradient')) {
|
||||
if (ratio != 1) this.ctx.scale(ratio, ratio)
|
||||
}
|
||||
|
||||
var colors = this.getProp('gradient')
|
||||
if (this.getProp('gradient')) {
|
||||
|
||||
if (
|
||||
(Array.isArray(colors) && colors.length > 1) ||
|
||||
(typeof colors === 'object' && Object.keys(colors).length > 1)
|
||||
) {
|
||||
var colors = this.getProp('gradient')
|
||||
|
||||
var grad = this.ctx.createLinearGradient(0, this.getProp('horizontal') ? 0 : this.height, 0, this.getProp('horizontal') ? this.width : 0)
|
||||
if (
|
||||
(Array.isArray(colors) && colors.length > 1) ||
|
||||
(typeof colors === 'object' && Object.keys(colors).length > 1)
|
||||
) {
|
||||
|
||||
try {
|
||||
if (Array.isArray(colors)) {
|
||||
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.gaugeGradient = grad
|
||||
try {
|
||||
if (Array.isArray(colors)) {
|
||||
|
||||
} else {
|
||||
|
||||
for (var k in colors) {
|
||||
if (!isNaN(k)) {
|
||||
grad.addColorStop(clip(k, [0, 1]), colors[k])
|
||||
for (var i in colors) {
|
||||
grad.addColorStop(i / (colors.length - 1), colors[i])
|
||||
}
|
||||
}
|
||||
this.gaugeGradient = grad
|
||||
this.gaugeGradient = grad
|
||||
|
||||
} else {
|
||||
|
||||
for (var k in colors) {
|
||||
if (!isNaN(k)) {
|
||||
grad.addColorStop(clip(k, [0, 1]), colors[k])
|
||||
}
|
||||
}
|
||||
this.gaugeGradient = grad
|
||||
|
||||
}
|
||||
} catch(err) {
|
||||
this.errorProp('gradient', '', err)
|
||||
}
|
||||
} catch(err) {
|
||||
this.errors.gradient = err
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue