Hi Jules,
I’ve been testing the fonts stuff and it’d be really great to be able to change the fonts in each control directly (like setFont(…) in labels).
Override L&F just to change the font of a button or a combo it’s a very big cannon for such a tiny fly
I think an extremely simple way to do it without breaking existing code and L&Fs is just to include a Font pointer in TextButton/etc classes, by default that pointer would be null so it’d be used the default font in L&F render code:
void LookAndFeel::drawButtonText (...)
{
if(button.GetInternalFontPtr() == nullptr)
{
// Standard behaviour: the button has no font, use default font...
Font font (getFontForTextButton (button));
g.setFont (font);
}
else
{
// Button has its own font, use it...
g.setFont(*(button.GetInternalFontPtr()));
}
g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
: TextButton::textColourOffId)
.withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
const int fontHeight = roundToInt (font.getHeight() * 0.6f);
const int leftIndent = jmin (fontHeight, 2 cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
const int rightIndent = jmin (fontHeight, 2 cornerSize / (button.isConnectedOnRight() ? 4 : 2));
g.drawFittedText (button.getButtonText(),
leftIndent,
yIndent,
button.getWidth() - leftIndent - rightIndent,
button.getHeight() - yIndent * 2,
Justification::centred, 2);
}
Cheers,
Javi