Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to make a GUI that works in all display modes?

Subject: How to make a GUI that works in all display modes?

From: Bruce Lee

Date: 1 Dec, 1999 13:26:11

Message: 1 of 12

Is there an easy way to create a GUI that displays properly in all display
modes? I develop in Windows 98 at 1024x768 with large fonts, but if I run
the file on another PC at a different resolution the window is too large to
fit on the screen, or the buttons are misplaced, etc. etc.

Do I have to create a GUI for all possible resolutions? Is there any
function which returns the currently selected screen resolution and font
size in Matlab?

*bl

Subject: How to make a GUI that works in all display modes?

From: Jordan Rosenthal

Date: 1 Dec, 1999 15:30:49

Message: 2 of 12

Bruce,

Use get(0,'Screensize') to return the resolution. For the font size, use
get(0,'DefaultAxesFontSize'), get(0,'DefaultTextFontSize'), and
get(0,'DefaultUIControlFontSize'). If you want the defaults for a
particular figure, replace the 0 with the handle for the figure.

Here is one approach to your problem that works okay. If you are sure you
will only be using a PC, then you can change all object units to normalized.
Either save the figure with normalized units, or use the following code
which will convert the units for you.

  hAxes = findall(hFig,'type','axes');
  hText = findall(hAxes,'type','text');
  hUIControls = findall(gcf,'type','uicontrol');
  set([hAxes; hText;
hUIControls],'units','normalized','fontunits','normalized');

Then you can just resize the figure, and all the objects will resize
accordingly. You can, for example, use the screen resolution information to
adjust your figure to take up a certain percentage of the screen.

If you want the code to look good on multiple operating systems, then,
depending on your GUI, you may want to use 'character' units for the layout
and then either convert to normalized at runtime or write your own resize
function that resizes the objects directly in 'character' units.

Hope that helped,

- Jordan

"Bruce Lee" <spamhole@spam.net> wrote in message
news:FM2DBn.7vv@bath.ac.uk...
> Is there an easy way to create a GUI that displays properly in all display
> modes? I develop in Windows 98 at 1024x768 with large fonts, but if I run
> the file on another PC at a different resolution the window is too large
to
> fit on the screen, or the buttons are misplaced, etc. etc.
>
> Do I have to create a GUI for all possible resolutions? Is there any
> function which returns the currently selected screen resolution and font
> size in Matlab?
>
> *bl
>
>

Subject: How to make a GUI that works in all display modes?

From: Damian T. Packer

Date: 1 Dec, 1999 17:01:41

Message: 3 of 12

Jordan Rosenthal wrote
>If you want the code to look good on multiple operating systems, then,
>depending on your GUI, you may want to use 'character' units for the
>layout and then either convert to normalized at runtime or write your own
>resize function that resizes the objects directly in 'character' units.


I just wanted to underscore this part of Jordan's post - 'character' units
are the mechanism we've added to solve the problem of
resolution-independence and font-independance in MATLAB GUIs. You need to
lay out your GUI with the figure, uicontrols, and axes all in character
units, and you need to save it this way. Then, when it is reloaded on any
other machine, all the text strings should still fit in the uicontrols, and
the uicontrols and axes should fit in the figure. You won't need to write
code to check the screensize, or the size of the default font.

If you make your figures non-resizable, then you are done. But if you want
your figures to be resizable, Jordan's suggestion of switching into
normalized units is a good one.

-Damian

Subject: How to make a GUI that works in all display modes?

From: Jordan Rosenthal

Date: 1 Dec, 1999 20:54:01

Message: 4 of 12

Damian,

> I just wanted to underscore this part of Jordan's post - 'character' units
> are the mechanism we've added to solve the problem of
> resolution-independence and font-independance in MATLAB GUIs. You need to
> lay out your GUI with the figure, uicontrols, and axes all in character
> units, and you need to save it this way. Then, when it is reloaded on any
> other machine, all the text strings should still fit in the uicontrols,
and
> the uicontrols and axes should fit in the figure. You won't need to write
> code to check the screensize, or the size of the default font.

