Filter löschen
Filter löschen

How to wait for uifigure to resize properly?

15 Ansichten (letzte 30 Tage)
Peter Valent
Peter Valent am 7 Mai 2021
Beantwortet: Mark am 19 Jan. 2024
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:
  1. Why is the resizing function run before all the uifigure components are resized properly?
  2. How to wait for the resizing? (1 second might not be enough once the uiaxes contains a lot of data)
Effect of uiwait:
  2 Kommentare
Anastasia Eltsova
Anastasia Eltsova am 7 Mai 2021
Not sure, if it works for you, but I used waitfor() function. It waits for a figure to be complete without async execution
Peter Valent
Peter Valent am 7 Mai 2021
I tried this but you have to set a property on which change you are waiting. The problem is that I dont know how to say whether all the uifigure children has alrady been resized. What if they are before the code reaches waitfor() function. Then the program would stuck there and it would wait until next change in the unknown property (probably position) happens.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mark
Mark am 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.

Kategorien

Mehr zu Maintain or Transition figure-Based Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by