User`s guide

15 Examples of GUIs Created Programmatically
The iconEditor’s loca lEdi tColor helper function calls mGetColorFcn,
the function returned by
colorPalette, to execute the colorPalette’s
getSelectedColor function.
function localE ditC olor
% helper function that chan ges the color of an icon data
% point to that of the currently selected color in
% colorPalet te
if mIsEditingIc on
pt = get(hIconEditAxes,'currentpo int');
x = ceil(pt(1,1));
y = ceil(pt(1,2));
color = mGetColorFcn();
% update color of the selecte d block
mIconCData(y, x,:) = color;
localUpdateIconPlot();
end
end
Achieve Proper Resize Behavior
The prepareLa yout u tility f un ction sets th e Units properties of all the GUI
components to enable the GUI to resize correctly on m ultiple platforms. Code
in the initialization section of iconEditor calls
prepareLayout w ith the handle
of the main figure.
prepareLayout(hMainFigure);
First, p repareLayout uses findall to retrieve the handles of all o bjects
contained in the figure. The list of retrieved handles includes the
colorPalette,whichisembeddedintheiconEditor, and its children. The
figure’s handle is passed to
findall as the input argument topContainer.
function prepar eLay out(topContainer)
...
allObjects = findall(topContainer);
Then, prepareLayout uses strcmpi to determine if the GUI is resizable.
Depending on the outcome, it sets the
Units properties of all the objects to
either
Normalized or Characters.
15-78