MATLAB Creating Graphical User Interfaces

(Barry) #1

14 Examples of UIs Created Programmatically


4 Figure window and component creation.
5 UI initialization.
6 Callback definitions. These callbacks, which service the UI components, are local
functions of the colorPalette main function and so have access to the data and
component handles created at the top level, without their having to be passed as
arguments.
7 Helper function definitions. These helper functions are local functions of the
colorPalette main function and so have access to the data and component handles
created at the top level, without their having to be passed as arguments.

UI Programming Techniques


This topic explains the following UI programming techniques as they are used in the
creation of the colorPalette.


  • “Pass Input Arguments to the Program” on page 14- 36

  • “Pass Output to a Caller on Returning” on page 14- 37


Pass Input Arguments to the Program

Inputs to the program are custom property-value pairs. colorPalette allows one such
property: Parent. The names are case-insensitive. The colorPalette syntax is

mGetColorFcn = colorPalette('Parent',hPaletteContainer)

Definition and Initialization of the Properties

The colorPalette function first defines a variable mInputArgs as varargin to accept
the input arguments.

mInputArgs = varargin; % Command line arguments

The colorPalette function then defines the valid custom properties in a 3-by-3 cell
array.
mPropertyDefs = {... % The supported custom property/value
% pairs
'parent', @localValidateInput, 'mPaletteParent';


  • The first column contains the property name.

  • The second column contains a function handle for the function,
    localValidateInput, that validates the input property values.

Free download pdf