[pve-devel] [PATCH v2 widget-toolkit 1/3] Buttons: add AltText

Matthias Heiserer m.heiserer at proxmox.com
Mon Mar 28 15:07:34 CEST 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 button.

Signed-off-by: Matthias Heiserer <m.heiserer at proxmox.com>
---
changes from v1:
move into separate class
rename vars to something a little bit nicer
move comment above function
reorder some statements

Note: Because it's now guaranteed that the function is called at render time,
I think we can leave out the extra logic to test which text is currently set.


 src/button/AltText.js | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 src/button/AltText.js

diff --git a/src/button/AltText.js b/src/button/AltText.js
new file mode 100644
index 0000000..e74d042
--- /dev/null
+++ b/src/button/AltText.js
@@ -0,0 +1,22 @@
+Ext.define('Proxmox.button.AltText', {
+    extend: 'Proxmox.button.Button',
+    xtype: 'proxmoxAltTextButton',
+
+    defaultText: "",
+    altText: "",
+
+    listeners: {
+	// HACK: calculate the max button width on first render to avoid toolbar glitches
+	render: function(button) {
+	    let me = this;
+
+	    button.setText(me.altText);
+	    let altWidth = button.getSize().width;
+
+	    button.setText(me.defaultText);
+	    let defaultWidth = button.getSize().width;
+
+	    button.setWidth(defaultWidth > altWidth ? defaultWidth : altWidth);
+	},
+    },
+});
-- 
2.30.2






More information about the pve-devel mailing list