|
|
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » What Label.WhenAction supposed to do? - nothing [PARTLY SOLVED :)]
What Label.WhenAction supposed to do? - nothing [PARTLY SOLVED :)] [message #1804] |
Mon, 20 March 2006 08:01 |
|
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
What Label.WhenAction supposed to do?
And why this works for button but not for label?
#include <CtrlLib/CtrlLib.h>
void testAction()
{ PromptOK("testLabelAction");
}
GUI_APP_MAIN
{
TopWindow w;
Button b;
Label l;
w.Add(b);
b.SetLabel("button - testAction");
b.SetPos(b.PosLeft(10, 100), b.PosTop(10, 30));
// b.WhenPush=callback(testAction); //both work
b.WhenAction=callback(testAction);
w.Add(l);
l.SetLabel("label - testAction");
l.SetPos(l.PosLeft(150, 100), l.PosTop(10, 30));
l.WhenAction=callback(testAction);
w.Run();
}
[Updated on: Sun, 09 April 2006 03:41] Report message to a moderator
|
|
|
|
Re: What Label.WhenAction supposed to do? [message #1841 is a reply to message #1804] |
Wed, 22 March 2006 17:24 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
the code you have posted was very important for me. I'am new of C++ and Ultimate++, but I've some experience with GUI using C API (Motif for example under Unix). Your code reminded me more or less what I've usually done in C style without to declare any class. Just each widget is child of someother and there are callback attached to them. I understand that the class method is elegant and powerful, but I'm a lazy man, , and I do not want to loose time with C++ and its intricasy (at least not now). So your approach for me was a surprise and showed that, perhaps, I can program in a sort of C style.
I would like to know, before to start to port one my program in U++ (the wich GUI is in C), if the approach you have showed could break at some moment, for example in complex interface. In other term, is it mandatory to implement class/es to let a GUI interface to work, or can I live without them in Ultimate++?
In case I can avoid the class I would like to see your code, or a similar one, in the documentation to let know to the beginner how it is easy to program with Ultimate++ in contrast with other GUI toolkits.
Luigi
fudadmin wrote on Mon, 20 March 2006 02:01 |
#include <CtrlLib/CtrlLib.h>
void testAction()
{ PromptOK("testLabelAction");
}
GUI_APP_MAIN
{
TopWindow w;
Button b;
Label l;
w.Add(b);
b.SetLabel("button - testAction");
b.SetPos(b.PosLeft(10, 100), b.PosTop(10, 30));
// b.WhenPush=callback(testAction); //both work
b.WhenAction=callback(testAction);
w.Add(l);
l.SetLabel("label - testAction");
l.SetPos(l.PosLeft(150, 100), l.PosTop(10, 30));
l.WhenAction=callback(testAction);
w.Run();
}
|
|
|
|
|
|
Re: What Label.WhenAction supposed to do? [message #1860 is a reply to message #1845] |
Fri, 24 March 2006 00:05 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
fudadmin wrote on Wed, 22 March 2006 13:47 |
Luigi, as an old C programmer I can tell you that you will lose more time with C programming style... . I used this style in my example just for clarity and to have less lines...
And to make a shift from C to C++ you don't need to much time unless you spend time following tutorials which are written with a purpose to make money...
My guess is that your laziness simply hides fear of unknown...
My advice - do it in a lazy man's way - learn from code samples, try to make programs and do not hesitate asking questions here!
|
Thank you for your advice. I'll try to fill the gap. I know the principle of C++ and I've even written some thing many years ago. But when now I approached again the C++ to use it in GUI development I see it is a mess.
Please let me ask you what is the word THISBACK that appear in the code and in assist menu'. For example in the reference assembly the package 'menu':
#include <CtrlLib/CtrlLib.h>
struct App : public TopWindow {
bool numbers_enabled;
void Exit()
{
Close();
}
void EnableNumbers()
{
numbers_enabled = !numbers_enabled;
}
void ShowNumber(int n)
{
PromptOK(AsString(n));
}
void SubMenu(Bar& bar)
{
for(int i = 0; i < 10; i++)
bar.Add(AsString(i), t_(THISBACK1)(ShowNumber, i));
}
void Menu(Bar& bar)
{
bar.Add("Enable numbers", THISBACK(EnableNumbers))
.Check(numbers_enabled);
bar.Add(numbers_enabled, "Numbers", THISBACK(SubMenu));
bar.Add("Exit", THISBACK(Exit))
.Key(K_CTRL_E);
}
void MainBar(Bar& bar)
{
bar.Add("Menu", THISBACK(Menu));
}
MenuBar menu;
typedef App CLASSNAME;
App()
{
numbers_enabled = false;
AddFrame(menu);
menu.Set(THISBACK(MainBar));
}
};
GUI_APP_MAIN
{
App().Run();
}
has some error somewhere because the compiler report:
C:\upp\reference\Menu\menu.cpp: In member function `void App::SubMenu(Bar&)':
C:\upp\reference\Menu\menu.cpp:24: error: `THISBACK1' undeclared (first use this function)
The THISBACK in assist sometime show the list of callback while sometime show nothing. Can you say two words about its purpose and how to use?
Many thanks in advance,
Luigi
|
|
|
|
|
|
|
Goto Forum:
Current Time: Sat May 04 08:58:34 CEST 2024
Total time taken to generate the page: 0.01685 seconds
|
|
|