mirror of https://github.com/espruino/BangleApps
ctrlpad: improve hit-test
parent
b072faf36a
commit
3fda06b701
|
@ -118,13 +118,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
hitTest(x: number, y: number): Control | undefined {
|
hitTest(x: number, y: number): Control | undefined {
|
||||||
const radius = 25;
|
let dist = Infinity;
|
||||||
|
let closest;
|
||||||
|
|
||||||
for(const ctrl of this.controls)
|
for(const ctrl of this.controls){
|
||||||
if(Math.abs(y - ctrl.y) < radius && Math.abs(x - ctrl.x) < radius)
|
const dx = x-ctrl.x;
|
||||||
return ctrl;
|
const dy = y-ctrl.y;
|
||||||
|
const d = Math.sqrt(dx*dx + dy*dy);
|
||||||
|
if(d < dist){
|
||||||
|
dist = d;
|
||||||
|
closest = ctrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return undefined;
|
return dist < 30 ? closest : undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue