Main Menu

Global font

Started by Garwin, 17 June 2022, 20:38:06

Garwin

I was able to solve the issue but anyway I am insterested how it works and why it happenes.

I have several states. In each state TGUI object is created.
In one of the states (score board) I set different global font than all other states.

But what was interesting that going from this state (score board) to another, this another state previously having standard font has same font as score board state.
And even if the state is created as new object and inside that state global font is set to standard (different than score board). All created buttons has the different font. And even if they are created after the standard font is set in this state as global.

I solve it switching on score board state global font to standard as I did not used it because fonts were set per widget but I am quite interested how it was possible.

texus

Did you change the font in the renderer of the button? If you change the font in the theme or via getSharedRenderer() then it is applied on any button, even those from other states.

If a font is set in the renderer, then the widget will use that one.
If the renderer has no font, then it selects the font from the parent widget (if it has one).
If neither font exist, then the default font is used.

Setting the font of the renderer overwrites the font on all widgets connected to that renderer immediately.
Calling Gui::setFont or setting the renderer font of a container will cause all child widgets to inherit the font and change to the new font unless their renderer specified a different font.
Calling Font::setDefaultFont font only affects new widgets, not existing ones.

(I really need to do something about this forum, since I updated the forum software I've had a lot of issues with notifications. I didn't get any notice about this topic. You might find quicker help on Discord)