But won't you still need to check the screen size in order to put the figure
in the right spot on the screen? I just ran this test Win98/Matlab 11.1,

1) With the screen resolution in 1024x768: Open guide, change figure units
to 'character', save the empty figure, and then close guide.
2) Close Matlab, change the screen resolution to 800x600, reopen Matlab,
open/run the figure just saved.

With this scenario, the figure is mostly off the screen and the title bar is
not visible. One way around this problem is to use some sort of
resize/replacement based on the screensize. Another solution is to build
the layout in the lowest screen resolution you expect to use so that it will
be visible in the higher resolutions. The drawback with this is that the
GUI might look very small at higher resolutions without a resize.

Do you have any other suggestions?

Thanks,

- Jordan

Subject: How to make a GUI that works in all display modes?

From: Bruce Lee

Date: 2 Dec, 1999 15:17:20

Message: 5 of 12

Thanks for your help Jordan. I noticed that, if you set a figure's units to
'normalised' in GUIDE then this seems to apply to the form's position too,
so the window automatically takes up the same proportion of the desktop
whatever the screen mode. There's no need to write a single line of code -
that's how I like it!

*bl

Subject: How to make a GUI that works in all display modes?

From: Damian T. Packer

Date: 2 Dec, 1999 10:49:32

Message: 6 of 12

Hi Jordan,

You wrote:
>But won't you still need to check the screen size in order to put the
figure
>in the right spot on the screen? I just ran this test Win98/Matlab 11.1,
>
>1) With the screen resolution in 1024x768: Open guide, change figure units
>to 'character', save the empty figure, and then close guide.
>2) Close Matlab, change the screen resolution to 800x600, reopen Matlab,
>open/run the figure just saved.
>
>With this scenario, the figure is mostly off the screen and the title bar
is
>not visible.

Agreed - character units are only meant to stop you from having to resize
your gui and its contents to take different resolutions and fontsizes into
account. You may still want to check screen size to make sure your GUI is
positioned on screen.

> Another solution is to build
>the layout in the lowest screen resolution you expect to use so that it
will
>be visible in the higher resolutions. The drawback with this is that the
>GUI might look very small at higher resolutions without a resize.
>
>Do you have any other suggestions?


No, I think you have the right idea here. Many of our GUI designers check
their GUIs at low resolution before releasing their product, to make sure it
will look good and fit on screen. People with high resolution screens
expect their GUIs to look small, especially if they have selected "small
fonts". And people have the option of selecting "large fonts", if they want
their GUIs to be bigger. And as long as you use character units, your GUIs
will automatically be sized properly for both large and small fonts.

Hope this helps,

-Damian

Subject: How to make a GUI that works in all display modes?

From: Jordan Rosenthal

Date: 2 Dec, 1999 12:23:58

Message: 7 of 12

Damian,

> account. You may still want to check screen size to make sure your GUI is
> positioned on screen.

Wouldn't a function that could do this make a great enhancement? :)

> their GUIs to be bigger. And as long as you use character units, your
GUIs
> will automatically be sized properly for both large and small fonts.

So how should you handle resize operations in this case? If the figure is
saved in character units, the resize won't really change anything. That's
usually why I go normalized at runtime. This tack is a pain, however, if I
want to use the guide tool since, when making edits, I invariably forget to
change back to character units before saving!

I write GUIs that need resize capability. (They are used by teachers during
lectures who want to maximize the size on the screen so the GUI looks good
when put through a projector, and by students who probably don't want the
entire screen taken up!) In my opinion, writing GUIs with good resize
capabilities has been the hardest part of writing them!

Are there any examples to show how to handle various GUI resizing issues
other then the few lines in the HelpDesk? It would be great to see
different 'ResizeFcn' callbacks and to check out how other people have
handled this.

A couple of other comments:

