inputfieldsandbuttons.C
shows an example of specifying what action to take in response when
a button gets activated by a pointer click or a key press, using
on_activate
().
on_activate
()'s parameter is a lambda that
gets executed when the button gets activated.
Note that the lambda gets invoked by the execution thread, see
the section called “Callbacks” and
the section called “Containers own references to the widgets in the container” for more information.
The lambda receives the following parameters.
A connection thread handle.
x::w::callback_trigger_t
provides additional information about why exactly the callback
got invoked, by a button or a key press. It's possible to use this
information to take different actions.
The
x::w::busy
factory parameter
provides the option of suspending keyboard and pointer button
processing after the callback returns. Normally LibCXXW's
internal execution thread resumes processing keyboard and button
clicks after this callback returns. Callbacks should not engage
in lengthy tasks, because they get executed by the library's
internal execution thread whose job is to update the display.
Callbacks are not executed by the main application thread.
A typical design pattern for this kind of a callback is to send
a message to the main application thread, which then starts
working.
It is desirable not to process any further pointer or keyboard clicks until the main application thread is finished, and the busy factory provides the means to do so. The callback uses this factory to construct a “mcguffin” for that purpose. An example of this is given in Chapter 12, Disabling input processing.