4

I am editing a GUI written in MATLAB and have a line in the OpeningFcn that sets the callback for resizing the figure.

set(hObject, 'UserData', handles.ParentFig, 'ResizeFcn',@cbFigResize, 'CloseRequestFcn', @Cancel);

The callback is pasted below with much edited out for simplicity.

function cbFigResize(src,evt)
% check if figure width is less than 600
if fpos(3) < 600 
    %set min. width to 600
    fpos(3) = 600
end
%check if figure height is less than 560
if fpos(4) <560
    % set minimum height to 560
    fpos(4) = 560;
end

My coworker runs Windows XP and an earlier version of MATLAB. I run Windows 7 and MATLAB 7.12.0.635. Now when he resizes figures they always resize properly. When I run the same code I can sometimes get the figure smaller than the above set minimum width and height limits. My coworker says it is a Windows 7 interrupt problem. If anybody else out there has this problem we found a simple but illogical workaround which I will post below.

function cbFigResize(src,evt,doStop)
if nargin < 3
    doStop = false;
end

% check if figure width is less than 600
if fpos(3) < 600 
    %set min. width to 600
    fpos(3) = 600
end
%check if figure height is less than 560
if fpos(4) <560
    % set minimum height to 560
    fpos(4) = 560;
end

if ~doStop
    cbFigResize(src,evt,true)
end

You can see that this function calls itself with a flag that stops if from becoming an infinite loop. And now I cannot resize windows below the minimum. Has anybody any insights into this behavior?

Paul Linden
  • 421
  • 4
  • 8
  • Can you expand the post to show the code that's actually setting figure properties after fpos is calculated? – Andrew Janke Nov 15 '11 at 18:04
  • fpos is set in the fig properties in guide. There are no changes to fpos besides the one above in the code. The code I have not included is just a maze of setting button positions based on the height and width of fpos. But no changes to fpos besides the one above. A user may resize the window which sets fpos but that is somewhere in MATLAB and not in my code. – Paul Linden Nov 15 '11 at 20:56

1 Answers1

1

A user on mathworks.com answered this question. His solution solved the problem. I will put the link below. http://www.mathworks.com/matlabcentral/answers/21294-matlab-resizefcn-callback-fails

Paul Linden
  • 421
  • 4
  • 8