Position of Not-visible figure is WRONG (two monitors bug?)

3 visualizaciones (últimos 30 días)
Veronica Taurino
Veronica Taurino el 10 de Mayo de 2022
Comentada: dpb el 12 de Mayo de 2022
If I create a figure and maximize it, I got sizes fitting my second monitor:
fig = figure('Menu','none','ToolBar','none','WindowState','maximized','Visible','on');
>> fig.Position
ans =
1.0e+03 *
0.0010 0.0490 1.2800 0.6493
But if I create a not visibile figure, I got a wrong position:
fig = figure('Menu','none','ToolBar','none','WindowState','maximized','Visible','off');
>> fig.Position
ans =
360 198 560 420
Moreover, if I change the visible property to "ON", Matlab at first shows me the same wrong position (even if the figure is indeed maximized, I can see it on the screen):
fig.Visible='on'
but when I click on "show all properties", it shows the right position:
fig.Position
ans =
1.0e+03 *
0.0010 0.0490 1.2800 0.6493
How can I solve this? I need it to properly define some sizes in my App (app designer).
For now, I create a figure, store the position and close it. But I would like the user didn't see an empty figure during the process.
Thank you
  1 comentario
dpb
dpb el 11 de Mayo de 2022
Again, you can avoid that by a selective workaround of a set of coordinates that you know are going to be in the visible range...depends upon which effect you think the lesser evil -- the temporary figure flicker or not being exactly where you want it.
I'd think it possible to figure out an algorithm about where your position is that you could compute a satisfactory set of coordinates from the data that are available.

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 10 de Mayo de 2022
I deal with it by having a usersettings structure saved as a .mat file that contains all the stuff to restore from the user's last session including the last position of figures where the user left them. The startup function reloads all those so the figure will be recreated where the user last left it. If the file doesn't exist, then there are some system defaults that are reasonable for the number/size of monitor(s).
You can discover the number and size of monitors at the time your app starts by querying the root properties of the graphics environment. See the doc section titled "Root Properties" under Graphics Object Properties
With that data, you can set reasonable bounds based on the user's environment and not be dependent upon the defaults as your present method is.
  5 comentarios
Walter Roberson
Walter Roberson el 12 de Mayo de 2022
'The task I am required to do is to locate GUI and plots perfectly from the beginning, not "perfectly enough"'
You need to switch graphics libraries then, unless you are using fixed width plots with fixed font size and fixed graphics resolution.
The graphics model used by MATLAB postpones layout until the graphics objects are made visible, for efficiency.
Automatic layout is fairly complicated. For example the exact drawing width of an axes depends on the details of how rounding is done in the conversion between data coordinates and physical coordinates which depends in part on the magnifying factor to account for high resolution displays. But whether you can complete a word or need to split over two lines can depend on the exact pixel width... and so on.
dpb
dpb el 12 de Mayo de 2022
Yeah, Walter, I didn't even begin to touch that level of detail -- in my environment at least, it's good enough to have the figure be on the screen; ime the user will always end up tweaking/moving stuff around anyways, no matter how finely-tuned the developer thinks they've made it.
Sometimes, there is no practical alternative but "perfect enough"...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by