From 2e8038264af755d10f19af39461c2880ed48dc73 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sat, 15 Dec 2018 11:49:04 -0400 Subject: Expand width of ContextMenu items to all be equal --- ui.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ui.js b/ui.js index aef7fd8..c3962d5 100644 --- a/ui.js +++ b/ui.js @@ -1724,7 +1724,6 @@ class ContextMenu extends FocusElement { this.y = y this.visible = true - // TODO: Actions, that sorta thing for (const { label, action } of items.filter(Boolean)) { const button = new Button(label) if (action) { @@ -1769,12 +1768,26 @@ class ContextMenu extends FocusElement { } fixLayout() { + // Do an initial pass to determine the width of this menu (or in particular + // the form), which is the greatest width of all the inputs. let width = 10 for (const input of this.form.inputs) { input.fixLayout() width = Math.max(width, input.w) } + // Then do a second pass to apply this 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 are), we need to append space + // characters. + for (const input of this.form.inputs) { + const inputWidth = ansi.measureColumns(input.text) + if (inputWidth < width) { + input.text += ' '.repeat(width - inputWidth) + } + input.fixLayout() + } + let height = Math.min(10, this.form.inputs.length) width += 3 // Space for the pane border and scrollbar -- cgit 1.3.0-6-gf8a5