|
|
Home » Community » Newbie corner » text box action with enter key
text box action with enter key [message #25090] |
Wed, 10 February 2010 02:29  |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
After typing data into a text box how can an action be triggered when the enter key is pushed?
There are several examples in the tutorial and examples directories that work with data put into a text box but I could find none that worked directly with or triggered by the enter key.
A simple example would be two boxes. After text is entered into box 1 and then the enter key is pushed the data can be modified and then box2<<= modify(~box1);
Seems like this is often used and an example in the tutorial would be of benefit to those learning upp.
In Java it is done like this:
public void propertyChange(PropertyChangeEvent e) {
Object source = e.getSource();
if (source == point1Field) {
point1Action();
return;
}
}
edit: The Converter package in tutorial uses:
value <<= THISBACK(ValueChanged);
but that picks up a change for each character and not just when all characters have been typed in and then the enter key pushed.
The characters could be checked for (13,10) OD,OA "\n" but it seems like something easier than this may have been implemented in upp if there are several text boxes. Especially when a string that ends with "\0" or "\n" is pasted into a box and action is not wanted until the enter key is pushed.
[Updated on: Wed, 10 February 2010 04:29] Report message to a moderator
|
|
|
|
Re: text box action with enter key [message #25092 is a reply to message #25091] |
Wed, 10 February 2010 05:49   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Thanks Aris. I am new to C++ GUI and upp.
I am lost on how to use the code you posted.
For a simple app re text only when enter key pushed (K_ENTER ?).
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
GUI_APP_MAIN
{
TopWindow app;
app.SetRect(0, 0, 200, 60);
EditField box1, box2;
app.Add(box1.TopPosZ(0, 20).HSizePos());
app.Add(box2.TopPosZ(20, 20).HSizePos());
box2<<= ~box1;
// box2<<= conv(~box1, units, decpl);
app.Run();
}
Having the data typed into box1 go to box2 only when K_ENTER.
My upp Gui works good and converts angles decimal degrees to deg min sec, converts distance meters, km, feet, miles nautical miles, etc.
Calculate the geodesic distance with the Vincenty Formula/s. There are some situations where data typed in like miles it should be acted on by K_ENTER rather than and before a calculation function is called.
[Updated on: Wed, 10 February 2010 05:53] Report message to a moderator
|
|
|
Re: text box action with enter key [message #25100 is a reply to message #25092] |
Wed, 10 February 2010 13:07   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class LaunchField : public EditField
{
public:
virtual bool Key(dword key, int count);
Callback WhenEnter;
typedef LaunchField CLASSNAME;
LaunchField() {}
~LaunchField() {}
};
bool LaunchField::Key(dword key, int count)
{
if(key == K_ENTER) {
WhenEnter();
return true;
}
return EditField::Key(key, count);
}
//==============================================
class MyApp : public TopWindow {
public:
LaunchField box1, box2;
void OnEnter1();
typedef MyApp CLASSNAME;
MyApp();
~MyApp() {}
};
MyApp::MyApp()
{
box1.WhenEnter = THISBACK(OnEnter1);
Add(box1.TopPosZ(0, 20).HSizePos());
Add(box2.TopPosZ(20, 20).HSizePos());
SetRect(0, 0, 200, 60); //if you really need
Zoomable().Sizeable().Title("CallbackField Demo");
}
void MyApp::OnEnter1()
{
box2<<= ~box1;
PromptOK("you can launch a rocket from here! but better replace me with your code!");
}
//==============================================
GUI_APP_MAIN
{
MyApp app;
app.Run();
}
I hope to hear something from you... like ... more questions!
Aris
[Updated on: Wed, 10 February 2010 13:10] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: text box action with enter key [message #25128 is a reply to message #25125] |
Thu, 11 February 2010 22:32   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Thanks Mirek, that was fast.
I have 1952, I will find out how to load the updater module for the /live_update.
I appreciate your example code that is similar to Java.
void MyDialogWindow::Key(dword code, int)
{
if(point1Field.HasFocus()) {
point1Action();
return;
}
}
Since I have used this in Java this may be the way to port that to U++.
[Updated on: Sat, 13 February 2010 12:30] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 08:41:42 CEST 2025
Total time taken to generate the page: 0.03485 seconds
|
|
|