« get me outta code hell

fix context menu not detecting scroll bar appropriately - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-14 17:33:20 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-14 17:33:20 -0300
commit180df0db0904ac8a0fd4070d0f2f320358d04a88 (patch)
treeae1f7df95cba1716a13d42a1e93b95b11f143c91
parent3111926f8826b323825bde6efe4ffdb3d10488cd (diff)
fix context menu not detecting scroll bar appropriately
-rw-r--r--ui.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/ui.js b/ui.js
index 20d7381..3d66ce8 100644
--- a/ui.js
+++ b/ui.js
@@ -5086,16 +5086,30 @@ class ContextMenu extends FocusElement {
 
     width += 2 // Space for the pane border
     height += 2 // Space for the pane border
-    if (this.form.scrollBarShown) width++
+
+    // Hilarity time: at THIS point, we can't identify if the form has its
+    // scroll bar visible, because we haven't constrained the height of the
+    // form. We're going to apply all the dimensions leading to the form twice,
+    // adapting the second time to be one wider if the form shows its scroll
+    // bar the first time.
+
     this.w = width
     this.h = height
-
     this.fitToParent()
 
     this.pane.fillParent()
     this.form.fillParent()
     this.form.fixLayout()
 
+    // We only need to update our own (and the descendants') width this time,
+    // because height won't have changed from the earlier measurement.
+    if (this.form.scrollBarShown) width++
+    this.w = width
+
+    this.pane.fillParent()
+    this.form.fillParent()
+    this.form.fixLayout()
+
     // After everything else, do a second pass to apply the decided width
     // to every element, so that they expand to all be the same width.
     // In order to change the width of a button (which is what these elements