This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Design Cross-Platform UIs in GUIDE

Default System Font

By default, user interface controls (uicontrols) use the default font for the platform on which they are running. For example, when displaying your UI on PCs, uicontrols use MS San Serif. When your program runs on a different platform, it uses that computer's default font. This provides a consistent look with respect to your UI and other applications.

If you have set the FontName property to a named font and want to return to the default value, you can set the property to the string default. This ensures that the software uses the system default at run-time.

You can use the Property Inspector to set this property:

As an alternative, use the set command to set the property in the UI code file. For example, if there is a push button in your UI and its handle is stored in the pushbutton1 field of the handles structure, then the statement


sets the FontName property to use the system default.

Specify a Fixed-Width Font

If you want to use a fixed-width font for a user interface control, set its FontName property to the string fixedwidth. This special identifier ensures that your UI uses the standard fixed-width font for the target platform.

You can find the name of the fixed-width font that is used on a given platform by querying the root FixedWidthFontName property.


Use a Specific Font Name

You can specify an actual font name (such as Times or Courier) for the FontName property. However, doing so may cause your UI to not look as you intended when run on a different computer. If the target computer does not have the specified font, it will substitute another font that may not look good in your UI or may not be the standard font used for UIs on that system. Also, different versions of the same named font may have different size requirements for a given set of characters.

Standard Background Color

The default component background color is the standard system background color on which the UI is displaying. This color varies on different computer systems, e.g., the standard shade of gray on the PC differs from that on UNIX® system, and may not match the default UI background color.

If you use the default component background color, you can use that same color as the background color for your UI. This provides a consistent look with respect to your UI and other applications. To do this in GUIDE, check Options > Use system color scheme for background on the Layout Editor Tools menu.

    Note   This option is available only if you first select the Generate FIG-file and MATLAB File option.

Cross-Platform Compatible Units

Cross-platform compatible UIs should look correct on computers having different screen sizes and resolutions. Since the size of a pixel can vary on different computer displays, using the default figure Units of pixels does not produce a UI that looks the same on all platforms.

For this reason, GUIDE defaults the Units property for the figure to characters.

System-Dependent Units

Character units are defined by characters from the default system font. The width of a character unit equals the width of the letter x in the system font. The height of a character unit is the distance between the baselines of two lines of text. Note that character units are not square.

Units and Resize Behavior

If you set the resize behavior from the GUI Options dialog box, GUIDE automatically sets the units for the UI components in a way that maintains the intended look and feel across platforms. To specify the resize behavior option, select Tools > GUI Options, and select an item from the Resize behavior pop-up menu:

  • If you choose Non-resizable, GUIDE defaults the component units to characters.

  • If you choose Proportional, GUIDE defaults the component units to normalized.

  • If you choose Other (Use SizeChangedFcn), GUIDE defaults the component units to characters. However, you must provide a SizeChangedFcn callback to customize the resize behavior.

The Non-resizable and Proportional options enable your UI to automatically adjust the size and relative spacing of components when the UI displays on different computers.

    Note   GUIDE does not automatically adjust component units if you modify the figure's Resize property programmatically or in the Property Inspector.

At times, it might be convenient to use a more familiar unit of measure, e.g., inches or centimeters, when you are laying out the UI. However, to preserve the look of your UI on different computers, remember to change the figure Units property back to characters, and the components' Units properties to characters (nonresizable UIs) or normalized (resizable UIs) before you save the UI.

Was this topic helpful?