I’ve checked the forum for this, but it seems none of the current solutions are working for me.
I want to set a default font for all components to use, so in my custom LookAndFeel class’ constructor I wrote setDefaultSansSerifTypefaceName("Avenir Next"); but this does not change the font.
The other functions in my LookAndFeel are working as expected. Also, the font exists on my system and works when I set the font for individual components.
Thanks!
Thanks Jules!
This does indeed work for me as well.
Although, I would’ve expected the setDefualtSansSerifTypefaceName call to work in the constructor of my custom LookAndFeel. The rest of my custom LookAndFeel works as expected within my application except for this call. For example here’s a summary of what my code looks like:
CustomLookAndFeel.h
class CustomLookAndFeel : public LookAndFeel_V3
{
public:
CustomLookAndFeel()
{
setDefaultSansSerifTypefaceName ("Avenir Next"); // This call doesn't work
}
// The rest of my LookAndFeel which does work . . .
};
MainComponent.cpp
class MainContentComponent : public Component
{
public:
MainContentComponent()
{
setLookAndFeel (&customLookAndFeel);
}
// The rest of the class . . .
private:
CustomLookAndFeel customLookAndFeel;
};
I’m probably just fundamentally misunderstanding something about this.
Thanks again for your solution though! I will definitely be using that solution. I just wanted to clarify my understanding about what I was trying to do earlier with the LookAndFeel Constructor.
Well, you could expect that all the Component’s that have your custom LookAndFeel class would use the Font right? I mean it’s a member method of the LookAndFeel class and it’s not a static one so the assumption is not so un-logical is it?
Well no - think about the code you actually write. E.g. if you create a font object
Font myFont (15.0f);
… then like I said above, how could it possibly know which component to get the L+F from? What if you have two different components with two L+Fs and use this same font object in both of them?
True that makes sense, but i think the OP was expecting that his JUCE Buttons or Labels would start using the Font he specified in his Custom LookAndFeel.
I know you can override all the draw methods and do anything you like but i can understand why he is confused. You told him he was probably doing something ‘silly’…
Well, yes, but to be fair if I’d seen the same symptoms in my own code, my first reaction would also have been to assume I’d made a silly mistake. Everyone makes silly mistakes, it’s not a criticism!
i have set this way but unable to set the font. is there any font ttf required in assets folder or juce will take it from library. I am new please help