[pve-devel] [PATCH widget-toolkit 1/2] Utils: add calculate max button width hack

Matthias Heiserer m.heiserer at proxmox.com
Thu Mar 24 12:33:29 CET 2022


The same code is used once in widget toolkit and twice in PVE already,
so it makes sense to add it as a separate function.

Signed-off-by: Matthias Heiserer <m.heiserer at proxmox.com>
---
 src/Utils.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/Utils.js b/src/Utils.js
index 6a03057..27fcd1d 100644
--- a/src/Utils.js
+++ b/src/Utils.js
@@ -1272,6 +1272,17 @@ utilities: {
 	    .map(val => val.charCodeAt(0)),
 	);
     },
+
+    calculateWidth: function(btn) {
+	// HACK: calculate the max button width on first render to avoid toolbar glitches
+	let defSize = btn.getSize().width;
+
+	btn.setText(btn.altText);
+	let altSize = btn.getSize().width;
+
+	btn.setText(btn.defaultText);
+	btn.setWidth(altSize > defSize ? altSize : defSize);
+    },
 },
 
     singleton: true,
-- 
2.30.2






More information about the pve-devel mailing list