/mlapptools

MATLAB class containing methods for programmatic uifigure modification

Primary LanguageMATLAB

mlapptools

mlapptools is an example set of static MATLAB methods for manipulating the DOM underlying the App Designer UI elements formally introduced in R2016a

For additional information, see Iliya Romm's guest Undocumented Matlab article, Customizing uifigures part 2, published Wednesday, September 7th, 2016

Methods

textAlign - Modify text alignment
fontWeight - Modify font weight
fontColor - Modify font folor
setStyle - Modify a specified style property

mlapptools.textAlign(uielement, alignment)

Description

Set the horizontal text alignment of the specified UI element, uielement, to that specified by the input alignment string, alignment.

Valid alignment strings are:

  • 'left' - Left align (default)
  • 'center' - Center align
  • 'right' - Right align
  • 'justify' - Each line has equal width
  • 'initial' - Revert to default
Examples

Using the demo GUI generated by ./Demo/DOMdemoGUI.m

myGUI = DOMdemoGUI;
mlapptools.textAlign(myGUI.TextArea, 'center');
myGUI = DOMdemoGUI;
mlapptools.textAlign(myGUI.TextArea, 'right');

mlapptools.fontWeight(uielement, weight)

Description

Set the font weight of the specified UI element, uielement, to the input weight string or integer, weight.

Valid font weight property values are:

  • 'normal' - Normal characters (default)
  • 'bold' - Thick characters
  • 'bolder' - Thicker characters
  • [400, 600, 800] - Integers mapping to 'normal', 'bold', and 'bolder'. Intermediate integers (and floats) are accepted but generally map to these 3 values
  • 'initial' - Revert to default
Examples

Using the demo GUI generated by ./Demo/DOMdemoGUI.m

myGUI = DOMdemoGUI;
mlapptools.fontWeight(myGUI.TextArea, 'bold');
myGUI = DOMdemoGUI;
mlapptools.fontWeight(myGUI.TextArea, 600);

mlapptools.fontColor(uielement, newcolor)

Description

Set the font color of the specified UI element, 'uielement', to the input color, newcolor. newcolor can be a predefined color string or a string containing a valid CSS color method call.

Valid color specifications are:

  • Hexadecimal colors - e.g. '#ff0000' for red
  • RGB colors - e.g. 'rgb(255,165,0)' for orange
  • RGBA colors - e.g. 'rgba(255,255,0,0.3)' for yellow
  • HSL colors - e.g. 'hsl(120, 100%, 50%)' for green
  • HSLA colors - e.g. 'hsla(240,100%,50%, 1.0)' for blue
  • Predefined color names - e.g. 'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'. For more colors, see the predefined color names CSS color specification.
Examples

Using the demo GUI generated by ./Demo/DOMdemoGUI.m

myGUI = DOMdemoGUI;
mlapptools.fontColor(myGUI.TextArea, 'aqua');
myGUI = DOMdemoGUI;
mlapptools.fontColor(myGUI.TextArea, 'rgb(255,165,0)');

mlapptools.setStyle(uielement, styleAttr, styleValue)

Description

Set the style attribute styleAttr of the specified UI element, 'uielement', to the value styleValue. styleAttr should be any valid CSS attribute, and styleValue a valid setting thereof.

This method provides a general interface to change CSS style attributes, with minimal input testing and error reporting, so it is up to the user to provide valid inputs.

Valid style attributes and corresponding settings can be found here.

Examples

Using the demo GUI generated by ./Demo/DOMdemoGUI.m

myGUI = DOMdemoGUI;
mlapptools.setStyle(myGUI.TextArea, 'background-image',...
 'url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg)');