Just saw this topic in my emails and thought it is worth posting an example here:
The recommended way is to use the TouchSpy option on the parent layout.
My implementation uses absolute deltas for moving instead of relative jumps to prevent drifting,
and also has update rate limiting for better control over performance
function OnStart() {
lay = app.CreateLayout("Absolute", "FillXY,TouchSpy")
lay.SetBackColor("#3300ff00")
for(let i = 0; i < 3; i++) {
txt = app.CreateText("Hello " + (i + 1))
txt.SetTextSize(62)
lay.AddChild(txt)
txt.SetBackColor("#330000ff")
txt.SetPosition(Math.random() * 0.8, Math.random() * 0.9)
addDND(txt, lay, 25 * i);
}
app.AddLayout(lay)
}
function addDND(txt, lay, rate = 50) {
txt.data._dragRate = rate;
txt.SetOnTouchDown(I(function() {
lay.data._d = txt;
lay.data._x = txt.GetPosition().left
lay.data._y = txt.GetPosition().top
}))
// add dnd callbacks only once
if(lay.data._dragInited) return;
lay.data._dragInited = true;
lay.SetOnTouchDown(I(ev => { lx = ev.X, ly = ev.Y; }));
lay.SetOnTouchUp(I(ev => { lay.data._d = undefined; }));
var nextUpdate = 0, lx = 0, ly = 0;
lay.SetOnTouchMove(I(ev => {
if(!lay.data._d) return;
const t = Date.now();
if(t < nextUpdate) return;
nextUpdate = t + (lay.data._d.data._dragRate || rate);
var dx = ev.X - lx, dy = ev.Y - ly;
lay.data._d.SetPosition(lay.data._x + dx, lay.data._y + dy);
}))
}