« 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
path: root/ui/DisplayElement.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/DisplayElement.js')
-rw-r--r--ui/DisplayElement.js45
1 files changed, 38 insertions, 7 deletions
diff --git a/ui/DisplayElement.js b/ui/DisplayElement.js
index fab957e..8720142 100644
--- a/ui/DisplayElement.js
+++ b/ui/DisplayElement.js
@@ -44,10 +44,37 @@ module.exports = class DisplayElement extends Element {
     // Like drawTo, but only calls drawTo if the element is visible. Use this
     // with your root element, not drawTo.
 
-    if (this.visible) {
+    if (!this.visible) {
+      return
+    }
+
+    const causeRenderEl = this.shouldRender()
+    if (causeRenderEl) {
       this.drawTo(writable)
-      this.drawChildrenTo(writable)
+      this.renderChildrenTo(writable)
       this.didRenderTo(writable)
+    } else {
+      this.renderChildrenTo(writable)
+    }
+  }
+
+  shouldRender() {
+    // WIP! Until this implementation is finished, always return true (or else
+    // lots of rendering breaks).
+    /*
+    return (
+      this[DisplayElement.scheduledDraw] ||
+      [...this.directAncestors].find(el => el.shouldRender())
+    )
+    */
+    return true
+  }
+
+  renderChildrenTo(writable) {
+    // Renders all of the children to a writable.
+
+    for (const child of this.children) {
+      child.renderTo(writable)
     }
   }
 
@@ -75,19 +102,19 @@ module.exports = class DisplayElement extends Element {
     }
   }
 
-  drawChildrenTo(writable) {
-    // Draws all of the children to a writable.
-
-    for (const child of this.children) {
-      child.renderTo(writable)
+  confirmDrawValuesExists() {
+    if (!this[DisplayElement.drawValues]) {
+      this[DisplayElement.drawValues] = {}
     }
   }
 
   getDep(key) {
+    this.confirmDrawValuesExists()
     return this[DisplayElement.drawValues][key]
   }
 
   setDep(key, value) {
+    this.confirmDrawValuesExists()
     const oldValue = this[DisplayElement.drawValues][key]
     if (value !== this[DisplayElement.drawValues][key]) {
       this[DisplayElement.drawValues][key] = value
@@ -237,6 +264,10 @@ module.exports = class DisplayElement extends Element {
   get visible() { return this.getDep('visible') }
   set visible(v) { return this.setDep('visible', v) }
 
+  // Commented out because this doesn't fix any problems (at least ATM).
+  // get parent() { return this.getDep('parent') }
+  // set parent(v) { return this.setDep('parent', v) }
+
   get absX() {
     if (this.parent) {
       return this.parent.contentX + this.x