diff options
Diffstat (limited to 'ui/DisplayElement.js')
-rw-r--r-- | ui/DisplayElement.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ui/DisplayElement.js b/ui/DisplayElement.js index 66d29aa..952c78e 100644 --- a/ui/DisplayElement.js +++ b/ui/DisplayElement.js @@ -184,6 +184,32 @@ module.exports = class DisplayElement extends EventEmitter { return ancestors } + getElementAt(x, y) { + const children = this.children.slice() + + // Start searching the last- (top-) rendered children first. + children.reverse() + + for (const el of children) { + if (!el.visible) { + continue + } + + const el2 = el.getElementAt(x, y) + if (el2) { + return el2 + } + + const { absX, absY, w, h } = el + if (absX <= x && absX + w > x) { + if (absY <= y && absY + h > y) { + return el + } + } + } + return null + } + get absX() { if (this.parent) { return this.parent.contentX + this.x |