canvas: allow onResize to send and trigger widget synchronization and scripts

This commit is contained in:
jean-emmanuel 2026-10-06 09:10:36 +02:00
parent 000714d22b
commit aec5ba9d9c
4 changed files with 14 additions and 5 deletions

View file

@ -1,5 +1,10 @@
# Changelog
## 1.31.2
- widgets
- canvas: allow `onResize` to send and trigger widget synchronization and scripts
## 1.31.1
- bug fixes

View file

@ -2,7 +2,7 @@
The canvas widget allows creating custom widgets with user-defined drawings and touch reactions.
It has two special properties, `touch` and `draw`, that work like the `script` property : they are used to defined scripts that will be executed when specific events occurs.
It has dedicated scripting properties (`onTouch`, `onDraw` and `onResize`) that work like the `onValue` property : they are used to defined scripts that will be executed when specific events occurs.
This widget requires a good understanding of the javascript [Canvas API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API) and of the javascript programming language in general.
@ -30,7 +30,7 @@ If this property is enabled, the widget will be redrawn at a fixed rate even if
This script is executed when the widget is touched, when it is released, and during the movement of the pointer while the widget is touched.
This script has access to the same variables and functions as the `script` property (except the event-specific ones), plus the following:
This script has access to the same variables and functions as the `onValue` property (except the event-specific ones), plus the following:
- `value`: widget value
- `width`: canvas width in pixels
@ -59,7 +59,7 @@ This script has access to the same variables and functions as the `script` prope
This script is executed when the widget should be redrawn, which is when it's touched and when it receives a value.
This script has access to the same variables and functions as the `script` property (except the event-specific ones), plus the following:
This script has access to the same variables and functions as the `onValue` property (except the event-specific ones), plus the following:
- `value`: widget value
- `width`: canvas width in pixels
@ -67,11 +67,13 @@ 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
In this script, all osc messages emissions are prevented and changing the value of a widget won't trigger widget synchronisation / scripts / advanced syntaxes updates.
### `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:
This script has access to the same variables and functions as the `onValue` property (except the event-specific ones), plus the following:
- `value`: widget value
- `width`: canvas width in pixels

View file

@ -123,6 +123,8 @@ The following variables are available in this context:
This script is specific to the root widget, it's called before any other widget is created and can be used to create global variables / functions accessible in other scripts.
In this script, all osc messages emissions are prevented and changing the value of a widget won't trigger widget synchronisation / scripts / advanced syntaxes updates.
## Available variables
The following variables and functions are accessible in this context.

View file

@ -180,7 +180,7 @@ class CanvasWidget extends Canvas {
width: this.width,
height: this.height,
cssVars: this.cssVars
}, {sync: false, send: false})
}, {sync: true, send: true})
}