« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ui.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/ui.js b/ui.js
index 9154390..3da7f5c 100644
--- a/ui.js
+++ b/ui.js
@@ -1014,10 +1014,11 @@ class PathElement extends ListScrollForm {
     }
 
     const itemPath = getItemPath(item)
+    const parentPath = itemPath.slice(0, -1)
 
-    for (const pathItem of itemPath) {
-      const isLast = pathItem === itemPath[itemPath.length - 1]
-      const element = new PathItemElement(pathItem, isLast)
+    for (const pathItem of parentPath) {
+      const isFirst = pathItem === parentPath[0]
+      const element = new PathItemElement(pathItem, isFirst)
       element.on('select', () => this.emit('select', pathItem))
       element.fixLayout()
       this.addInput(element)
@@ -1031,11 +1032,14 @@ class PathElement extends ListScrollForm {
 }
 
 class PathItemElement extends FocusElement {
-  constructor(item, isLast) {
+  constructor(item, isFirst) {
     super()
 
     this.item = item
-    this.isLast = isLast
+    this.isFirst = isFirst
+
+    this.arrowLabel = new Label(isFirst ? 'In: ' : ' > ')
+    this.addChild(this.arrowLabel)
 
     this.button = new Button(item.name || '(Unnamed)')
     this.addChild(this.button)
@@ -1043,9 +1047,6 @@ class PathItemElement extends FocusElement {
     this.button.on('pressed', () => {
       this.emit('select')
     })
-
-    this.arrowLabel = new Label(isLast ? '' : ' > ')
-    this.addChild(this.arrowLabel)
   }
 
   selected() {
@@ -1056,7 +1057,7 @@ class PathItemElement extends FocusElement {
     this.button.fixLayout()
     this.arrowLabel.fixLayout()
     this.w = this.button.w + this.arrowLabel.w
-    this.arrowLabel.x = this.button.right
+    this.button.x = this.arrowLabel.right
     this.h = 1
   }
 }