pads: expose/clean --point-size css var, make pointSize property dynamic

This commit is contained in:
jean-emmanuel 2024-06-20 14:30:08 +02:00
parent da6c5d02c7
commit f93056d21e
6 changed files with 33 additions and 11 deletions

View file

@ -197,6 +197,7 @@ class Canvas extends Widget {
case 'alphaFillOff':
case 'alphaFillOn':
case 'colorBg':
case 'pointSize':
fastdom.measure(()=>{
this.cacheCanvasStyle()
fastdom.mutate(()=>{

View file

@ -64,7 +64,6 @@ module.exports = class MultiXy extends Pad {
this.npoints = Array.isArray(this.getProp('points')) ? this.getProp('points').length : this.getProp('points') || 0
this.labels = Array.isArray(this.getProp('points'))
this.pointSize = parseInt(this.getProp('pointSize'))
this.preventChildrenTouchState = true
this.pads = []
@ -82,7 +81,7 @@ module.exports = class MultiXy extends Pad {
logScaleX:this.getProp('logScaleX'),
logScaleY:this.getProp('logScaleY'),
axisLock:this.getProp('axisLock'),
pointSize: this.getProp('pointSize'),
pointSize: 'auto',
pips: this.getProp('pips') && i == this.npoints-1,
sensitivity: this.getProp('sensitivity'),
input:false
@ -249,9 +248,9 @@ module.exports = class MultiXy extends Pad {
updateHandlesPosition() {
for (var i=0;i<this.npoints;i++) {
this.padsCoords[i] = [clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE
,- clip(this.pads[i].faders.y.percent,[0,100]) / 100 * (this.height - (this.pointSize * 2 + 2) * PXSCALE) - (this.pointSize + 1) * PXSCALE]
var pointSize = this.pads[i].cssVars.pointSize
this.padsCoords[i] = [clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (pointSize * 2 + 2) * PXSCALE) + (pointSize + 1) * PXSCALE
,- clip(this.pads[i].faders.y.percent,[0,100]) / 100 * (this.height - (pointSize * 2 + 2) * PXSCALE) - (pointSize + 1) * PXSCALE]
}

View file

@ -11,8 +11,6 @@ class Pad extends Canvas {
</inner>
`})
this.canvas.style.setProperty('--pointSize', parseInt(this.getProp('pointSize')) + 'rem')
}
cacheCanvasStyle(style) {
@ -21,16 +19,35 @@ class Pad extends Canvas {
super.cacheCanvasStyle(style)
this.pointSize = parseFloat(style.getPropertyValue('--pointSize')) * PXSCALE
this.padPadding = (this.cssVars.padding + this.cssVars.lineWidth) + 2 * PXSCALE
}
onPropChanged(propName, options, oldPropValue) {
var ret = super.onPropChanged(...arguments)
switch (propName) {
case 'pointSize':
this.setCssVariables()
return
}
return ret
}
}
Pad.cssVariables = Pad.prototype.constructor.cssVariables.concat(
{js: 'pointSize', css: '--point-size', toCss: x=>parseFloat(x) + 'rem', toJs: x=>parseFloat(x) * PXSCALE},
)
Pad.dynamicProps = Pad.prototype.constructor.dynamicProps.filter(n => n !== 'decimals').concat([
'spring',
'axisLock'
'axisLock',
'pointSize'
])
module.exports = Pad

View file

@ -208,7 +208,7 @@ module.exports = class Xy extends Pad {
draw() {
var pointSize = this.pointSize,
var pointSize = this.cssVars.pointSize,
margin = this.padPadding,
x = this.faders.x.percentToCoord(this.faders.x.percent),
y = this.faders.y.percentToCoord(this.faders.y.percent),
@ -287,7 +287,7 @@ module.exports = class Xy extends Pad {
}
if (!pipsDrawn) this.clearRect = [x - this.pointSize - 2 * PXSCALE, y - this.pointSize - 2 * PXSCALE, (this.pointSize + PXSCALE) * 4, (this.pointSize + PXSCALE) * 4]
if (!pipsDrawn) this.clearRect = [x - pointSize - 2 * PXSCALE, y - pointSize - 2 * PXSCALE, (pointSize + PXSCALE) * 4, (pointSize + PXSCALE) * 4]
if (!ephemeral || this.active) {

View file

@ -30,6 +30,8 @@
.multixy-container {
--point-size: 20rem;
canvas:not(:first-child) {
position: absolute;
top: 0;