Game Development Community

Setting GUI Focus

by Necrode · in Torque 3D Professional · 11/10/2009 (12:39 am) · 5 replies

Does anyone know how to set focus on a particular gui element? I have a GuiTextEditCtrl that allows a user to type a message. Upon pressing enter the text input loses focus for some reason, and needs to be clicked on to accept input again.
I tried MyTextInput.makeFirstResponder(true); but that only works to set the focus on the text input when I first push the Gui on screen.
Thanks

About the author

They locked me in here with a computer, and said I don't get to leave until I've completed a computer game.


#1
11/10/2009 (12:50 pm)
i would suggest tracking down why the control loses focus when the user presses enter. that's not the default behaviour, so something must be causing it.
#2
11/10/2009 (1:11 pm)
GuiTextEditCtrl::dealWithEnter() will actually clear first-responder status and thus cause the focus to be lost.

makeFirstResponder(true) should absolutely work fine. Tested it and it worked without problems.

Where are you calling makeFirstResponder from? From the altCommand? If so, you're being overridden directly afterwards because the clearing in GuiTextEditCtrl::dealWithEnter only takes place *after* executing the command.

One way out would probably be to do a

$ThisControl.schedule( 1, "makeFirstResponder", true );

in the altCommand.
#3
11/10/2009 (4:07 pm)
heh, grampa's showing his age.. they didn't have dealWithEnter() back in TGE !
thanks for correcting me.
#4
11/10/2009 (4:16 pm)

Hehe, youngster showing his lack of age here... didn't know it was different in TGE :)

(And my point certainly wasn't to correct you, Orion)
#5
11/10/2009 (8:07 pm)
I've been using AltCommand, I added in the schedule and it worked! Thanks for the tip!