How to wait for uifigure to resize properly?
18 views (last 30 days)
Show older comments
I am building a rather complex program in appdesigner, which contains axes showing a map. I had difficulties to make sure that the map always stays at the same location whenever I resize the app and whenever I zoom in or out the map shown. I decided to control the resizing behaviour of the uifigure in which I adjust the x,y limits of the uiaxes. I have the following problem:
In the first step the resize function gets the position of a uipanel in which the uiaxes is situated. In the next step this position is used to adjust the position of the uiaxes. It seems that the position is wrong as the resizing of the uipanel is probably not complete. I added the following code to wait for the uifigure resizing and it worked:
uiwait(app.UIFigure,1)
The problem is that I have to wait for 1 second (not possible to set less than 1 second) before the plot is updated.
My questions:
- Why is the resizing function run before all the uifigure components are resized properly?
- How to wait for the resizing? (1 second might not be enough once the uiaxes contains a lot of data)
Effect of uiwait:
2 Comments
Anastasia Eltsova
on 7 May 2021
Not sure, if it works for you, but I used waitfor() function. It waits for a figure to be complete without async execution
You can read more here Interrupt Callback Execution - MATLAB & Simulink (mathworks.com)
Answers (1)
Mark
on 19 Jan 2024
In my app, I am using AutoResizeChildren, so I cannot use the SizeChangedFcn callback. Instead, I do my resizing within the startupFcn, since it only needs to happen once in my case. However, I was still having issues with the resizing happening before everything had loaded, so the auto resizing did not work as expected. Using drawnow before my positioning changes fixed this issue for me.
0 Comments
See Also
Categories
Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!