From 463177281c294ad69f85d00a10450494c2001870 Mon Sep 17 00:00:00 2001 From: Matthias Heiserer Date: Mon, 28 Mar 2022 15:07:34 +0200 Subject: [PATCH] Buttons: add AltText 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 Reviewed-by: Dominik Csapak --- src/Makefile | 1 + src/button/AltText.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/button/AltText.js diff --git a/src/Makefile b/src/Makefile index dd7729e..95da5aa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -45,6 +45,7 @@ JSSRC= \ form/ACME.js \ form/UserSelector.js \ button/Button.js \ + button/AltText.js \ button/HelpButton.js \ grid/ObjectGrid.js \ grid/PendingObjectGrid.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); + }, + }, +});