GuiControl::renderJustifiedText() Vertical Centering
by David Wyand · in Torque Game Engine · 12/29/2003 (7:06 pm) · 7 replies
Greetings!
I've been working with TGE's GUI, and have found an issue with vertical centering of text within a GUI element.
In gui/guiControl.cc, within the GuiControl::renderJustifiedText() function, we have the following (about line 1174):
The part in question has been bolded above. I'm not sure why you'd want to subtract two from the font height. Here's an example:
We have a button that is 16 units high, and we are using a font that is 14 units high. The above code would evaluate to:
This gives start.y a value of 2. In other words, the button text will start to draw 2 units down from the top of the button. As 16 - 2 - 14 = 0, that leaves no units between the bottom of the text and the bottom of the button. The button text ends up not looking vertically centered at all.
I feel that the formula should drop the "-2", to give the following:
Using this new formula, we have ( 16 - ( 14 ) ) / 2 = 1. This means that we'll have 1 unit above and below the text for the button...perfectly centered vertically.
How does this change sit with everyone else?
- LightWave Dave
I've been working with TGE's GUI, and have found an issue with vertical centering of text within a GUI element.
In gui/guiControl.cc, within the GuiControl::renderJustifiedText() function, we have the following (about line 1174):
start.y = ( extent.y - ( font->getHeight() [b]- 2[/b] ) ) / 2;
The part in question has been bolded above. I'm not sure why you'd want to subtract two from the font height. Here's an example:
We have a button that is 16 units high, and we are using a font that is 14 units high. The above code would evaluate to:
start.y = ( 16 - ( 14 - 2 ) ) / 2;
This gives start.y a value of 2. In other words, the button text will start to draw 2 units down from the top of the button. As 16 - 2 - 14 = 0, that leaves no units between the bottom of the text and the bottom of the button. The button text ends up not looking vertically centered at all.
I feel that the formula should drop the "-2", to give the following:
start.y = ( extent.y - ( font->getHeight() ) ) / 2;
Using this new formula, we have ( 16 - ( 14 ) ) / 2 = 1. This means that we'll have 1 unit above and below the text for the button...perfectly centered vertically.
How does this change sit with everyone else?
- LightWave Dave
About the author
A long time Associate of the GarageGames' community and author of the Torque 3D Game Development Cookbook. Buy it today from Packt Publishing!
#2
Ask and you shall receive:

The Before image is prior to my change above (with the "-2"), and the After image is with my change above (removal of the "-2").
And please, no questions about my sooper seecret project! :o)
- LightWave Dave
12/29/2003 (9:24 pm)
Greetings!Ask and you shall receive:

The Before image is prior to my change above (with the "-2"), and the After image is with my change above (removal of the "-2").
And please, no questions about my sooper seecret project! :o)
- LightWave Dave
#3
So, about that sooper seecret project..... ;-)
12/29/2003 (10:16 pm)
Looks much better :-) Thanks for the tip, David - it never 'clicked' before why it looked a bit off :-)So, about that sooper seecret project..... ;-)
#5
- LightWave Dave
[EDIT: Strange that I had a double post so many hours later...]
12/30/2003 (6:16 am)
Damnit Davis! No askie! :o)- LightWave Dave
[EDIT: Strange that I had a double post so many hours later...]
#6
01/26/2004 (11:32 am)
Ok, it's checked in!
#7
01/26/2004 (12:24 pm)
Thanks Ben!
Associate Kyle Carter