panel: expose useful event.firstTarget

This commit is contained in:
jean-emmanuel 2025-04-02 10:27:15 +02:00
parent bdf3ad1958
commit 6fa3f9862e
2 changed files with 10 additions and 3 deletions

View file

@ -82,8 +82,11 @@ This script has access to the same variables and functions as the `script` prope
??? infos "Containers onTouch"
*Currently only available in v1.29.0-beta*
Containers (root, panel, etc) can monitor touch events happening inside them, it works like with [Canvas](../canvas/#ontouch), with a few differences:
- `event.firstTarget` will return the id of the first touched widget
- setting `event.preventDefault` to `true` will prevent the event from reaching widgets in the container ('start' and 'move' events only)
- setting `event.allowScroll` to `true` will allow touch scrolling where it would normally be prevented ('start' event only)
- setting `event.inertia` will affect 'move' events (works like widget `sensitivity` in reverse (1 = normal, 10 = slow move))

View file

@ -359,16 +359,20 @@ class Panel extends Container() {
onTouch(e, name) {
var event = {...e}
delete event.firstTarget
var event = {...e},
w
event.targetName = event.target ? event.target.getAttribute('name') : ''
event.targetTagName = event.target ? event.target.tagName : ''
var w = widgetManager.getWidgetByElement(event.target)
w = widgetManager.getWidgetByElement(event.target)
if (w) event.target = w === this ? 'this' : w.getProp('id')
else event.target = null
w = widgetManager.getWidgetByElement(event.firstTarget)
if (w) event.firstTarget = w === this ? 'this' : w.getProp('id')
else event.firstTarget = null
event.type = name
this.scripts.onTouch.run({