diff options
author | Florrie <towerofnix@gmail.com> | 2018-12-08 02:37:15 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-12-08 02:37:15 -0400 |
commit | 1f434c1ef11fa55bab1718ea4e3ca8d115c0dfb1 (patch) | |
tree | 341321a95d376faf720dda8d4e0ca4b69880f3e6 /ui/DisplayElement.js | |
parent | 013835d81e5e56f59faf17e215a73f9e8dc4310b (diff) |
Mouse support
Not exactly the most elegant implementation, but it definitely works and isn't really difficult to code around!
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 |