Axes, Menus, and Toolbars in Programmatic UIs
- For each of the menu items, the Callback property specifies the callback that
services that item. These callbacks are defined as nested functions in the same file.
The Toolbar
These statements define the toolbar and the two buttons it contains:
hToolbar = uitoolbar(... % Toolbar for Open and Print buttons
'Parent',hMainFigure, ...
'HandleVisibility','callback');
hOpenPushtool = uipushtool(... % Open toolbar button
'Parent',hToolbar,...
'TooltipString','Open File',...
'CData',iconRead(fullfile(matlabroot,...
'toolbox\matlab\icons\opendoc.mat')),...
'HandleVisibility','callback', ...
'ClickedCallback', @hOpenMenuitemCallback);
hPrintPushtool = uipushtool(... % Print toolbar button
'Parent',hToolbar,...
'TooltipString','Print Figure',...
'CData',iconRead(fullfile(matlabroot,...
'toolbox\matlab\icons\printdoc.mat')),...
'HandleVisibility','callback', ...
'ClickedCallback', @hPrintMenuitemCallback);
- The uitoolbar function creates the toolbar.
- The uipushtool function creates the two push buttons in the toolbar.
- The uipushtool TooltipString property assigns a tool tip that displays when the
user moves the mouse pointer over the button and leaves it there. - The CData property specifies a truecolor image that displays on the button. For these
two buttons, the utility iconRead function supplies the image. - For each of the uipushtools, the ClickedCallback property specifies the callback
that executes when the user clicks the buttons.
Initialize the UI
This code creates the plot that appears when the UI initially displays. This code also
checks to see if the user provided an output argument.
% Update the plot with the initial plot type
localUpdatePlot();
% Define default output and return it if it is requested by users
mOutputArgs{1} = hMainFigure;
if nargout>0
[varargout{1:nargout}] = mOutputArgs{:};