SetGlobalFontSize()

Started by Heinrich, 15 October 2014, 13:11:34

Heinrich

Oftentimes my code looks like


widget = create();
widget->setTextSize(Globals::getGuiTextSize());


Having it as a parameter in .conf files would also be an option. Well, this is for people who want the same font size in all their widgets anyway.

Also: Currently it is imho impossible to change the text size of entries in tgui::combobox. Even when I get the renderer for the widget. Also the sf::text is never exposed, so getting the text somehow and setting it there doesn't work either.

What do you think?

texus

I don't want to include it in the .conf file since it is supposed to contain theme-specific options (aka properties that are the same for all widgets and usually don't need to get changed in the code).

But the setGlobalFontSize sounds like a good idea. I'll add it to the todo list.

Heinrich

#2
 :D While I'm at it; Currently text is centered inside a button by computing the center of it's axis-aligned bounding box.  Which is good. However, this bounding box depends on what glyphs you used, for example 'A's center is higher than 'j's center. The consequence is, that the base line of text does not align if you have words containing an Ascender(https://en.wikipedia.org/wiki/Ascender_%28typography%29)  and one that does not. Same for descenders. Image probably says more than words:

Note how "Hangar" has a glyph with a descender (the 'g') and "Join" has not. Vertically this looks correct most of the time (unless your word is long and contains a single Descender, then it looks as if it was too high in it's button)  because the text seems to be correctly centered. Horizontally it looks jumbled. Depending on the Font size this can be more or less noticeable. A solution would be to compute the center by using it's baseline glyphs only. I agree this is not an urgent issue.

texus

Some widgets (like ComboBox) indeed do not expose the size of the text directly. It is automatically determined by the size of the widget (or in case of e.g. ListBox, the item height).

I though a little longer about it and having a setGlobalFontSize function is not that easy. It should be defined whether it adjusts widgets that are already created and/or widgets that are created later. Text size 0 is already reserved for auto-scaling so it would be hard to find out when the global size is used.
So it won't be a quick fix.

Edit: I am aware of that issue and its on the todo list.

Heinrich

#4
QuoteIt should be defined whether it adjusts widgets that are already created and/or widgets that are created later

A change should propagate to all widgets. Like so.

setGlobalFontSize(12);
widget a;  // (is size 12);
setGlobalFontSize(14);
widget b;  // (is size 14);

getSize(a) //14
getSize(b) //14


texus

Changing all the existing widgets isn't that hard.
Changing all widgets that still have to be created is a lot harder. And not changing them is not an option because then every time you have to add a new widget you still have to set the size again.

Heinrich

#6
Quote from: Heinrich on 15 October 2014, 13:11:34
Oftentimes my code looks like


widget = create();
widget->setTextSize(Globals::getGuiTextSize());



:P I understand why one would not to. Myself, I have a static class called settings where I store some global variables like fontSize, paths, videomode, audiovolume, etc

texus

I can write such a getGuiTextSize function for you, but then you still have to apply it for every widget :).

One of the problems is that every widget is different.
You gave a good example yourself with the ComboBox: you cannot set its size. The text size is calculated on the fly and not stored. It would take some work to allow setting a font size in every widget.
Then there is the unfortunate delay between creating the widget and adding it to its parent. If I would make the text size global then this is not an issue, but then you cannot have exceptions. It would be nicer is text size was determined by the parent so that you could have 2 child windows with a different text size for their widgets. But by the time you add a widget to its parent you could have already set a size manually and there is currently no way to detect that.

So its a lot harder on my side than just adding a global function and calling setTextSize on creation :).

Heinrich

#8
Quote from: texus on 15 October 2014, 14:14:44
I can write such a getGuiTextSize function for you, but then you still have to apply it for every widget :).

:) Thanks, but I have such a function, the suggestion is for other users. You could put something like this internally into the widget creation code.

Myself, I will stick to mine anyway since I really do set this everytime in my code as I create a widget. Actually the function is static unsigned int Settings::getGuiTextSize(Globals::TXTSIZE size) // sizes are TXTSIZE::HEADING and so on. This is an artifact, it should rather be named LARGE, NORMAL SMALL. getGuiTextSize(Globals::TXTSIZE size = Globals::TXTSIZE::NORMAL), now that I think of it.
Be careful not to accidentally write an html renderer  ;D

Heinrich

Quote from: texus on 15 October 2014, 14:14:44
But by the time you add a widget to its parent you could have already set a size manually and there is currently no way to detect that.

Well, you could do setGlobalDefaultTextSize(int size) which would simply set a default but not change anything and setGlobalTextSize(int size) which overwrites everything. But I do not want to mess your API up further.

texus

Its not about adding functions, its about how the widgets handle the given text size themselves.
But since this looks like a pretty big change and since I don't have time anyway, I'm just going to not think about this again until July/August :).