Rubeus
Member
|
GUI Object Callback Question
I think I might be missing something simple here-I've just started working with the GUI.
I have a checkbox on a gui object and working, and it calls a callback function when the checkbox is changed. What I need, though, is whether the checkbox is checked or not-IE: did the user check or uncheck it?
It seems to me that this should be standard for a callback function to have built in. I don't have to pass a reference of itself in as the ptr user data, do I? The header doesn't explain func() very well, I think. (That, and the many asterisks and parans are making my head spin @_@)
|
|
11-02-2013 12:18 AM |
|
Rofar
Member
|
RE: GUI Object Callback Question
Here is the way I do it. I pass a reference to the class that is going to handle the result of the action. In other words, the GUI class is passed as reference. In the GUI class I have a handler function ( such as void OnCheck() ). The callback function calls this handler which then can check the state of the checkbox to see if it is checked or unchecked.
Here is an example:
Code:
class SomeGui
{
public:
static void CheckBoxChanged(SomeGui& gui) { gui.OnCheck(); }
private:
void OnCheck();
}
I agree it seems like the checked state should be built in to the callback but that's not how it works.
|
|
11-02-2013 02:40 AM |
|
Esenthel
Administrator
|
RE: GUI Object Callback Question
static void Callback(CheckBox &cb) {if(cb())on;else off;}
|
|
11-02-2013 08:39 AM |
|
Rubeus
Member
|
RE: GUI Object Callback Question
void Callback( CheckBox &cb ){ }
myCheckbox.func( Callback, myCheckbox );
Using it like this works fine---unless you have your checkbox saved in a Memc container that changed your memory addresses immediately after setting up the callback.
Don't mind me; I'll just spend hours working out my own bonehead mistakes.
|
|
11-02-2013 03:22 PM |
|