Game Development Community

GuiTextListCtrl and usuage of the columns attribute

by Lateral Punk · in Torque Game Engine · 09/10/2004 (11:43 am) · 15 replies

I'm trying to figure out how to use the GuiTextListCtrl. I have it working on screen, but what i'm looking for is using the "columns" attribute so that i can have multiple column text per row. I can't find much documentation pertaining how this columns field works. I have already looked at playerlist.gui and their usuage of this control, but don't use this feature that i want. I want my text list to work like this (and i think the gui control allows for it, correct me if i'm wrong):

col 0 col 1
row 0 A AA
row 1 B BB

i guess as part of the question, how in the world does the addRow method of the control work? whats the difference betwen id and index?

any help would be greatly appreciated!

#1
09/10/2004 (2:20 pm)
Greetings!

If I remember correctly, the 'columns' parameter for the GuiTextListCtrl specifies the width of the columns in pixels. So, if the first column were to start at the 0 position, the next column at 50 pixels and the final column at 125 pixels, the .gui file would look like this:

columns = "0 50 125";

You just separate the values with a space.

Now, to populate your columns with the addRow method, you separate your text with tabs. The strings you'd want to send then are:

"A\tAA\tAAA"
"B\tBB\tBBB"

for the first and second row.

I hope that helps. It's just from memory.

- LightWave Dave
#2
09/11/2004 (7:30 am)
Yeah, that's a bit tricky - the numbers in columns are pixels from the left of the control to the start of the column, not widths of the columns. That always messes me up...
#3
09/13/2004 (9:49 am)
Greetings!

Ah, oops! What Ben said.

- LightWave Dave
#4
09/19/2004 (1:12 pm)
That hit the spot! thanks!!
#5
11/07/2004 (1:16 am)
This thread solved a big problem of mine. I'm wondering though if it's possible that when you click on a row that has two columns, to return the text only from the first column.

Currently, getValue and getRowTextById both return the content of the whole row. Is there a way to specify from which column to retrieve the data of a given row?

If not, any pointers on how I can implement it in guiTextListCtrl.cc?

Thanks,
Nick
#6
11/07/2004 (1:43 am)
You can use the "getRowTextById " method and use getWord(int, string);

Example:

%columnData = %obj.getRowTextById(%id);
%word_one = getWord(0, %columnData);
%word_two = getWord(1, %columnData);

This will only work if the info has spaces between the words, if they dont it wont work.
#7
11/07/2004 (1:57 am)
Man you just made my day! It's exactly what I needed.

Let me just point out that it's:
%word_one = getWord(%columnData, 0);
%word_two = getWord(%columnData, 1);

instead of:
%word_one = getWord(0, %columnData);
%word_two = getWord(1, %columnData);

Now if I could only prevent the user from typing spaces in the GuiTextEditCtrl.

Nick
#8
11/07/2004 (3:26 am)
I knew it was one way or the other..

So, You want to prevent them from typing spaces? Or you want them to type spaces?

Ahh, I think I know whatyou are talking about.

Say you have 2 columns and in column 1 you have "Hello All" and in column 2 you have "Holly Cow".

This the type of spacing you want to remove?
#9
11/07/2004 (4:49 am)
Hmm, using the same column setup as above lets see.

%fullText = %obj.getRowTextById(%id);
This would return the string "Hello All^Holy Cow"

Now this is not what we need, and what would be SOOO much better than the "getWord" call would be getField..

Example:

%word_one = getField(%obj.getRowTextById(%id), 0);

This will return the whole string in column 1.. This should be exactly what you need.

Sam
#10
11/07/2004 (12:23 pm)
Perfect! I had actually tried the getField function but must have not used it correctly.

This is for the Save/Load functionality for my single player game. The left column will hold the actual save name which will also be the name of the file, while the right column will be the time/date stamp. I didn't want the time/date stamp to be passed with the filename string.

Now the save/load functionality is almost done. I'm able to save and load any variable I need within the game. Used John Vanderbeck's SQLite resource along with some custom script/C++ functions to accomplish this.

Thanks for your help Sam.

Nick
#11
01/30/2006 (10:51 am)
I have a little problem with the GuiTextListCtrl as well. I created an onscreen (playgui) GuiTextListCtrl and what I want to do is show the player name with their current score. In the playgui.gui I have this :

new GuiTextListCtrl(RedPlayList) {
profile = "MedRedTextProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "0 0";
extent = "115 20";
minExtent = "8 2";
visible = "1";
enumerate = "0";
resizeCell = "1";
columns = "0 100";
fitParentWidth = "0";
clipColumnText = "0";
};

now when the score changes I do this

function changeScore(%clientId,%score)

%text = RedTeamList.getRowTextById(%clientId);
%text = setField(%text,1,%score);
RedTeamList.setRowById(%clientId, %text);

it always prints a 0 no matter the value for score.

I put in a echo right after %text = setField(%text,1,%score);
echo(%text);
and it prints to the console "Player ^2"; or what ever the score is. The display still shows Player 0

any clues?
#12
02/03/2006 (7:34 am)
Bump, No one have an answer for me? Do I need to use addField to initialize this?
#13
06/11/2006 (2:49 pm)
This post makes it sound like you can have more than 2 columns in the guittextlistctrl? Is this true, or are you still limited to the two columns?
#14
09/21/2006 (8:05 am)
I was wondering about this as well. I actually need 7 columns but am having trouble getting it working. I've tried 2 and it worked.

columns = "0 100 150 200 250 300 350 400 450";

[ edit ]

After further research and seeing that GuiTextListCtrl inherits from GuiControlArray, I knew it should be able to have multple columns.

So I went back to script and found the problem was that the GuiTextListCtrl kept auto-rezing to 80x16. Once I turned off autoresizing, I was able to see all of my columns (7 of them), so yes it can do more than 2 columns.
#15
05/02/2007 (10:47 am)
How did you actually turn off the autoresizing?