diff options
author | Florrie <towerofnix@gmail.com> | 2018-05-31 14:57:24 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-05-31 14:57:24 -0300 |
commit | b7e7223670328b4cba1c1454dd25057d24025b2b (patch) | |
tree | f3979cc512e564125cfec52c3f11f12a477af124 | |
parent | f2676294c95695e2de3a7fb88eafae76d6827618 (diff) |
fillParent util
-rw-r--r-- | ui/DisplayElement.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ui/DisplayElement.js b/ui/DisplayElement.js index 75263ac..ca50672 100644 --- a/ui/DisplayElement.js +++ b/ui/DisplayElement.js @@ -118,6 +118,20 @@ module.exports = class DisplayElement extends EventEmitter { this.y = Math.round((this.parent.contentH - this.h) / 2) } + fillParent() { + // Utility function to fill this element in its parent. Must be called + // only when it has a parent. + + if (this.parent === null) { + throw new Error('Cannot fill parent when parent is null') + } + + this.x = 0 + this.y = 0 + this.w = this.parent.contentW + this.h = this.parent.contentH + } + get root() { let el = this while (el.parent) { |