1) If 'character' units are the suggested way to go, maybe the guide tool
should automatically create new figures/objects with these units set. Of
course, I could see why you wouldn't want to change a previously created
figure's units, but for new figures it might be helpful. If 'character'
units are definitely the way to go, it seems to me the software should
encourage it. A menu in guide to change all relavent units from one to
another would be very helpful.

2) The guide display grid can currently only be in terms of pixels. It
would be really helpful if this could be given in terms of other units,
'character' especially. Precisely laying out a GUI in character units is a
pain when the display grid is in pixels! If you align to grid (which is in
pixels) the placement in character units is rarely ever a nice integer.
That makes it much harder to place another object a certain distance from
the first. As an example, try placing one object one third of the width of
another object. In pixels, it's pretty easy because the numbers are usually
integers. In 'character' units aligned to the grid, you can't do it in your
head and must calculate the correct results.


Thanks again for your comments,

- Jordan

Subject: How to make a GUI that works in all display modes?

From: Richard Lang

Date: 3 Dec, 1999 09:41:54

Message: 8 of 12


>
>I write GUIs that need resize capability. (They are used by teachers
during
>lectures who want to maximize the size on the screen so the GUI looks good
>when put through a projector, and by students who probably don't want the
>entire screen taken up!) In my opinion, writing GUIs with good resize
>capabilities has been the hardest part of writing them!


I entirely agree but I don't think this is Matlab's fault. GUI design is
always a thorny issue. However it seems to me that some of the points
raised here are, for example, often handled very neatly in Java using Layout
Managers. And it also seems to me that the concept is usable in Matlab. I
haven't tried any of the following explicitly but it seems to me that you
could create a Layout object which you attach to a figure resize function.
This object defines a conceptual layout on screen - say 1/3 of the screen on
the left and 2/3 on the right. You could register your GUI controls with
the manager, defining the portion they should be in, and the manager should
take care of resizing different parts of the GUI appropriately. It would be
easy to allow the manager to accept another manager for a section and then
pass on resize calls down the tree, allowing you to define your interface
layout pretty nicely.

In my opinion this is probably best done by wrapping things up in Matlab
classes but it may be feasible without that if you prefer. It should
certainly lead to much greater code reuse. If I get the time then I'll
certainly be trying it out in the future.

Richard

Subject: How to make a GUI that works in all display modes?

From: Jordan Rosenthal

Date: 3 Dec, 1999 10:25:42

Message: 9 of 12

Richard,

> I entirely agree but I don't think this is Matlab's fault. GUI design is
> always a thorny issue.

I guess I did kind of sound like I was complaining about Matlab...but I
didn't mean it to come out that way. I actually love programming GUIs in
Matlab's environment because it enables me to build the kinds of things I
need really quickly. I was more just trying to point out some of the
difficulties in hopes of obtaining an even better environment in the future.
:)

> However it seems to me that some of the points
> raised here are, for example, often handled very neatly in Java using
Layout
> Managers. And it also seems to me that the concept is usable in Matlab.
I

