Create GUI figures which scale position and size based on resolution
Show older comments
Hello, I have a program which first has one GUI which has a button which is pushed to call three other GUIs. I want these four GUIs to have a set layout, in that the initial GUI occupies ~1/4 of the screen on the left side, two GUIs stacked upon each other in the middle of the screen, then the final GUI on the right side. I have changed the positions for each and made it so that this layout is present using my laptop at its native screen resolution. The issue, however, is that I plan to give the program to others, and when I change the screen resolution of my laptop to one with a different aspect ratio of a smaller size, the distance between GUIs and their size remains the same. This pushes the last, right-most GUI partially off the screen. I have set all units, including font units and position units, to 'normalized' for all four GUI windows. Is there something else I have to do to have the window size scale automatically?
Thanks, Ak
8 Comments
OCDER
on 16 Jul 2018
I'm guessing resize behavior is an issue, as the GUI gets cutoff for being too large?
Adam
on 16 Jul 2018
Use
get( groot, 'Screensize' )
to dynamically get the screensize and use this in positioning calculations rather than hardcoding for a screensize. Depending on what you are doing it can still be messy, as always with having UIs look nice on different resolution screens, but if you get the maths right it will at least guarantee to be on-screen.
Ak K
on 16 Jul 2018
Ak K
on 16 Jul 2018
Rik
on 16 Jul 2018
How are you currently setting the positions of each GUI window? You can use the line of code OCDER suggested to get the screen size, and use that to determine where each window should go.
However, this will ignore the position and size of your taskbar and other floating edge objects (like sidebars). A more robust method of getting the entire available size of the screen would be to maximize a window, and then getting its size.
OCDER
on 17 Jul 2018
Is there a demo code we can look at to see how you're resizing the GUIs? I think this just involves some clever size calculations. Start with what Adam suggested for using the screen resolution first, and then divide out the position and sizes of the GUIs. But then, I'm not sure how it works with dual-monitor setups.
Adam
on 18 Jul 2018
My second monitor is just considered as an extension of the first in terms of size - e.g. screen resolution returns 1920 as my lateral screen size. If I position a figure at 2100 it puts it on the second monitor.
You can use
get( groot, 'MonitorPositions' )
if you want to make full use of the real estate available on a given machine, although this would involve having to do different things depending how many monitors there are. The above command gives me a 2x4 output for my monitors so taking the size of the first dimension of this result will tell you how many monitors there are, though there may be a single call function that also gives you this that I am not aware of.
As an aside, if you want to nosey into what is available (which I always do!)
get( groot )
will give a list of all the values you can query from groot.
Ak K
on 18 Jul 2018
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!