Setting TextButton font size

Not that I know off. So I think you have to implement your own LF class.

Again as I complained about earlier in this thread, it is because there is hard coded values in the function that draw button text. Not in drawButtonText which I earlier in this thread “fixed” to get rid of the hard coded margins, but the remaining hard coded value is in getTextButtonFont, see below.

Font getTextButtonFont (TextButton&, int buttonHeight)
	{
		return { jmin (**16.0f**, buttonHeight * 0.6f) };
	}

So I revised my earlier class and function, so it makes short text bigger, and drawFittedText inside drawButtonText should still manage to scale down for longer text. Try and implement this and let me know if it works for you;


class myLookAndFeel : public LookAndFeel_V4 {
public:
	void drawButtonText (Graphics& g, TextButton& button,
		bool /*shouldDrawButtonAsHighlighted*/, bool /*shouldDrawButtonAsDown*/)
	{
		Font font (button.getHeight () * 0.6f);
		g.setFont (font);
		g.setColour (button.findColour (button.getToggleState () ? TextButton::textColourOnId
			: TextButton::textColourOffId)
			.withMultipliedAlpha (button.isEnabled () ? 1.0f : 0.5f));

		const int yIndent = button.proportionOfHeight (0.1f);
		const int cornerSize = jmin (button.getHeight (), button.getWidth ()) / 2;

		const int leftIndent = cornerSize / (button.isConnectedOnLeft () ?
                  yIndent * 2 : yIndent);
		const int rightIndent = cornerSize / (button.isConnectedOnRight () ? 
                  yIndent * 2 : yIndent);
		const int textWidth = button.getWidth () - leftIndent - rightIndent;

		if (textWidth > 0)
			g.drawFittedText (button.getButtonText (),
				leftIndent, yIndent, textWidth, button.getHeight () - yIndent * 2,
				Justification::centred, 2, 0.5f);
	}
}

You can adjust the “0.6f” value in “Font font (button.getHeight () * 0.6f);” to your needs, for example a bit up for bit larger font size.

Also note that with the above solution, because I bypassed getTextButtonFont, you lose the consistency of uniformly sized text for all buttons.

1 Like