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

조회 수: 5 (최근 30일)
Veronica Taurino
Veronica Taurino 2022년 5월 10일
댓글: dpb 2022년 5월 12일
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
dpb
dpb 2022년 5월 11일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2022년 5월 10일
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
Walter Roberson
Walter Roberson 2022년 5월 12일
'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 2022년 5월 12일
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"...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by