User`s guide

WriteCodeforCallbacks
Write Code for Callbacks
In this section...
“What Is a Callback?” on page 12-7
“Kinds of Callbacks” on page 12-8
“Specify Callbacks in Function Calls” on page 12-11
What Is a Callback?
A callback is a function that you write and associate with a specific component
in the GUI or with the GUI figure itself. The callbacks control GUI or
component behavior by perfo rming some action in response to an e vent for
its component. The event can be a mouse click on a push button, menu
selection, key p res s, etc. This kind of p rogramming is often called event-driven
programming.
The callback functions you provide co ntrol how the GUI responds to events
such as button clicks, slider movement, menu item selection, or the creation
and deletion of components. There is a set of callbacks for each component
and for the GUI figure itself.
The callback routines usually appear in a GUI code file following the
initialization code and the creation of the components. See “File Organization”
on page 11-4 for more information.
When an event occurs for a component, MA TLAB software invokes the
component callback that is associated with that e vent. As an example,
suppose a GUI has a push button that triggers the plotting of some data.
When the user clicks the button, the software calls the callback you associated
with clicking that button, and then the callback, which you h ave programmed,
gets the data and plots it.
A component can be any control device such as an axes, push button, list box,
or slider. For purposes of programming, it can also be a menu, toolbar tool, or
a container such as a panel or button group. See “Types of GUI Components”
on page 11-9 for a list and descriptions of components.
12-7