About Store Forum Documentation Contact
Donations:
392$/mo



Post Reply 
GUI Object Callback Question
Author Message
Rubeus Offline
Member

Post: #1
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
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #2
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
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: GUI Object Callback Question
static void Callback(CheckBox &cb) {if(cb())on;else off;}
11-02-2013 08:39 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #4
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
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: GUI Object Callback Question
Please use Memx for const_mem_addr objects grin
11-02-2013 10:11 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: GUI Object Callback Question
Next Code Editor release will warn you if you're trying to put const_mem_addr objects into Memc/Mems/Memt/Memb smile
11-07-2013 11:18 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #7
RE: GUI Object Callback Question
Awesome! That will be helpful for dopes like me! smile
11-08-2013 04:30 AM
Find all posts by this user Quote this message in a reply
Post Reply