« get me outta code hell

Add new property clickThrough to all elements - 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
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-08-25 18:08:28 -0300
committerFlorrie <towerofnix@gmail.com>2019-08-25 18:10:43 -0300
commit878e55e7c2a203d89fb1dad83ba6d6d8751b521a (patch)
treefa938c31928806c49d855101e6dee074aa2c5856 /ui
parentacb8c05987c72ceca423acf2f5761a50f641d1f8 (diff)
Add new property clickThrough to all elements
Diffstat (limited to 'ui')
-rw-r--r--ui/DisplayElement.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/ui/DisplayElement.js b/ui/DisplayElement.js
index 9498487..b7e07b9 100644
--- a/ui/DisplayElement.js
+++ b/ui/DisplayElement.js
@@ -26,6 +26,11 @@ module.exports = class DisplayElement extends EventEmitter {
 
     this.hPadding = 0
     this.vPadding = 0
+
+    // Note! This only applies to the parent, not the children. Useful for
+    // when you want an element to cover the whole screen but allow mouse
+    // events to pass through.
+    this.clickThrough = false
   }
 
   drawTo(writable) {
@@ -196,13 +201,17 @@ module.exports = class DisplayElement extends EventEmitter {
   }
 
   getElementAt(x, y) {
+    // Gets the topmost element at the provided absolute coordinate.
+    // Note that elements which are not visible or have the clickThrough
+    // property set to true are not considered.
+
     const children = this.children.slice()
 
     // Start searching the last- (top-) rendered children first.
     children.reverse()
 
     for (const el of children) {
-      if (!el.visible) {
+      if (!el.visible || el.clickThrough) {
         continue
       }