From b064b8f3a8510126fc31ed76afd606ecfebace1e Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 13 Dec 2025 11:30:10 +0100 Subject: [PATCH] button: add onTouch --- CHANGELOG.md | 1 + src/client/widgets/basics/button.mjs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a1e417..7b3b3962 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - add new `scrollbar` widget that connects to a scrolling container widget and acts as it scrollbar - input: add `noCanvas` option to avoid blurry text under some circumstances - xy: add `clipX` and `clipY` proprties (allows multixy to set per-pads anges limits) + - button: add `onTouch` script - editor - selecting a widget automatically shows it in the widget tree if it's not minimized diff --git a/src/client/widgets/basics/button.mjs b/src/client/widgets/basics/button.mjs index 22890c90..ae048a66 100644 --- a/src/client/widgets/basics/button.mjs +++ b/src/client/widgets/basics/button.mjs @@ -51,6 +51,9 @@ class Button extends Widget { 'From a script property, feedback messages can be simulated with:', '`set("widget_id", value, {external: true})`' ]}, + }, + scripting: { + onTouch: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the panel is touched and released, and when the pointer moves when the widget is touched. See documentation.',]}, } }) @@ -84,6 +87,10 @@ class Button extends Widget { }, {element: this.widget}) } + if (this.getProp('onTouch')) { + this.on('draginit',(e)=>this.onTouch(e, 'start'), {element: this.container}) + } + var mode = this.getProp('mode'), tap = mode === 'momentary' || mode === 'tap', push = mode === 'push' || tap @@ -219,8 +226,24 @@ class Button extends Widget { } + if (this.getProp('onTouch')) { + this.on('dragend',(e)=>this.onTouch(e, 'stop'), {element: this.container}) + } + } + onTouch(e, name) { + + var event = {...e} + + event.type = name + + this.scripts.onTouch.run({ + value: this.value, + event: event + }, {sync: true, send: true}) + + } get value() {