Game Development Community

guiTextCtrl Help

by Chase Webb · in Torque 2D Beginner · 06/29/2014 (7:31 am) · 11 replies

Hey all. A small question for you today. Can someone give me a list of what values can be used when making a guiTextCtrl? I'm trying to add text to my buttons that appear like they are on separate lines (as if I hit Enter between words in a word processor), and this is what everyone suggested to me, but I'm having a hell of a time trying to figure out how to make the text size and color alter.

Thanks in advance!

#1
06/29/2014 (8:19 am)
You need to look in the modules/Sandbox/1/gui/guiProfiles.cs script - you assign a profile to gui objects and the guiTextCtrl is no different.

You can also add profile definitions anywhere - even generate them dynamically - but it's good to keep everything in one place. I usually place profiles that my module uses in the module's /gui folder.
#2
06/29/2014 (8:42 am)
Yeah, profiles will fix your issue in most cases.

What you describe however usually means that the GuiTextCtrl has HorizSizing and VertSizing values that are not what you want.

HorizSizing determines how the control Width or X position will be modified.
Valid values are : "left", "right", "center", "width" or "relative".

VertSizing determines how the control Height or Y position will be modified.
Valid values are : "top", "bottom", "center", "height" or "relative".

Center is always reliable in both instances and will always keep your control in the center of its parent on that axis.

The other settings, when coupled with a valid Position "X Y" can produce very different results and must be tested to understand properly. I still get confused when using them.

Also make sure to set MinExtent to something valid; the control will never shrink below that width and height.
#3
06/29/2014 (1:33 pm)
Also, make sure that the control is tall enough to display your text - if it's not wide enough it cuts off the end, but if it's not tall enough it doesn't render the text at all.
#4
06/30/2014 (7:27 am)
Unfortunately, nothing suggested above seems to have helped me. Can someone give me an example button with two child GuiTextCtrls with non default text size and color?

On a related note, is the profile Gui_Profile_Modalless_Text no supporting the text changes for some reason?
#5
06/30/2014 (10:53 am)
Note that you can simply use the 'text' field of your GuiButton to display text on a button.

Also try using GuiMLTextCtrl, ML stands for multi-line.

Look at the 1:29 mark in the following video


I think this is what you're talking about, a text control within a button control.

Here is the exact Gui that I use

<GuiBitmapButtonCtrl
class="DialogBTN"
Name="DialogTemplateGUI"
Profile="GreenButtonProfile">

<GuiMLTextCtrl
Position="15 15"
HorizSizing="width"
VertSizing="relative"
Profile="GuisomeTextProfile" />
</GuiBitmapButtonCtrl>

and here is the GuiProfile that is used by the GuiMLTextCtrl
if (!isObject(GuiSomeTextProfile)) new GuiControlProfile(GuiSomeTextProfile)
{
   fontType = "Fanwood Italic"; //You probably don't have that font :)
   fontSize = "32";
   justify = "center";
   fontColor = "255 255 255 255";
   Modal = false;
   border = false;
   borderColor = "0 0 0 0";
};

and the text I use is formatted as follows, where NL stands for New Line.


"Lay down the roads from" NL "START to END" NL "and click the Next button" NL "when done."


Just don't expect it to write out one character at a time :) That'd take another post entirely!

Hope that helps!
#6
06/30/2014 (7:13 pm)
NL, SPC, and TAB - love them....

One character at a time - I helped someone do that ages ago on here somewhere....
#7
07/02/2014 (8:27 am)
Ok, I'm making some progress - mainly because I've discovered that it seems you can edit button options by making new profiles and putting the settings there, while the only settings you can set from within the "new guiMLTextCtrl" that work appear to be Name, Profile, Text, and Position.

Font size seems to be helping, though auto sizing and centering have failed completely so far.

This is what I've got:

Profile:
//-----------------------------------------------------------------------------
// CUSTOM MADE TESTING
if (!isObject(LBGuiTextProfile)) new GuiControlProfile (LBGuiTextProfile)
{
    border=true;

    // font
    fontType = $platformFontType;
    fontSize = $platformFontSize;

    fontColor = "white";
	bordercolor = "white";
HorizSizing = "width";
VertSizing = "height";
justify = "center";
    modal = true;
    justify = "center";
    autoSizeWidth = true;
    autoSizeHeight = true;
    returnTab = false;
    numbersOnly = false;
    cursorColor = "0 0 0 255";
	minextent = "50 50";
			FontSize = "14";
};

and here is where I call it:
%TestLevelButton = new GuiButtonCtrl(TestLevelButton)
      {
         Name="TestLevelButton";
        Profile="BlueButtonProfile";
        Text="";
        ButtonType="PushButton";
        canSaveDynamicFields="0";
        isContainer="1";
        HorizSizing="relative";
        VertSizing="relative";
        Position="914 658";
        Extent="100 100";
        MinExtent="75 75";
        canSave="1";
        Visible="1";
        Active="1";
        hovertime="1000";
        groupNum="-1";
        useMouseEvents="1";
      };
	  
	 %TestLevelButtonText1 = new guiMLTextCtrl(TestLevelButtonText1){
        Name="TestLevelButtonText1";
        Profile="LBGuiTextProfile";
        Text="Test" NL "Level";
        Position="25 25";
      };

	  %TestLevelButton.add(%TestLevelButtonText1); 
	  %LoadLevelBuilderBottomFrame.add(%TestLevelButton);
#8
07/02/2014 (8:28 am)
While I'm on this topic, why can't the NL functionality from guiMLTextControl be added to GuiButtonCtrl? Being able to just add the text in the button multi-lined would save a lot of time.
#9
07/03/2014 (7:07 am)
It's not a question of can or can't - it's more a question of who and when....

I'd start by comparing GuiControl::renderJustifiedText() to guiMLTextCtrl::reflow() - but remember that guiMLTextCtrl supports html tags so you can probably omit that.

But really, looking at how GuiControl handles text (simple stringtable entry) versus how guiMLTextCtrl handles text... well, just take a peek and you'll see what I mean.

Might be easier to borrow the GuiControl::renderToolTip() wrapping.
#10
07/05/2014 (1:42 am)
Yup, looked over those two (and a couple other functions) and the code is way beyond me. Back to trying to figure out why my text settings for buttons and gui(ml)textctrls aren't working right.
#11
07/05/2014 (7:24 am)
Ok, for future reference for anyone trying to use GuiMLTextCtrl:

1- Some settings you have to define in the guiProfiles.cs
2- Other settings you have to use when you call the profile (when you do "new GuiMLTextCtrl()") - though I don't know if this applies when you use taml files instead of torquescript functions.
3- Both of these are irrelevant and stop working when you find the list of HTML commands. One example would be that justify does NOT work unless you throw it in the text field as so: "<just:center>Here is my text blah <br>blah<br>blah"