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

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Mar 25 09:35:48 CET 2022


On 24.03.22 12:33, Matthias Heiserer wrote:
> 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) {

way to general name for such a specific use case, NACK, rather:

maxAltTextButtonWidth

> +	// HACK: calculate the max button width on first render to avoid toolbar glitches

comment could go in line above the function declaration.

> +	let defSize = btn.getSize().width;

now that we're not on a deeper indentation level we can also spell out the variable
names more nicely.

> +
> +	btn.setText(btn.altText);
> +	let altSize = btn.getSize().width;
> +
> +	btn.setText(btn.defaultText);
> +	btn.setWidth(altSize > defSize ? altSize : defSize);
> +    },
>  },
>  
>      singleton: true,






More information about the pve-devel mailing list