« get me outta code hell

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:
-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) {