GUIDE UI object positions change between retina display and windows

4 Ansichten (letzte 30 Tage)
Liner
Liner am 13 Jan. 2016
Bearbeitet: Afiq Azaibi am 30 Mär. 2017
I found a strange behavior for guide making GUIs. I routinely go between my retina display Mac and my home Windows 7 computer (non-retina display) using MATLAB2015b. Even after setting the main figure property and all UI objects to 'normalized' units, when opening and editing a GUI with guide on a Mac with a retina display, all the buttons and UI locations which I edit and add to the GUI appear in the proper location on a Mac Retina display however when opening the same GUI in windows, the buttons are not on the GUI but I think are scaled in position off the GUI perhaps their normalized positions are multiplied some dpi factor which is much higher on retina display, however this factor is not shut off when rendering the edited GUI on a Windows machine. Does anybody else see this behavior or have a solution for it? Thanks, Linus
  1 Kommentar
Adam
Adam am 13 Jan. 2016
I don't use a Mac at all, but we have experienced some odd behaviour when using normalized units across different displays in some situations.
In our case this usually happens where we have normalised components within nested panels. These do not behave well.
The only other behaviour of this kind I have seen that I can recall though is related to dpi differences between a laptop and a normal monitor, especially when the laptop was using a 125% or 150% text size setting though this is a windows setting as far as I am aware so I don't know what other differences you get on a Mac.
Bottom line though is that I never really trust normalised units for positioning components any more when we have to use the program on different machines (usually people's laptops).
Nowadays I tend to use the GUI Layout toolbox in the File Exchange for programmatic UIs. This also exhibits some buggy behaviour in certain cases of nested panels, but generally behaves better from my experience.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Pavel Dey
Pavel Dey am 22 Jan. 2016
There is a bug in how 'character' units are handled between systems in different operating systems (specifically operating systems with different system DPI settings).
As a workaround, the 'Units' can be changed to something other than 'characters'. 'pixels' are system dependent, and should scale all elements depending on the system DPI settings. 'inches' and 'centimeters' are absolute units, and scaling should not occur. 'normalized' units are generally considered good practice, but this will scale the elements based on the size of their parent, so this can have a cascading effect on GUIs.
Changing the 'Units' negates the advantages of specifying 'characters' as 'Units', so text may not fit exactly the same way inside its containing object. It is recommended to leave extra space around the text to ensure that even if the element shrinks or the text size grows, it will still display as expected.
Another workaround is to simply rebuild the GUI in the system that appears to have the issue. However, considering you work on both interchangeably, it will not be a sustainable solution for you.
Hope it helps you to understand the issue.
  1 Kommentar
Walter Roberson
Walter Roberson am 22 Jan. 2016
Note that for sufficiently new MATLAB and sufficiently high DPI, "pixels" have been assigned a fixed width that does not depend upon the actual DPI. 'pixels' become more like 'points', that somewhat obscure unit which is 1/72 of an inch.

Melden Sie sich an, um zu kommentieren.


Afiq Azaibi
Afiq Azaibi am 30 Mär. 2017
Bearbeitet: Afiq Azaibi am 30 Mär. 2017
When interchanging the units of graphics objects in MATLAB, the way the figure appears in one environment may be drastically different in another. This can be caused by a difference in monitors and screen resolutions especially if the 'pixel' unit is being used. A best practice is to stay consistent with using the 'normalized' unit for these objects which gets rendered in respect to its parents opposed to the screen. If you have code that looks the way you want but is using a variety of units, try using the following function to find all instances of units to 'normalized' within your figure. It could be possible you may not have caught all instances of objects with a 'units' property.
function [] = normalize(obj)
%sets to normal if it can
prop = properties(obj);
if(sum(ismember(prop,'Units')))
obj.Units = 'normalized';
end
%recurses on all the children
if(~isempty(obj.Children))
for i = 1:length(obj.Children)
normalize(obj.Children(i));
end
end
end

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by