Game Development Community

Center a text control

by Jason McIntosh · in Torque Game Builder · 04/13/2005 (7:42 am) · 3 replies

Anybody know how to make a GuiTextCtrl update so that it's centered? I've got the horizontal sizing set to "centered" but it doesn't change when I alter the control's text. I tried using repaint() but that didn't work.

Tried searching forums and resources but found nothing except a 3d text control resource.

#1
04/13/2005 (2:02 pm)
Jason, the centered horizsizing is just for the position of the control. You need to actually define a GuiControlProfile and then set justify="center" so that the text itself gets centered within the extents of the guiTextCtrl.

So, in short:

// in your local profile definitions
// (I call my "profileoverrides.cs" as they
// override/superceed the profiles defined by common.)

new GuiControlProfile (CenteredTextProfile)
{
   fontType = "Arial";
   fontSize = 12;
   fontColor = "255 255 255";
   fixedExtent = true;
   justify = "center";
};

// in your gui:
new GuiTextCtrl()
{
   position = "20 20";
   extent = "400 50";
   profile = "CenteredTextProfile";
   horizSizing = "bottom";
   vertSizing = "left";
   text = "Centered Text" ;
}

Also, I believe you can get the same effect by setting the text to use TGE's built-in HTML-lite tags: "Centered Text" but I've never tested it.
#2
04/13/2005 (5:50 pm)
The ML tags only work in the MLText controls
#3
04/14/2005 (7:08 am)
@David: Ok, I was thinking that would center the control itself based on the text (since the extents change with text length). Thanks for the clarification.