From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id EBADB6DF5A for ; Mon, 28 Mar 2022 15:07:45 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E22B625E43 for ; Mon, 28 Mar 2022 15:07:45 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 4FEAE25E31 for ; Mon, 28 Mar 2022 15:07:45 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2736140B30 for ; Mon, 28 Mar 2022 15:07:45 +0200 (CEST) From: Matthias Heiserer To: pve-devel@lists.proxmox.com Date: Mon, 28 Mar 2022 15:07:34 +0200 Message-Id: <20220328130737.2961451-1-m.heiserer@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.007 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH v2 widget-toolkit 1/3] Buttons: add AltText X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Mar 2022 13:07:46 -0000 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 --- 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