Fix event x/y by finding container node (#849)

* Fix event x/y by finding relativeParent

* use a tree search to find the container instead of event target hacks
This commit is contained in:
jberg 2019-08-12 16:33:38 -07:00 committed by Jordan Eldredge
parent a950ceb99e
commit d13ff4d302
2 changed files with 11 additions and 7 deletions

View file

@ -28,9 +28,13 @@ function useJsUpdates(node) {
}
function handleMouseEventDispatch(node, event, eventName) {
const rect = event.target.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
event.stopPropagation();
// In order to properly calculate the x/y coordinates like MAKI does we need
// to find the container element and calculate based off of that
const container = Utils.findParentNodeOfType(node, ["container"]);
const x = event.clientX - container.getleft();
const y = event.clientY - container.gettop();
node.js_trigger(eventName, x, y);
if (event.nativeEvent.type === "mousedown") {

View file

@ -56,19 +56,19 @@ class GuiObject extends MakiObject {
}
gettop() {
return this.attributes.y || 0;
return Number(this.attributes.y) || 0;
}
getleft() {
return this.attributes.x || 0;
return Number(this.attributes.x) || 0;
}
getheight() {
return this.attributes.h || 0;
return Number(this.attributes.h) || 0;
}
getwidth() {
return this.attributes.w || 0;
return Number(this.attributes.w) || 0;
}
resize(x, y, w, h) {