Creating Graphical User Interfaces    

Implementing the GUI

This section describes the steps followed to implement the requirements described in the previous section.

Launching the Dialog

The Close button's callback needs to launch a dialog that asks for confirmation of the impending close operation. This callback must then wait for a dialog to return a value. To accomplish this, the dialog's application M-file assigns an output argument and the Close button's callback waits for it to be returned.

The following picture illustrates the dialog positioned over the GUI figure.

Wait for User Input

To make the dialog wait for user input, select Function does not return until application window dismissed in the GUIDE Application Options dialog. This option adds a call to uiwait in the dialog's application M-file.

Making the Dialog Figure Modal

To make the dialog figure modal, select the figure in the Layout Editor and then right-click to display the context menu. Select Property Inspector from the context menu. Use the Property Inspector to set the figure's WindowStyle property to modal.

Sequence Following a Close Button Press

The following sequence occurs when the user presses the Close button on the GUI application figure:

  1. User clicks Close button - callback calls the M-file to launch the confirmation dialog and waits for a returned value.
  2. Confirmation dialog M-file executes and waits for user to take one of three possible actions: click the Yes push button, the No push button, or the close box (X) on the window border. All other interactions with MATLAB are blocked.
  3. Confirmation dialog callbacks resume M-file execution, causing output the value to be returned to the Close button callback.
  4. Close button callback resumes execution and takes appropriate action based on user response to the confirmation dialog.

 Launching a Dialog to Confirm an Operation The Close Button Callback