Game Development Community

GuiTextCtrl position

by Amjad Yahya · in Torque 2D Beginner · 11/16/2013 (12:44 pm) · 2 replies

I can't seem to place my GuiTextCtrl where I want it to be. I create a GuiTextCtrl like so:

%text=new GuiTextCtrl()
	{
		text = "Hellow World!@#";
		textID = "STR_HELLO";
		Profile="GuiTextProfile";
		maxlength = "100";
		HorizSizing = "relative";
        VertSizing = "relative";
		Position = "100 0";

	};
   Canvas.pushDialog(%text);

The GuiTextCtrl position is always rendered at the left center of my screen regardless of what position I set.

#1
11/16/2013 (1:52 pm)
When you use
Canvas.pushdialog();

T2D will assume that you are pushing a new full-screen dialog to the Canvas stack. There are two ways to circumvent this.

Add Method

The easiest way is simply to add your GuiTextCtrl to the current dialog, in the most common case, MySceneWindow.

MySceneWindow.add(%text);

New GuiControl Method

The second way is to first create a blank GuiControl, add the GuiTextCtrl to it, and then push the new GuiControl to the Canvas

%myDialog = new GuiControl();

%text=new GuiTextCtrl()  
    {  
        text = "Hellow World!@#";  
        textID = "STR_HELLO";  
        Profile="GuiTextProfile";  
        maxlength = "100";  
        HorizSizing = "relative";  
        VertSizing = "relative";  
        Position = "100 0";  
  
    };
%mydialog.add(%text);

Canvas.pushDialog(%mydialog);

The first method should be used if you only plan to add one label to your current interface. The second method allows you to create an entire screen of Gui Controls and easily push / pop it from the Canvas.
#2
11/17/2013 (2:48 am)
Thanks Simon, this was very useful, does guiTextCtrl receive mouse clicks?