MATLAB Answers

Normalize app designer window position

176 views (last 30 days)
Brandon Campanile
Brandon Campanile on 1 Dec 2018
Edited: Andrew Diamond on 27 Mar 2020
I have an application I made in app designer that has the line app.UIFigure.WindowState = 'maximized'. The UIFigure has a default position of [1 1 1920 1080] and fits to my screen very nicely and maximizes very well. However, it's only working for my display; on anyone elses it does not scale correctly. The matlab application I am using is located here. The "normalized" property is not yet supported in app designer so I have to use the pixel units. Whenever I change the size of the UIFigure programmatically it does not resize the children (yes I have resize children on). I've tried the following:
d=get(0,'screensize');
app.UIFigure.Position = [1 1 d(3) d(2)];
However, this isn't changing the size of the children recursively. I even tried scaling it like this:
d = get(0,'screensize');
app.UIFigure.Position = [1 1 d(3)*app.UIFigure.Position(3)/1920 d(4)*app.UIFigure.Position(4)/1080];
The above works for some elements (not UIFigure), but I have too many to do that for each one. I also tried making a recursive function. I dont remember exactly, but it was something like this:
d = get(0,'screensize');
updatePosition(app.UIFigure)
function updatePosition(R)
if ~isempty(R.Children)
R.Children.Position = [1 1 d(3)*R.Children.Position(3)/1920 d(4)*R.Children.Position(4)/1080];
updatePosition(R.Children)
end
end
Nothing is working. App designer needs some serious TLC. Does anybody know of a way to get the app to size appropriately for different screen sizes and resolutions (short of a startup fnc that changes the position of every single element)?
  1 Comment
Chris Portal
Chris Portal on 3 Dec 2018
Do you have screenshots that shows what it looks like on your display vs someone elses, just to understand what you mean by “does not scale correctly”?

Sign in to comment.

Answers (3)

Jorge Barrasa Fano
Jorge Barrasa Fano on 6 Aug 2019
The line:
movegui(app.UIFigure,"center");
at the beginning of startupFcn works fine for me. No need to do pause() and it avoids playing with window coordinates.
  1 Comment
Andrew Diamond
Andrew Diamond on 27 Mar 2020
This doesn't rescale the children for me. On a display smaller than the application size, It will move the app and seems to resize the figure to fit but not the children. I have whole gui elements that are simply not available because of this (they get chopped off in the now smaller figure). Resizing the window manually afterwards doesn't do anything to help. The FigureSizeChanged callback does not get called.
It does seem that if I stop in the debugger in the startufcn it will do it but I tried to emulate that with a pause(5) and a drawnow but that didn't work. I guess I could set up a timer to try and resize in a few seconds but it's pretty nasty

Sign in to comment.


Scott Guillaudeu
Scott Guillaudeu on 22 Jul 2019
In startupFcn, try pause(2) before setting app.UIFigure.Position. It's ugly and I don't know exactly why it works, but It seems to take a while to layout the figure the first time and it will only resize all the children after it's done the first layout.
This works for me on a Mac, but I haven't tried any other OSes.

Mekiedje Jöel
Mekiedje Jöel on 21 Jan 2019
Hello, i just have the same problem. Have you solved the problem ?

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!