Home » U++ Library support » U++ Widgets - General questions or Mixed problems » What is best way to obtain button info via callback?
What is best way to obtain button info via callback? [message #13586] |
Tue, 15 January 2008 19:51 |
jlfranks
Messages: 57 Registered: May 2007 Location: Houston, TX, USA
|
Member |
|
|
The problem that I'm trying to solve is to have one callback handler for buttons with layout like Qwerty keyboard (we only have
a touch panel and need a keyboard device).
The alphabetic buttons can be upper or lower case, depending on
the case toggle button. I would sure be nice to service over 50
buttons (keys on keyboard) with one callback routine.
The problem is that Button only takes THISBACK and not THISBACK1, so there's no way of sending an argument identifying the key that is pressed.
Also, there is a way to set the label on the button, but not a way to get the lable. Handler could have simply used this, if it knew which key to access.
Is simple way of writing this (sure don't like writing 50 callbacks that all do just about the same thing) ?
--jlf
|
|
|
|
Re: What is best way to obtain button info via callback? [message #36714 is a reply to message #13586] |
Thu, 28 June 2012 16:14 |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
Thanks for opening my eyes for this!
We can use one callback to handle all buttons and this keeps the code much more organized:
enum {btn1, btn2};
void MainWin::SetEditOutput(int n)
{
switch (n) {
case btn1:
output <<= "You clicked button 1";
break;
case btn2:
output <<= "You clicked button 2";
break;
}
}
MainWin::MainWin()
{
CtrlLayout(*this, "Window title");
button1.WhenPush = THISBACK1(SetEditOutput, btn1);
button2.WhenPush = THISBACK1(SetEditOutput, btn2);
}
|
|
|
Goto Forum:
Current Time: Sat Sep 21 06:09:58 CEST 2024
Total time taken to generate the page: 0.05098 seconds
|