3.6 Event handling

RapaGUI events are handled in the very same way as normal Hollywood events. This means that you just have to pass a callback function to Hollywood's InstallEventHandler() function and whenever a RapaGUI event is triggered, your callback function will be called.

Here is an example how to install a RapaGUI event callback:

 
InstallEventHandler({RapaGUI = p_EventHandler})

Whenever an event occurs, RapaGUI will then call p_EventHandler() with a table as parameter. The table will have the following fields initialized:

Action:
Initialized to "RapaGUI".

Class:
Contains the name of the MOAI class this event comes from, e.g. "Choice".

Attribute:
Contains the name of the class attribute that has triggered the event, e.g. "Active".

ID:
Contains the ID of the MOAI object that triggered this event, e.g. "mychoice".

TriggerValue:
Contains the current value of the attribute that triggered this event. You could also find this out by doing a moai.Get() on the object but it is more convenient to get the current value directly to your event callback.

MOAIUserData:
If the object was assigned certain userdata, it will be passed to the event handler callback in this tag. See MOAI.UserData for details.

NotifyData:
If the object was assigned certain notify data, it will be passed to the event handler callback in this tag. See MOAI.NotifyData for details.

On top of that it is also necessary to tell RapaGUI which events you would like to receive. Only events you explicitly request to receive are passed to your event callback to minimize overhead. An exception are button, toolbar button and menu item events. They are passed to your event callback even if you haven't requested them. The reason for this design choice is that normally all of these events need to be individually handled because the user expects something to happen when pressing a button.

All RapaGUI events are coupled to attributes of MOAI objects. The next section describes this in detail.


Show TOC