MATLAB Answers

0

What are the changes to the behavior of ResizeFcn in MATLAB R2014b?

I am aware of the fact that MATLAB graphics have undergone changes in R2014b. Can you summarize the changes to the behavior of the 'ResizeFcn' in MATLAB R2014b. I use the function extensively when developing my apps and I need to know what are the changes to be aware of.

Products


Release

R2014b

1 Answer

Answer by MathWorks Support Team on 28 Aug 2014
 Accepted Answer

 Changes in the behavior of the 'ResizeFcn' callback reflect changes to the positioning and layout of figures and containers to make their behavior more consistent with one another and across all platforms. Note that use of the 'ResizeFcn' property is not recommended. It might be removed in a future release. Use 'SizeChangedFcn' instead.
Starting in R2014b, the ResizeFcn callback might execute before all variables in the program file are assigned. When this happens, the 'ResizeFcn' callback returns an error.
For example, this GUI has a 'ResizeFcn' callback that uses a variable returned by the 'createGUI' function.
function mygui
    hs = createGUI;
    function handles = createGUI
        % Create figure and its children
        f = figure('Tag','fig',...
                   'ResizeFcn',@doResizeFcn,...
                   'Visible','off');
        u = uicontrol('Parent',f,'Tag','ctrl');
        handles = guihandles(f);
       
        % make figure visible
        set(f,'Visible','on');
    end
    function doResizeFcn(varargin)
        length(hs)
    end
end
Running this GUI in the new graphics system results in an error because 'hs' does not exist when the 'doResizeFcn' callback executes for the first time (when the figure becomes visible).
mygui
Undefined function or variable "hs".
Error in mygui/doResizeFcn (line 18)
        length(hs)
 
Error using mygui/createGUI (line 14)
Error while evaluating Figure SizeChangedFcn
To correct the problem, make the figure visible after all the variables that the callback references are assigned. In this case, make the figure visible after calling the createGUI function.
function mygui
    hs = createGUI;
    % Make the figure visible
    set(hs.fig, 'Visible','on');
     function handles = createGUI
        % Create figure and its children
        f = figure('Tag','fig',...
                   'ResizeFcn',@doResizeFcn,...
                   'Visible','off');
        u = uicontrol('Parent',f,'Tag','ctrl');
        handles = guihandles(f);
    end
    function doResizeFcn(varargin)
        length(hs)
    end
end
 
Starting in R2014b, changing the size of an invisible container, such as a figure, panel, button group, does not trigger the ResizeFcn callback until the container becomes visible.
In previous releases of MATLAB®, the 'ResizeFcn' callback executes when the size of the container changes, regardless of whether it is visible.
You can control the visibility of figures and containers using the 'Visible' property:
  • A figure is visible if its 'Visible' property is set to 'on'.
  • A uipanel or uibuttongroup is visible if its 'Visible' property, and that of its ancestors, is set to 'on'. For example, a uibuttongroup whose parent is a uipanel is visible when the 'Visible' property of the uibuttongroup, uipanel, and the figure are all set to 'on'.
Starting in R2014b, changing the outer bounds of a figure or container does not trigger the 'ResizeFcn' callback.
For example, this figure 'ResizeFcn' callback does not execute in the new graphics system when you change the 'OuterPosition' (by removing the menu bar) on the second line of this code. However, the callback does execute in previous releases of MATLAB.
f = figure('ResizeFcn','display resized');
set(f,'Menubar','none');
Starting in R2014b, the 'ResizeFcn' callback executes only when the container's drawable area (the inner area) changes. Previous releases of MATLAB might not execute the 'ResizeFcn' callback when the drawable area changes.
For example, this uipanel 'ResizeFcn' callback executes in the new graphics system when you change the uipanel's drawable area by increasing the border width. The callback does not execute when your run this code in previous releases.
p = uipanel('ResizeFcn','display resized');
set(p,'BorderWidth',3);

  0 Comments

Sign in to comment.