TextButton Font size without LaF

Hi all,
I need to have 6 TextButtons that all look the same but with different font sizes.
Do I really need to subclass from my CustomTextButtonLookAndFeel 6 times and change the font size there? this seems absurd.

Thanks!
Rollo

LookAndFeel_V2::drawButtonText uses drawFittedText, that automatically adapts the font size so the whole text is visible.
If you don’t want that, you can override that method. But you are right, it would be overly complicated to use several lookAndFeel classes.
Instead you could put a property into the button, that you use in your drawButtonText method:

button.getProperties()["fontsize"] = 20;
//...
auto fontsize = button.getProperties().getWithDefault ("fontsize", 12);
g.setFont (fontsize);
g.drawText (...);  // don't use drawFittedText to force your size

Hi Daniel, thanks for your help!

This results in a (no viable overloaded “=”) error.

Oh, I am sorry, since it returned a reference, I thought it would accept it as lvalue…
But you can use the set of the NamedValueSet instead:

button.getProperties().set ("fontsize", 20);

Hope that’s better :wink:

2 Likes

Perfect!
Amazing idea :slight_smile:
Thanks