« get me outta code hell

fillParent util - tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-05-31 14:57:24 -0300
committerFlorrie <towerofnix@gmail.com>2018-05-31 14:57:24 -0300
commitb7e7223670328b4cba1c1454dd25057d24025b2b (patch)
treef3979cc512e564125cfec52c3f11f12a477af124
parentf2676294c95695e2de3a7fb88eafae76d6827618 (diff)
fillParent util
-rw-r--r--ui/DisplayElement.js14
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) {