|
|
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » How to use callbacks with "embedded" controls...
How to use callbacks with "embedded" controls... [message #2523] |
Sun, 16 April 2006 18:54 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Quote: |
Waiting for your next task
Aris
|
Here I am,
I think I need other few things to understand before I can proceede alone (well... almost alone). One is the following (perhaps the title of the thread is not correct).
We have a marvellous threestate OptionImage of which all the world is envious. I've attached to it a callback (it costed me one hour of useless temptives before to found the exact syntax... from other side very obvious at the end)
void Avail3(One<Ctrl>& ctrl)
{ ctrl.Create<OptionImage>().ThreeState().SetImage(imgYes(), imgNo(), imgMaybe()).WhenAction=callback(Avail3Action);
}
where the callback is
void Avail3Action()
{ int int_row;
String s ;
PromptOK("ImageButton action");
}
What I desire is that this callback can recognize the state of the ImageButton that has activated it. So that it can prompt the state of the pressed ImageButton to inform the user about what he did (it is a very delicate operation).
Unfortunately this callback is not a method of the class so it has no access to the ArrayCtrl. Otherwise I could easily look in the cell and retrieve the state of the pressed button.
I'm sure there is way to pass as argument of Avail3Action() just the pressed button. It should be already available in some form in Avail3() so that it can be passed even to Avail3Action. Unfortunately I'm lost with the syntax like One<Ctrl>& ctrl.
I've even tried to let be the previous callback two new methods of the class to have access to all the instances, but the compiler cried in corrispondence of the argument One<Ctrl>& ctrl passed to the metod Avail3().
Have you any hint?
Thank you,
Luigi
Edit: The title was changed...
[Updated on: Mon, 17 April 2006 02:23] by Moderator Report message to a moderator
|
|
|
Re: How to use callbacks with "embedded" controls... [message #2535 is a reply to message #2523] |
Mon, 17 April 2006 02:54 |
|
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
First of all, don't create too long code "sausages", esp. in the wrong places...
Second, don't spend your hours in the wrong bushes by creating a bicycle. That means, always check if your parents have those wheels...
I'm not very sure but I guess:
Step1.
void VegaMain::Init()
{
info="Ready";
tab1.arr.WhenEnterRow = THISBACK(UpdateInfo);
tab1.arr.WhenCtrlsAction = THISBACK(UpdateInfo);
}
Step2. in VegaStatus.cpp add this:
void VegaMain::UpdateInfo()
{
info = "Wait..Counting...Busy...";
int nTotal = tab1.arr.GetCount();
int nAvail = tab1.GetAvail(); //might optimize later...
info = NFormat("Ready: Total players: %d - Available: %d", nTotal, nAvail);
}
Step3
update VegaMain.h
Step4
and also in the same VegaMain.h
class VegaTab1 : public WithVegaTab1Layout<TopWindow> {
public:
void SortRecord(int column);
void AddPlayer();
// void ShowNumberRecord(); you don't need it here...
int GetAvail(); //new!!!
Step5
in VegaTab1.cpp
int VegaTab1::GetAvail()
{
int n=0;
for(int i=0; i<arr.GetCount(); i++) {
if ( arr.Get(i, "Avail") ) n=n+1;
}
return n;
}
Step5
remove your 1 hour wasted time and spoiled callback from Avail3
Step6
make "info" label in the layout at least double width.
Step7
Ctrl_F5.
You can apply this logic with Prompts if you like...
Step8
Report any success or failure...
[Updated on: Mon, 17 April 2006 03:19] Report message to a moderator
|
|
|
|
|
Re: How to use callbacks with "embedded" controls... [message #2543 is a reply to message #2542] |
Mon, 17 April 2006 10:19 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
fudadmin wrote on Mon, 17 April 2006 10:03 | If something is empty, it means it's empty! I do not question such things. Just accept as they are .
P.S in fact, I think, you can study nuller classes etc. if you wish...
|
Yesterday I've upgraded the U++ and only now I've seen that the documentation is increased. In particular about three state I have just read
Quote: |
Widget providing the selection of 2 or alternatively 3 states (true, false, Null). Value of Option is either 0, 1, or Null. When setting Value to Option, string "1" is interpreted as true state, other non-Null strings as false.
|
I accept it without complain.
|
|
|
|
Re: How to use callbacks with "embedded" controls... [message #2545 is a reply to message #2535] |
Mon, 17 April 2006 11:19 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
fudadmin wrote on Mon, 17 April 2006 02:54 |
Report any success or failure...
|
I'm very sorry to remain again on the same argument, but I'm obeserving a strange behaviour and before to say it is a bug it is better to verify.
It regards the OptionImage inside the array. When I click in each cell of the array except the OptionImage the cursor of the array move on the clicked row. This is OK because I can read the selected row and retrieve its data. Instead when I click on the OptionImage the cursor doesn't change and remains where it was. This is not good because my code cannot intercept the clicked row and in turn the clicked optionimage button.
Is it normal? It seems that the button has overrided the property of that column as it where not in an array.
Is there an alternative way to listen the optionimage button? (if not let's neglect it).
This is the code that prompt the status of the clicked button.
int VegaTab1::GetAvail()
{ int n;
String s, player, s1;
// n = arr.GetCursor(); // doesn't change, so I try the next line
n = arr.GetClickRow(); // nothing
// arr.SetCursor( n);
s=AsString( arr.Get(n, "Avail") );
player = arr.Get(n, "Name");
if (s=="1") PromptOK("You have made available player " + player);
else if (s=="0") PromptOK("You have made NOT available player " + player);
else PromptOK("You have assigned a BYE to player " + player);
n = 0;
for(int i=0; i<arr.GetCount(); i++) {
if ( arr.Get(i, "Avail") ) n=n+1;
//s1 += AsString( arr.Get(i, "Avail") ) + " ";
}
// PromptOK( s1 );
return n;
}
|
|
|
|
|
|
|
Re: How to use callbacks with "embedded" controls... [message #2636 is a reply to message #2613] |
Wed, 19 April 2006 16:44 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
fudadmin wrote on Wed, 19 April 2006 06:26 | Ok, I think, this should help: [snip]
|
Aris,
I tried the code and it works nicely, but... there is a little drawback.
If you remind I wanted to intercept the clicked embedded OptionImage to get its status and prompt the user with a message (and write in the infoctrl too). Now I can do it because, thanks to you, the focus go on the row in which the button is. This is the code that shows its status:
int VegaTab1::GetAvail()
{ int n = 0;
String s, player, s1;
for(int i=0; i<arr.GetCount(); i++) {
if ( arr.Get(i, "Avail") ) n=n+1;
}
//try this here. Later we'll rearrange...
arr.ChildGotFocus(); //lets move the focus after calculations...
//do you tests below...
n = arr.GetCursor();
s=AsString( arr.Get(n, "Avail") );
PromptOK( s );
return n;
}
Now, when I click the optionimage, the PromptOK( s ) appear TWO times, instead of one, and it is annoying. This is due both do the click and the refocus connected connected to WhenCtrlsAction :
void VegaMain::Init()
{ info1="Ready";
tab1.arr.WhenEnterRow = THISBACK(UpdateInfo);
tab1.arr.WhenCtrlsAction = THISBACK(UpdateInfo);
}
that call GetAvail:
void VegaMain::UpdateInfo()
{ int int_row, nTotal, nAvail;
nTotal = tab1.arr.GetCount();
nAvail = tab1.GetAvail();
info1 = NFormat("Total players: %d - Available: %d", nTotal, nAvail);
}
I've noticed that if you comment
// tab1.arr.WhenCtrlsAction = THISBACK(UpdateInfo);
then the consecutive click on the option image will not produce a PromptOK dialog.
So now I'm a bit confused on the place where I have to put the hands to correct this behaviour.
I hope to have been clear.
Luigi
|
|
|
|
|
|
|
Re: How to use callbacks with "embedded" controls... [message #2652 is a reply to message #2649] |
Thu, 20 April 2006 05:02 |
|
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
Yes, you can read a few more chapters. Also, it's useful writing some notes when you find anything new. One more tip - read everything with an approach that later you will need to explain or teach someone else efficiently. If you have enthusiasm you could write one more chapter of Ultimate's tutorial.
P.S. I'll write more and present you with once more "refurbished" Vega very soon...
[Updated on: Thu, 20 April 2006 05:03] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat May 04 14:04:25 CEST 2024
Total time taken to generate the page: 0.02526 seconds
|
|
|