mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 09:37:17 +00:00
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:
parent
a950ceb99e
commit
d13ff4d302
2 changed files with 11 additions and 7 deletions
|
|
@ -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") {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue