From b7e7223670328b4cba1c1454dd25057d24025b2b Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 31 May 2018 14:57:24 -0300 Subject: fillParent util --- ui/DisplayElement.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ui/DisplayElement.js') 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) { -- cgit 1.3.0-6-gf8a5