SetGlobalFontSize()
« on: 15 October 2014, 13:11:34 »
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?
« Last Edit: 15 October 2014, 13:26:02 by Heinrich »

*

texus

  • *****
  • 1172
    • View Profile
    • Texus's Blog
Re: SetGlobalFontSize()
« Reply #1 on: 15 October 2014, 13:25:44 »
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.

Re: SetGlobalFontSize()
« Reply #2 on: 15 October 2014, 13:42:37 »
 :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.
« Last Edit: 15 October 2014, 13:47:00 by Heinrich »

*

texus

  • *****
  • 1172
    • View Profile
    • Texus's Blog
Re: SetGlobalFontSize()
« Reply #3 on: 15 October 2014, 13:42:54 »
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.

Re: SetGlobalFontSize()
« Reply #4 on: 15 October 2014, 13:52:11 »
Quote
It 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

« Last Edit: 15 October 2014, 13:59:24 by Heinrich »

*

texus

  • *****
  • 1172
    • View Profile
    • Texus's Blog
Re: SetGlobalFontSize()
« Reply #5 on: 15 October 2014, 14:02:07 »
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.

Re: SetGlobalFontSize()
« Reply #6 on: 15 October 2014, 14:07:57 »
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
« Last Edit: 15 October 2014, 14:10:22 by Heinrich »

*

texus

  • *****
  • 1172
    • View Profile
    • Texus's Blog
Re: SetGlobalFontSize()
« Reply #7 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 :).

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 :).

Re: SetGlobalFontSize()
« Reply #8 on: 15 October 2014, 14:21:38 »
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
« Last Edit: 15 October 2014, 14:39:11 by Heinrich »

Re: SetGlobalFontSize()
« Reply #9 on: 15 October 2014, 14:43:43 »
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

  • *****
  • 1172
    • View Profile
    • Texus's Blog
Re: SetGlobalFontSize()
« Reply #10 on: 15 October 2014, 14:47:04 »
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 :).