Handling GuiListBoxCtrl?
by Sean Xie · in Torque 2D Beginner · 02/05/2014 (3:14 pm) · 4 replies
I am using a GuiListBoxCtrl object to list a few items on the screen. I wonder if there is some function linked to item selection in this GuiListBoxCtrl.
For example, I want to update some text when the item selected is changed. So, is there some function like onUpdate or onSelectionChange linked to the update of item selection?
Sorry if I am not being clear enough on stating the problem..
For example, I want to update some text when the item selected is changed. So, is there some function like onUpdate or onSelectionChange linked to the update of item selection?
Sorry if I am not being clear enough on stating the problem..
#2
I guess the way I was asking the question was quite ambiguous.
The problem is, I need to know when the selected item in the GuiListBoxCtrl is changed. For example, if I have 3 items in the list box and I choose one of them, I want some other guiControl (say, a line of text, or an image) to change. And when I choose another item, the text or image changes again.
02/05/2014 (7:21 pm)
Thank you for your reply.I guess the way I was asking the question was quite ambiguous.
The problem is, I need to know when the selected item in the GuiListBoxCtrl is changed. For example, if I have 3 items in the list box and I choose one of them, I want some other guiControl (say, a line of text, or an image) to change. And when I choose another item, the text or image changes again.
#3
02/06/2014 (7:11 am)
Text is easy - again, use the variable field. With the data source being the list box it's more complex because we have to somehow figure out which list box item is supplying the data. So we could create a field on the GuiListBoxCtrl object and update it in the GuiListBoxCtrl's onMouseDown() callback - using the getSelectedItems() method (note: this returns multiple items if more than one item is selected) and then taking the property you want and assigning it to the data field.// off the cuff....
function myGuiListBox::onMouseDown(%this)
{
// get item
%item = getWord(%this.getSelectedItems(), 0);
%this.customData = %item.text; // set the variable of the other control to point to this field
}
#4
Also I am sure that the profile of the object has modal set to true.
02/06/2014 (8:35 am)
Now it goes back to the other prboblem I have. The onMouseDown() callback is not called when I click the GuiListBoxCtrl object, even if I have the useMouseEvents field of the object set to true.Also I am sure that the profile of the object has modal set to true.
Torque Owner Richard Ranft
Roostertail Games
<GuiImageButtonCtrl canSaveDynamicFields="0" isContainer="0" Profile="GuiDefaultProfile" HorizSizing="right" VertSizing="bottom" Position="22 15" Extent="35 30" MinExtent="8 2" canSave="1" Visible="1" Active="1" tooltipWidth="250" hovertime="1000" groupNum="-1" buttonType="ToggleButton" NormalImage="ToyAssets:TD_Crystal_greesSprite" DownImage="ToyAssets:TD_Crystal_blueSprite" useMouseEvents="0" command="$EventValue++;" /> <GuiListBoxCtrl canSaveDynamicFields="0" isContainer="0" Profile="GuiDefaultProfile" HorizSizing="right" VertSizing="bottom" Position="75 15" Extent="35 30" MinExtent="8 2" canSave="1" Visible="1" Active="1" tooltipWidth="250" hovertime="1000" groupNum="-1" buttonType="ToggleButton" NormalImage="ToyAssets:TD_Crystal_greesSprite" DownImage="ToyAssets:TD_Crystal_blueSprite" useMouseEvents="0" variable=$EventValue />With the above controls, the button will increment the value of $EventValue and the text in the GuiListBoxCtrl will automatically update to reflect the value of $EventValue.