From f31cc2091ce28fcee376a2815ad2afd9067102c2 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Mon, 10 Mar 2025 19:34:26 +0100 Subject: [PATCH] button: `locals.touchCoords` not updated upon release and incorrect when `doubleTap` is set --- src/client/widgets/basics/button.js | 31 ++++++++++++++++++------- src/client/widgets/mixins/double_tap.js | 4 +++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/client/widgets/basics/button.js b/src/client/widgets/basics/button.js index 8fd99237..6f116cae 100644 --- a/src/client/widgets/basics/button.js +++ b/src/client/widgets/basics/button.js @@ -94,7 +94,12 @@ class Button extends Widget { doubleTap(this, (e)=>{ this.touchActive = true - this.setValue(this.getProp('on'), {sync: true, send: true, y: e.offsetY, x: e.offsetX, local:true}) + + if (this.exposeTouchCoords) { + this.parsersLocalScope.touchCoords = [e.offsetX / this.buttonSize[0], 1 - e.offsetY / this.buttonSize[1]] + } + + this.setValue(this.getProp('on'), {sync: true, send: true, local:true}) if (tap) this.container.classList.add('active') @@ -107,7 +112,12 @@ class Button extends Widget { if (this.touchActive) return this.touchActive = true - this.setValue(this.getProp('on'), {sync: true, send: true, y: e.offsetY, x: e.offsetX, local:true}) + + if (this.exposeTouchCoords) { + this.parsersLocalScope.touchCoords = [e.offsetX / this.buttonSize[0], 1 - e.offsetY / this.buttonSize[1]] + } + + this.setValue(this.getProp('on'), {sync: true, send: true, local:true}) if (tap) this.container.classList.add('active') @@ -116,6 +126,17 @@ class Button extends Widget { } + if (this.exposeTouchCoords) { + this.on('drag',(e)=>{ + + if (!this.touchActive) return + + this.parsersLocalScope.touchCoords[0] += e.movementX / this.buttonSize[0] + this.parsersLocalScope.touchCoords[1] += e.movementY / this.buttonSize[1] + + }, {element: this.container}) + } + this.on('dragend',()=>{ if (!this.touchActive) return @@ -298,12 +319,6 @@ class Button extends Widget { } - if (this.exposeTouchCoords) { - if (options.y !== undefined) { - this.parsersLocalScope.touchCoords = [options.x / this.buttonSize[0], 1 - options.y / this.buttonSize[1]] - } - } - if (options.local || !options.fromExternal) this.localSet = true if (options.send) this.sendValue() diff --git a/src/client/widgets/mixins/double_tap.js b/src/client/widgets/mixins/double_tap.js index 0c8910a9..f7677beb 100644 --- a/src/client/widgets/mixins/double_tap.js +++ b/src/client/widgets/mixins/double_tap.js @@ -24,8 +24,10 @@ module.exports = (self, callback, options={})=>{ ) { // execute callback at next cycle to ensure draginit events are resolved first + // normalize event now or offset gets lost + var e = normalizeDragEvent(event.detail) setTimeout(()=>{ - callback(normalizeDragEvent(event.detail)) + callback(e) }, 0) lastTapTime = 0