Agreed, that sounds like a good idea. Maybe during my next break, I'll try
and mimic some of these managers in Matlab. (Unfortunately, my next break
may not be until Easter, but isn't that the way of things..... )

Thanks for the suggestion,

- Jordan

Subject: How to make a GUI that works in all display modes?

From: Tom Krauss

Date: 7 Dec, 1999 13:29:33

Message: 10 of 12



Richard Lang wrote:

> I haven't tried any of the following explicitly but it seems to me that you
> could create a Layout object which you attach to a figure resize function.
> This object defines a conceptual layout on screen - say 1/3 of the screen on
> the left and 2/3 on the right. You could register your GUI controls with
> the manager, defining the portion they should be in, and the manager should
> take care of resizing different parts of the GUI appropriately. It would be
> easy to allow the manager to accept another manager for a section and then
> pass on resize calls down the tree, allowing you to define your interface
> layout pretty nicely.
>
> In my opinion this is probably best done by wrapping things up in Matlab
> classes but it may be feasible without that if you prefer. It should
> certainly lead to much greater code reuse. If I get the time then I'll
> certainly be trying it out in the future.

I think this is a GREAT idea! I have often wished for the capability
to allow certain ui objects to stay the same size in pixels (or characters),
but anchored a certain distance from one of the corners, such as
top-left or top-right. Any resizefcn class should make this easy to
do.

Let us know if you get anything working!

Cheers,
  Tom Krauss
  PhD Student

Subject: How to make a GUI that works in all display modes?

From: Tom Krauss

Date: 7 Dec, 1999 13:30:12

Message: 11 of 12



Richard Lang wrote:

> I haven't tried any of the following explicitly but it seems to me that you
> could create a Layout object which you attach to a figure resize function.
> This object defines a conceptual layout on screen - say 1/3 of the screen on
> the left and 2/3 on the right. You could register your GUI controls with
> the manager, defining the portion they should be in, and the manager should
> take care of resizing different parts of the GUI appropriately. It would be
> easy to allow the manager to accept another manager for a section and then
> pass on resize calls down the tree, allowing you to define your interface
> layout pretty nicely.
>
> In my opinion this is probably best done by wrapping things up in Matlab
> classes but it may be feasible without that if you prefer. It should
> certainly lead to much greater code reuse. If I get the time then I'll
> certainly be trying it out in the future.

I think this is a GREAT idea! I have often wished for the capability
to allow certain ui objects to stay the same size in pixels (or characters),
but anchored a certain distance from one of the corners, such as
top-left or top-right. Any resizefcn class should make this easy to
do.

Let us know if you get anything working!

Cheers,
  Tom Krauss
  PhD Student

Subject: How to make a GUI that works in all display modes?

From: Jerry Gregoire

Date: 21 Aug, 2013 17:37:05

Message: 12 of 12

"Jordan Rosenthal" <jr@ece.gatech.edu> wrote in message <8240pa$96$1@news-int.gatech.edu>...
> Bruce,
>
> Use get(0,'Screensize') to return the resolution. For the font size, use
> get(0,'DefaultAxesFontSize'), get(0,'DefaultTextFontSize'), and
> get(0,'DefaultUIControlFontSize'). If you want the defaults for a
> particular figure, replace the 0 with the handle for the figure.
>
> Here is one approach to your problem that works okay. If you are sure you
> will only be using a PC, then you can change all object units to normalized.
> Either save the figure with normalized units, or use the following code
> which will convert the units for you.
>
> hAxes = findall(hFig,'type','axes');
> hText = findall(hAxes,'type','text');
> hUIControls = findall(gcf,'type','uicontrol');
> set([hAxes; hText;
> hUIControls],'units','normalized','fontunits','normalized');
>
> Then you can just resize the figure, and all the objects will resize
> accordingly. You can, for example, use the screen resolution information to
> adjust your figure to take up a certain percentage of the screen.
>
> If you want the code to look good on multiple operating systems, then,
> depending on your GUI, you may want to use 'character' units for the layout
> and then either convert to normalized at runtime or write your own resize
> function that resizes the objects directly in 'character' units.
>
> Hope that helped,
>
> - Jordan
>
> "Bruce Lee" <spamhole@spam.net> wrote in message
> news:FM2DBn.7vv@bath.ac.uk...
> > Is there an easy way to create a GUI that displays properly in all display
> > modes? I develop in Windows 98 at 1024x768 with large fonts, but if I run
> > the file on another PC at a different resolution the window is too large
> to
> > fit on the screen, or the buttons are misplaced, etc. etc.
> >
> > Do I have to create a GUI for all possible resolutions? Is there any
> > function which returns the currently selected screen resolution and font
> > size in Matlab?
> >
> > *bl
> >
> >
>
>

had problems if i had a uipanel in gui. other than that all is good.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us