About events

Events is what NWG uses to respond to user events. Event callbacks are bound and unbound to controls through the Ui.

The EventCallback enum describe the callback arguments. All callback arguments are guaranteed to start with |ui, caller|. Where ui is the Ui that owns the control and caller is the ID of control the triggered the event.

For a list of all built-in events see 6. List of events .

Binding events

To bind an event to a control the bind(ID, cb_ID, callback) -> Result<(), Error> method must be used. Unlike with actions, trying to bind an event that is not supported by a control will return an Error.

Arguments
Behaviour
Failure
Example
ui.bind("HelloBtn", "SayHello", EventCallback::Click(Box::new(|ui, caller|{
    println!("Caller is: {:?}", caller);
}))).unwrap();

Unbinding events

To unbind an event to a control the unbind(ID, cb_ID, event) -> Result<(), Error> method must be used.

Arguments
Failure
Example
ui.unbind("HelloBtn", "SayHello", Event::Click).unwrap();

Listening for events

Once your setup is completed, the nwg::dispatch_events() function must be called in order to block the thread and process the system events. The function will return once a Quit (WM_QUIT) event is received.

Behaviour
Example
nwg::dispatch_events();