« get me outta code hell

Always display at least part of group name - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-07-09 18:12:10 -0300
committerFlorrie <towerofnix@gmail.com>2019-07-09 18:12:10 -0300
commitcddda96a4622225caee1e889524876c02ab97c87 (patch)
treef5d3bde0d52e9a9a9094231c6d2c2c1cd952a7d0 /ui.js
parenta0d5dfcd12b27811dad61b2fea5b73c359f54cf5 (diff)
Always display at least part of group name
...in PathElements. Particularly, in the queue listing, which is often
too thin to display even a single group name.
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/ui.js b/ui.js
index 378cd77..7cc55e2 100644
--- a/ui.js
+++ b/ui.js
@@ -2068,8 +2068,21 @@ class PathItemElement extends FocusElement {
   }
 
   fixLayout() {
-    this.button.fixLayout()
+    const text = this.item.name || '(Unnamed)'
+
+    const maxWidth = this.parent ? this.parent.contentW : Infinity
     this.arrowLabel.fixLayout()
+
+    const maxButtonWidth = maxWidth - this.arrowLabel.w
+
+    if (text.length > maxButtonWidth) {
+      this.button.text = unic.ELLIPSIS + text.slice(-(maxButtonWidth - 1))
+    } else {
+      this.button.text = text
+    }
+
+    this.button.fixLayout()
+
     this.w = this.button.w + this.arrowLabel.w
     this.button.x = this.arrowLabel.right
     this.h = 1