9 Examples of GUIDE UIs
When the you resize the window and release the mouse, the SizeChangedFcn callback
executes. Unless you have maximized the figure, the SizeChangedFcn callback enforces
the height of the window and resets the width of the Contact Name field. The following
sections describe how this calculation works.
Width Changes
If the new width is greater than the original width, set the figure to the new width.
The size of the Contact Name text box changes in proportion to the new figure width.
This is accomplished by:
- Obtaining the figure width as a ratio of its original width.
- Expanding or contracting the width of the Contact Name field proportionally.
If the new width is less than the original width, use the original width. The code relies on
the fact that the original width of the Contact Name field is 72 character units.
Height Changes
The height and width of the UI window is specified in pixel units. Using units of pixels
enables maximizing and minimizing the figure to work properly. The code assumes
that its dimensions are 470-by-250 pixels. If you attempt to change the height, the code
restores the original height. However, because the resize function is triggered when
you release the mouse button after changing the size, the resize function cannot
always determine the original position of the window on the screen. Therefore, the resize
function applies a compensation to the vertical position (second element in the figure
Position vector) by adding the vertical position to the height when you release the
mouse and subtracting the original height.
When you resize the UI window from the bottom, the window stays in the same position.
When you resize from the top, the window moves to the location where you release the
mouse button.
SizeChangedFcn
% uicontrol units are in 'characters'
Figure_Size = get(hObject,'Position');
% This is the figure's original position in pixel units
Original_Size = [350 700 470 250];
% If the figure seems to be maximized, do not resize at all
pix_pos = get(hObject,'Position');
scr_size = get(groot,'ScreenSize');
if .99*scr_size(3) < pix_pos(3) % Apparently maximized