Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/tree/Stage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

import EventEmitter from "../EventEmitter.mjs";
import ElementCore from "./core/ElementCore.mjs";
import Utils from "./Utils.mjs";
import WebGLRenderer from "../renderer/webgl/WebGLRenderer.mjs";
import C2dRenderer from "../renderer/c2d/C2dRenderer.mjs";
Expand Down Expand Up @@ -543,9 +544,11 @@ export default class Stage extends EventEmitter {

getChildrenByPosition(x, y) {
const children = [];
this.root.core.update();
this.ctx.updateTreeOrder = 0;
this.root.core.updateTreeOrder();
this.root.core.collectAtCoord(x, y, children);

children.sort(ElementCore.sortZIndexedChildren);
return children;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tree/core/CoreContext.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class CoreContext {
stage: Stage;

renderToTextureCount: number;
updateTreeOrder: number;

constructor(stage: Stage);

Expand Down
2 changes: 2 additions & 0 deletions src/tree/core/ElementCore.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ declare class ElementCore {
/**
* Fill the array `children` with all the ElementCore instances (including itself and
* its children) that intersect the point (`x`, `y`)
*
* To enforce z-sorting, the result should be sorted using `ElementCore.sortZIndexedChildren`.
*
* @param x
* @param y
Expand Down
6 changes: 2 additions & 4 deletions src/tree/core/ElementCore.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,8 @@ export default class ElementCore {
}
} else {
a.splice(n); // Remove items that were sorted in b array, so that we can sort a
+ // Beware that the function passed here to Array.sort must be stable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fun that it still worked with these + copy-pasta

+ a.sort(ElementCore.sortZIndexedChildren); // Needed because items with same _zIndex may not be ordered by _updateTreeOrder
// Beware that the function passed here to Array.sort must be stable
a.sort(ElementCore.sortZIndexedChildren); // Needed because items with same _zIndex may not be ordered by _updateTreeOrder
// Merge-sort arrays;
ptr = 0;
let i = 0;
Expand Down Expand Up @@ -2163,8 +2163,6 @@ export default class ElementCore {
this._children[i].collectAtCoord(x, y, children);
}
}

return children.sort(ElementCore.sortZIndexedChildren);
}

inBound(tx, ty) {
Expand Down