MATLAB Creating Graphical User Interfaces

(Barry) #1
Write Callbacks Using the GUIDE Workflow

GUIDE Callback Syntax


All callbacks must accept at least three input arguments:



  • hObject — Handle to the UI component that triggered the callback.

  • eventdata — A variable that contains detailed information about specific mouse or
    keyboard actions.

  • handles — A struct that contains handles to all the objects in the UI. GUIDE uses
    the guidata function to store and maintain this structure.


For the callback function to accept additional arguments, you must put the additional
arguments at the end of the argument list in the function definition.


The eventdata Argument


The eventdata argument provides detailed information to certain callback functions.
For example, if the end user triggers the KeyPressFcn, then MATLAB provides
information regarding the specific key (or combination of keys) that the end user
pressed. If eventdata is not available to the callback function, then MATLAB passes
it as an empty array. The following table lists the callbacks and components that use
eventdata.


Callback Property Name Component
WindowKeyPressFcn
WindowKeyReleaseFcn
WindowScrollWheel

figure

KeyPressFcn figure, uicontrol, uitable
KeyReleaseFcn figure, uicontrol, uitable
SelectionChangedFcn uibuttongroup
CellEditCallback
CellSelectionCallback

uitable

Renaming and Removing GUIDE-Generated Callbacks


Renaming Callbacks


GUIDE creates the name of a callback function by combining the component’s Tag
property and the callback property name. If you change the component’s Tag value, then
GUIDE changes the callback's name the next time you save the UI.

Free download pdf