Default font size


#1

Is it possible to add something like setDefaultFontHeight to the LookAndFeel class?
I’m looking for a way to set the font size/height for all components of an application in one place and I wasn’t able to find a way without having to call setFont for each component.
Of course I could overwrite for example the “drawLabel” in a custom LookAndFeel and do the same for all other components.
But at least for the labels this is not satisfying because as soon as the label gets edited, the TextEditor uses the internal juce default font size as long as I didn’t call setFont on each label.

I think many people would like to see a setDefaultFontSize, as it seems to be a pretty basic feature.
If for some reason this isnt’ possible then maybe you could add something to the LookAndFeel that allows for overriding the font height of a Labels’ TextEditor.

If I missed something and what I requested is already there, then I’d be happy if you could give me a hint where to look for it.
Thanks.

Jan


#2

Default font size for what?

The default sizes for different types of component can (and will often) be different… I can’t see how it’d make any sense to try to impose a global size for everything!


#3

Of course they can and sometimes will be.
But for example Chrome, Firefox, Visual Studio, Finder… the same fontsize is used for tabs, menubars, menu items, labels, buttons and so on. Many applications use the same fontsize for all controls throughout the application except some special dialogs.
I thought it mitght be helpful to set one global value that is used for all components by default if not explicitly set for a component. This would make it much easier to keep the gui clean and consistent.
I know I can set it for each component to get the desired effect but it’s not very elegant to set the same value for 120 components over and over again.

To override the LAF for labels and set the fontsize there is not very helpful because if the labels becomes a texteditor, the editor uses its own fontsize e.g. the fontsize set for the label and not the fontsize set in the drawLabel of the LookAndFeel.


#4

Well sure, I understand, but if you’re writing a custom lookandfeel that does use the same font size for everything, then in your custom l+f class you’d have your own global size member. Since the existing LookAndFeel base-class doesn’t behave like that, then adding a global size to it would be pointless (and confusing) because none of the existing methods would use that value.

Sounds like this is something that should be added to the L+F so that you only have to set it once. Which exactly are you having to do 120 times?


#5

You could:

  1. Subclass LookAndFeel and add our default font size interface to it:
virtual int getDefaultFontSize ();
  1. Use dynamic_cast on a Component’s LookAndFeel to determine if it has the getDefaultFontSize interface.

  2. If a child component is added to a content component or any of its children, use a series of dynamic_cast to figure out what kind of Component it is: Label, TextBox, etc… Once the Component subclass is known, call getDefaultFontSize if it is available on that Component LookAndFeel and then call the subclass specific function to set the font size.

  3. To get a call when child components are added, use the ComponentListener.

  4. If ComponentListener doesn’t operate recursively, an alternative is to maintain your own recursive list of a content component and its children (using SafePointer). At well defined points (such as through an AsyncUpdater after a window is created) you could ask for a refresh of the list and update font sizes as needed.

This can all be done using the existing JUCE APIs, and neatly tucked away into one or two utility classes with a clean interface.


#6

Both of you, thanks for your suggestions. For sure Juce offers many ways to achieve this. I just thought I might have missed something obvious.
The LookAndFeel class offers so many ways to tune the appearence of an application, so I was a bit surprised that it wasn’t already there.
Maybe the support for customizing the TextEditor in the LookAndFeel class could be slightly improved but I know it’s not that easy because the text style isn’t set for the whole component but for lines or characters.


#7

There is something like a default font size for a component already, for example a Label gets initialized with “font(15.0f)”, a TextEditor with “currentFont(14.0f)”.
Why not make things more transparent and add this to the LookAndFeel:

virtual Font getLabelFont(); virtual Font getTextEditorFont();
The same way as there already isvirtual Font getAlertWindowFont();
In my opinion this is exactly what the LookAndFeel class is for. Adding the AlertWindow Font to the LookAndFeel but setting fixed values for Label and TextEditor is somehow not consistent.


#8

Yes, I agree - A lot of the older classes still have a few hard-coded things like that in them, and I’ve generally just added them to the L+F when people request it. I guess no-one else ever noticed those ones before.


#9

Nice, thanks.
Just to keep things clean, we currently already have “getAlertWindowFont”, “getComboBoxFont” and some other methods using this naming convention but there is also “getFontForTextButton”. I think we should stick with the naming convention “get[Componentname]Font”. The “getFontForTextButton” is the only exception I found but probably it would break peoples code to change this.


#10

Honestly, it’s one method to change - find and replace works like a charm, so it can’t be that big of a deal, can it?


#11

It’s a big deal if people have custom subclasses which override that method, because their code would stop working without any warning.


#12

It’s a big deal if people have custom subclasses which override that method, because their code would stop working without any warning.[/quote]

Yes, this would happen to people with custom subclasses which override that method, wouldn’t it?

:mrgreen:

It looks like the method should now be called with

Sean Costello


#13

I'm trying to figure out how to get the default font when simply Font() is done, to happen.

I can't see how to override the default type faces used.  What I want in specific is a way to get the AlertWindow to use a specific font, but the only way I can see to do that is to override the laf DrawAlertBox() member.  That's overkill for something so simple.

Apart from that, I want the default font to always be one I specify, but I cannot find a way to do that.


#14

LookAndFeel::setDefaultSansSerifTypefaceName()  ??

Or for full control you can override LookAndFeel::getTypefaceForFont() and remap fonts in any way you like. 


#15

It doesn't work for me at all.  


#16

My getTypefaceForFont() never gets called no matter what I do

 


#17

Well, most of the apps I write have custom default fonts, and that's what we always use! I've no idea what you might be doing differently, I'm afraid..


#18

Is there a sample I can look at ?   Maybe it's something simple


#19

Either you're not overriding the function correctly, or your lookandfeel object isn't the default one.