canvas: add onResize script property
This commit is contained in:
parent
c2bc99b2b3
commit
c84067c456
4 changed files with 44 additions and 2 deletions
|
|
@ -6,7 +6,10 @@
|
|||
- custom module: submodules not loading their own submodules with relative paths properly
|
||||
- custom module: issue with circular submodule requires
|
||||
- server: harmless error message when importing css files from the main theme file
|
||||
- server: allow using folder names "client" and "assets" for user files (eg for images used in a session)
|
||||
- server: allow using folder names "client" and "assets" for user files (eg for images used in a session)
|
||||
|
||||
- widgets
|
||||
- canvas: add `onResize` script property
|
||||
|
||||
## 1.16.2
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,17 @@ This script has access to the same variables and functions as the `script` prope
|
|||
- `ctx`: [canvas rendering context](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D) of the widget
|
||||
- `cssVars`: object containing the computed value of some of the widget's style properties such as `colorWidget`, `alphaFill`, `padding`, etc
|
||||
|
||||
### `onResize`
|
||||
|
||||
This script is executed when the widget has resized, before it is redrawn.
|
||||
|
||||
This script has access to the same variables and functions as the `script` property (except the event-specific ones), plus the following:
|
||||
|
||||
- `value`: widget value
|
||||
- `width`: canvas width in pixels
|
||||
- `height`: canvas height in pixels
|
||||
- `cssVars`: object containing the computed value of some of the widget's style properties such as `colorWidget`, `alphaFill`, `padding`, etc
|
||||
|
||||
## Example: XY pad
|
||||
|
||||
Let's create a simple xy pad, with a value made of two numbers between 0 and 1. We set `valueLength` to `2` to make sure the widget only accepts incoming messages with two values (x and y).
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class CanvasWidget extends Canvas {
|
|||
onValue: {type: 'script', value: '', editor: 'javascript', help: ['Script executed whenever the widget\'s value updates. See <a href="https://openstagecontrol.ammd.net/docs/widgets/scripting/">documentation</a>.']},
|
||||
onTouch: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the widget is touched and released, and when the pointer moves when the widget is touched. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]},
|
||||
onDraw: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the widget is redrawn. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.']},
|
||||
onResize: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the widget is resized. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.']},
|
||||
}
|
||||
return defaults
|
||||
|
||||
|
|
@ -49,6 +50,20 @@ class CanvasWidget extends Canvas {
|
|||
this.valueLength = Math.max(1, parseInt(this.getProp('valueLength')) || 1)
|
||||
this.value = this.valueLength > 1 ? Array(this.valueLength).fill(0) : 0
|
||||
|
||||
if (this.getProp('onResize')) {
|
||||
this.scripts.onResize = new Script({
|
||||
widget: this,
|
||||
property: 'onResize',
|
||||
code: this.getProp('onResize'),
|
||||
context: {
|
||||
value: 0,
|
||||
width: 100,
|
||||
height: 100,
|
||||
cssVars: {}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (this.getProp('onDraw')) {
|
||||
this.scripts.onDraw = new Script({
|
||||
widget: this,
|
||||
|
|
@ -161,6 +176,19 @@ class CanvasWidget extends Canvas {
|
|||
|
||||
}
|
||||
|
||||
extraResizeHandle(event) {
|
||||
|
||||
if (!this.getProp('onResize')) return
|
||||
|
||||
this.scripts.onDraw.run({
|
||||
value: this.value,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
cssVars: this.cssVars
|
||||
}, {sync: false, send: false})
|
||||
|
||||
}
|
||||
|
||||
onRemove() {
|
||||
|
||||
clearInterval(this.drawInterval)
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ module.exports = class Knob extends Slider {
|
|||
|
||||
}
|
||||
|
||||
extraResizeHandle() {
|
||||
extraResizeHandle(event) {
|
||||
|
||||
super.extraResizeHandle(event)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue