diff --git a/CHANGELOG.md b/CHANGELOG.md index f2caf49c..f85b0b95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.18.0 +- scripting + - add `updateCanvas()` function (forces a canvas widget to redraw) + - remote control - `/NOTIFY`: if multiple arguments are provided, interpret the first one as the icon's name for the client notification diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 8e7d2df0..99ae03eb 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -207,6 +207,13 @@ Forces a widget to check if one of its properties has changed and update itself ---- +#### `updateCanvas(id)` +- `id`: widget `id` as a string. Can be `"this"` to target the host widget. + +Forces a canvas widget redraw. + +---- + #### `httpGet(url, callback)` - `url`: url of the resource to fetch (local url only) diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index 7aad6bb2..b0508bf0 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -223,6 +223,19 @@ class ScriptVm extends Vm { } + this.sandbox.contentWindow.updateCanvas = (id)=>{ + + this.checkContext('updateCanvas') + + var widgets = this.resolveId(id) + for (var i = widgets.length - 1; i >= 0; i--) { + + if (widgets[i].batchDraw) widgets[i].draw() + + } + + } + this.sandbox.contentWindow.getIndex = (id = 'this')=>{ this.checkContext('getIndex') @@ -510,7 +523,7 @@ class ScriptVm extends Vm { for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar', - 'openUrl', 'getVar', 'setVar', 'runAs', 'Image']) { + 'openUrl', 'getVar', 'setVar', 'runAs', 'Image', 'updateCanvas']) { this.sanitize(this.sandbox.contentWindow[imports]) }