expose the computed dimensions of canvas-based widgets in css (as --widget-width and --widget-height) and script (as locals.width and locals.height)
This commit is contained in:
parent
ce353d1b59
commit
9e16fff2fa
2 changed files with 25 additions and 1 deletions
|
|
@ -1,10 +1,28 @@
|
|||
var Widget = require('./widget'),
|
||||
resize = require('../../events/resize'),
|
||||
canvasQueue = require('./queue')
|
||||
canvasQueue = require('./queue'),
|
||||
html = require('nanohtml')
|
||||
|
||||
|
||||
class Canvas extends Widget {
|
||||
|
||||
static defaults() {
|
||||
|
||||
var defaults = super.defaults(Canvas)
|
||||
defaults.style.css.help.push(
|
||||
'Canvas-based widget have their computed width and height available as css variables (read-only):',
|
||||
'- `--widget-width`',
|
||||
'- `--widget-height`',
|
||||
)
|
||||
defaults.scripting.script.help.push(
|
||||
'Canvas-based widget have their computed width and height available as local variables:',
|
||||
'- `locals.width`',
|
||||
'- `locals.height`',
|
||||
)
|
||||
return defaults
|
||||
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
|
||||
super(options)
|
||||
|
|
@ -54,6 +72,11 @@ class Canvas extends Widget {
|
|||
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.parsersLocalScope.height = this.height
|
||||
this.parsersLocalScope.width = this.width
|
||||
|
||||
this.clearRect = []
|
||||
|
||||
if (ratio != 1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue