GuiTextEditCtrl ... how to I take away its focus?
by Nmuta Jones · in Torque Game Engine · 02/28/2010 (10:43 pm) · 13 replies
I've been searching for over an hour for the answer to this question.
I have this in my playGui.gui:
The problem is that when the game starts, the GuiTextEditCtrl has the focus.... and won't give it up. So I can't move the player.
How do I get this box to lose its focus, and where do I call such a command from? client side? and when?
I have this in my playGui.gui:
new GuiTextEditCtrl(myinput) {
canSaveDynamicFields = "0";
Profile = "GuiTextEditProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "24 95";
Extent = "64 18";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
maxLength = "1024";
historySize = "0";
password = "0";
tabComplete = "0";
sinkAllKeyEvents = "0";
password = "0";
passwordMask = "*";
};The problem is that when the game starts, the GuiTextEditCtrl has the focus.... and won't give it up. So I can't move the player.
How do I get this box to lose its focus, and where do I call such a command from? client side? and when?
About the author
Lead Developer for MediaBreeze Multimedia
#2
02/28/2010 (11:33 pm)
I did a dump on the GuiTextEditCtrl and I got all of this, but not a single one appears to deal with focus:==>mathinput.dump(); Member Fields: Accelerator = "" AltCommand = "" canSave = "1" canSaveDynamicFields = "0" class = "" Command = "" deniedSound = "" escapeCommand = "" Extent = "64 18" historySize = "0" HorizSizing = "right" hovertime = "1000" langTableMod = "" maxLength = "1024" MinExtent = "8 2" password = "0" password = "0" passwordMask = "*" position = "24 95" Profile = "GuiTextEditProfile" sinkAllKeyEvents = "0" superclass = "" tabComplete = "0" text = "" textID = "" ToolTip = "" tooltipprofile = "" validate = "" Variable = "" VertSizing = "bottom" Visible = "1" Tagged Fields: Methods: add() - set.add(obj1,...) addGuiControl() - S32 controlId bringToFront() - set.bringToFront(object) clear() - set.clear() delete() - obj.delete() dump() - obj.dump() dumpClassHierarchy() - obj.dumpClassHierarchy() findObjectByInternalName() - string InternalName forceValidateText() - textEditCtrl.forceValidateText() getCenter() - returns center of control, as space seperated ints getClassName() - obj.getClassName() getCount() - set.getCount() getCursorPos() - textEditCtrl.getCursorPos() getDynamicField() - obj.getDynamicField(index) getDynamicFieldCount() - obj.getDynamicFieldCount() getExtent() - Get the width and height of the control. getFieldValue() - obj.getFieldValue(fieldName); getGlobalCenter() - returns center of control, as space seperated ints getGlobalPosition() - getGroup() - obj.getGroup() getHelpPage() - getId() - obj.getId() getInternalName() - getInternalName returns the objects internal name getMinExtent() - Get the minimum allowed size of the control. getName() - obj.getName() getObject() - set.getObject(objIndex) getParent() - returns the Id of the parent control getPosition() - getText() - textEditCtrl.getText() getType() - obj.getType() getValue() - isActive() - isAwake() - isChildOfGroup() - returns true, if we are in the specified simgroup - or a subgroup thereof isMember() - set.isMember(object) isMemberOfClass() - isMemberOfClass(string classname) -- returns true if this object is a member of the specified class isMethod() - obj.isMethod(string method name) isVisible() - listObjects() - set.listObjects(); makeFirstResponder() - (bool isFirst) pointInControl() - returns true if the point is in the control, point is in parent coords pushToBack() - set.pushToBack(object) remove() - set.remove(obj1,...) reorder() - set.reorder(obj1, obj2) reorderChild() - (child1, child2) uses simset reorder to push child 1 after child 2 - both must already be child controls of this control resize() - (int x, int y, int w, int h) save() - obj.save(fileName, <selectedOnly>) schedule() - object.schedule(time, command, <arg1...argN>); selectAllText() - textEditCtrl.selectAllText() setActive() - (bool active) setCanSave() - Sets whether this control can serialize itself to the hard disk setCenter() - sets control position, by center - coords are local not global setCursorPos() - textEditCtrl.setCursorPos( newPos ) setExtent() - sets the width & height of the control. setFieldValue() - obj.setFieldValue(fieldName,value); setFirstResponder() - Sets this control as the first responder setInternalName() - string InternalName setName() - obj.setName(newName) setPosition() - int x,y in local space setPositionGlobal() - int x,y in global screen space setProfile() - (GuiControlProfile p) setText() - obj.setText( newText ) setTextID() - obj.setTextID( newText ) setValue() - (string value) setVisible() - (bool visible)
#3
setFirstResponder is what you are looking for, e.g.
02/28/2010 (11:50 pm)
setFirstResponder is what you are looking for, e.g.
// Give focus back to PlayGui after text edit stole it: PlayGui.setFirstResponder();
#4
//--- OBJECT WRITE END ---
PlayGui.setFirstResponder();
Also, when I type it into the console, PlayGui.setFirstResponder() does not regain my focus either.
How do I go back and forth between the two , anyway, since the focus has to go back and forth between the two?
My text Ctrl is located INSIDE of PlayGui, by the way. should it be in a different gui file, to enable toggling? I'm lost on this one.
03/01/2010 (12:02 am)
I tried that. It's not working for me. At the end of my PlayGui.gui file, after OBJECT WRITE END//--- OBJECT WRITE END ---
PlayGui.setFirstResponder();
Also, when I type it into the console, PlayGui.setFirstResponder() does not regain my focus either.
How do I go back and forth between the two , anyway, since the focus has to go back and forth between the two?
My text Ctrl is located INSIDE of PlayGui, by the way. should it be in a different gui file, to enable toggling? I'm lost on this one.
#5
So, to solve this you either need to prevent your text edit control to grab focus in the first place (it won't grab it by default) or refocus to a different control after the text edit control grabbed the focus.
03/01/2010 (12:13 am)
Both approaches you tried won't work. Focus is a very dynamic thing so it must be set at the right time. During GUI operation, many controls will claim first responder status.So, to solve this you either need to prevent your text edit control to grab focus in the first place (it won't grab it by default) or refocus to a different control after the text edit control grabbed the focus.
#6
Then why is my GuiTextEditCtrl grabbing the focus to begin with ?
And then also, "when" is the best time to tell Torque to focus to a different control? If I can't do it in the console, then how will it work anywhere else? I'm totally confused.
03/01/2010 (12:19 am)
You say that Quote:
(it won't grab it by default)
Then why is my GuiTextEditCtrl grabbing the focus to begin with ?
And then also, "when" is the best time to tell Torque to focus to a different control? If I can't do it in the console, then how will it work anywhere else? I'm totally confused.
#7
03/01/2010 (12:27 am)
see below
#8
Probably because your text edit control is tabbable (not a real word, but looks nice).
When a control's profile has both canKeyFocus=true and tab=true, the control will grab focus in its onWake method.
So, one way you can solve this is by using a profile derived from GuiTextEditProfile with tab=false.
Other than that, I'm just noticing a mistake of mine. You can't usually give focus to PlayGui since by default it does not have a profile with canKeyFocus=true.
Instead, what you want to to is something like
to make the edit ctrl yield focus.
03/01/2010 (12:33 am)
Quote:Then why is my GuiTextEditCtrl grabbing the focus to begin with ?
Probably because your text edit control is tabbable (not a real word, but looks nice).
When a control's profile has both canKeyFocus=true and tab=true, the control will grab focus in its onWake method.
So, one way you can solve this is by using a profile derived from GuiTextEditProfile with tab=false.
Other than that, I'm just noticing a mistake of mine. You can't usually give focus to PlayGui since by default it does not have a profile with canKeyFocus=true.
Instead, what you want to to is something like
myinput.makeFirstResponder( false );
to make the edit ctrl yield focus.
#9
Thank you so much for helping me troubleshoot this.
Unfortunately, mathinput.setFirstResponder(false);
Does not work either.
I even tried making a button, and on that button putting
PlayGui.setFirstResponder();
as the command,
and it still will NOT give up the focus on that GuiTextEditCtrl.
The only thing that has worked for me so far is making a button that DELETES the text box totally after retrieving its input. The damn GuiTextEditCtrl is simply possessed. I have to kill it after I use it to get this thing to work.
03/01/2010 (12:42 am)
@Rene :Thank you so much for helping me troubleshoot this.
Unfortunately, mathinput.setFirstResponder(false);
Does not work either.
I even tried making a button, and on that button putting
PlayGui.setFirstResponder();
as the command,
and it still will NOT give up the focus on that GuiTextEditCtrl.
The only thing that has worked for me so far is making a button that DELETES the text box totally after retrieving its input. The damn GuiTextEditCtrl is simply possessed. I have to kill it after I use it to get this thing to work.
#10
It's makeFirstResponder(false) not setFirstResponder(false) :)
Alternatively, use a non-tabbable profile.
PlayGui can't become first responder with a profile that has canKeyFocus=false as described above. Wasn't thinking of this initially.
03/01/2010 (12:46 am)
It's makeFirstResponder(false) not setFirstResponder(false) :)
Alternatively, use a non-tabbable profile.
PlayGui can't become first responder with a profile that has canKeyFocus=false as described above. Wasn't thinking of this initially.
#11
I am almost confident in saying that it simply does not work. I think GuiTextEditCtrl was not made to relinquish focus. period.
Here is my workaround:(this works:)
1. I made the GuiTextEditCtrl and a button to remove it. I put them both in a gui file called dynamicstuff.gui. The button calls a function called respondtouser. This value is placed in the "command" field of the button.
2. exec dynamicstuff.gui from your init.cs or wherever, client side.
3. make a trigger that essentially does: PlayGui.addGuiControl(your_custom_GuiTextEditCtrl _handle);
PlayGui.addGuiControl(your_custom_Button_handle);
4. in your respondtouser file, do
(first get the contents of the box before it goes away):
%caughtvariable = your_custom_GuiTextEditCtrl _handle.getText();
PlayGui.remove(your_custom_GuiTextEditCtrl _handle);
PlayGui.remove(your_custom_Button_handle);
(Note that "remove" is different from "delete". Remove just takes the dynamic text boxes, etc. OUT of the PlayGui.... delete destroys them all together).
And voila. You get text boxes that appear when you need them, and disappear when you don't, allow you to get focus when you need it.
If anyone can find a way to toggle back between focus and non focus of GuiTextEditCtrl , chime in. I've tried everything I could think of, and I have not seen one instance of anyone on these forums succeeding. At least nobody who did it has shared their trick ;)
03/01/2010 (2:14 am)
That did not work either. I am almost confident in saying that it simply does not work. I think GuiTextEditCtrl was not made to relinquish focus. period.
Here is my workaround:(this works:)
1. I made the GuiTextEditCtrl and a button to remove it. I put them both in a gui file called dynamicstuff.gui. The button calls a function called respondtouser. This value is placed in the "command" field of the button.
2. exec dynamicstuff.gui from your init.cs or wherever, client side.
3. make a trigger that essentially does: PlayGui.addGuiControl(your_custom_GuiTextEditCtrl _handle);
PlayGui.addGuiControl(your_custom_Button_handle);
4. in your respondtouser file, do
(first get the contents of the box before it goes away):
%caughtvariable = your_custom_GuiTextEditCtrl _handle.getText();
PlayGui.remove(your_custom_GuiTextEditCtrl _handle);
PlayGui.remove(your_custom_Button_handle);
(Note that "remove" is different from "delete". Remove just takes the dynamic text boxes, etc. OUT of the PlayGui.... delete destroys them all together).
And voila. You get text boxes that appear when you need them, and disappear when you don't, allow you to get focus when you need it.
If anyone can find a way to toggle back between focus and non focus of GuiTextEditCtrl , chime in. I've tried everything I could think of, and I have not seen one instance of anyone on these forums succeeding. At least nobody who did it has shared their trick ;)
#12
Putting a GuiTextEditCtrl on PlayGui and calling makeFirstResponder(false) on it here works just fine with T3D as well as with ye good ol' TGE 1.5.
03/01/2010 (2:25 am)
Well, seems like you're mixing something up there.Putting a GuiTextEditCtrl on PlayGui and calling makeFirstResponder(false) on it here works just fine with T3D as well as with ye good ol' TGE 1.5.
#13
03/01/2010 (2:28 am)
Hm. well I am using AFX for 1.5.2 and it does not work , so I'm using the workaround. Hopefully anyone reading this thread in the future can use either one of our methods and find success.
Torque Owner Nmuta Jones