mlapptools
is a collection of static methods for customizing the R2016a-introduced web-based uifigure
windows and
associated UI elements through DOM manipulations.
For additional information, see Iliya Romm's Undocumented Matlab guest article, Customizing uifigures part 2, published Wednesday, September 7th, 2016.
- Feature requests/suggestions and bug repots - please feel free to open an issue in the repository.
- General discussion - MATLAB and Octave chatroom on Stack Overflow.
- Specific questions about manipulating uifigures / App Designer apps -
matlab-app-designer
tag on Stack Overflow.
aboutDojo
- Return the dojo toolkit version.
fontColor
- Modify font color.
fontWeight
- Modify font weight.
getHTML
- Return the full HTML code of a uifigure
.
getWebElements
- Extract a webwindow
handle and a widget ID from a uifigure
control handle.
getWebWindow
- Extract a webwindow
handle from a uifigure
handle.
getWidgetInfo
- Gather information about a specific dijit widget.
getWidgetList
- Gather information about all dijit widget in a specified uifigure
.
setStyle
- Modify a specified style property.
setTimeout
- Override the default timeout for dojo commands, for a specific uifigure
.
textAlign
- Modify text alignment.
Returns a struct
containing version information about the Dojo toolkit loaded into the first open uifigure
.
If no uifigure
is open, a temporary window is created, queried, then closed - indicating the default Dojo version.
>> mlapptools.aboutDojo()
ans =
struct with fields:
major: 1
minor: 11
patch: 2
flag: ''
revision: '91fa0cb'
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.
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)');
Set the font weight of the specified UI element, uiElement
, to the input weight string or integer, weight
.
For this setting to have an effect, the font being used must have built-in faces that match the specified weight.
Valid font weight property values are:
'normal'
- Normal characters (default)'bold'
- Thick characters'lighter'
/'bolder'
- The closest available "lighter" or "bolder" weight, relative to the parent.100 .. 900
- Integers mapping to'normal'
,'bold'
, etc. Intermediate integers (and floats) are accepted but generally map to the available values'initial'
- Revert to default
Using the demo GUI generated by ./Demo/DOMdemoGUI.m
myGUI = DOMdemoGUI;
mlapptools.fontWeight(myGUI.TextArea, 'bold');
myGUI = DOMdemoGUI;
mlapptools.fontWeight(myGUI.TextArea, 600);
A method for obtaining the HTML code of a uifigure. Intended for R2017b (and onward?) where the CEF URL cannot be
simply opened in a browser. The returned HTML is a deep copy, meaning that any changes will not modify the
uifigure
where it originated from.
Using the demo GUI generated by ./Demo/DOMdemoGUI.m
myGUI = DOMdemoGUI;
fullHTML = mlapptools.getHTML(myGUI.UIFigure);
web(['text://' fullHTML]);
A method for obtaining the webwindow handle and the widget ID corresponding to the provided uifigure
control. The
widget ID can be used to call the 4-parameter variant of setStyle
.
myGUI = DOMdemoGUI;
[win, widgetID] = mlapptools.getWebElements(myGUI.TextArea);
A method for getting the webwindow handle associated with the provided uifigure
.
Using the demo GUI generated by ./Demo/DOMdemoGUI.m
myGUI = DOMdemoGUI;
win = mlapptools.getWebWindow(myGUI.UIFigure);
Query the dijit registry for a widgets
having a specific ID, and return its details in a scalar cell
containing a struct
.
Using the demo GUI generated by ./Demo/DOMdemoGUI.m
myGUI = DOMdemoGUI;
[win, widgetID] = mlapptools.getWebElements(myGUI.TextArea);
nfo = mlapptools.getWidgetInfo(win, widgetID);
Query the dijit registry for all widgets within the current page, and return them in a cell array of structs.
Using the demo GUI generated by ./Demo/DOMdemoGUI.m
myGUI = DOMdemoGUI;
nfoList = mlapptools.getWidgetList(myGUI.UIFigure);
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.
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)');
Modify the amount of time allotted to dojo queries before they are considered "failed due to timeout". This value is
uifigure
-specific. If left unmodified, the default value is 5
seconds.
myGUI = DOMdemoGUI;
mlapptools.setTimeout(myGUI.UIFigure, 3); % This will wait less for dojo queries to finish.
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
Using the demo GUI generated by ./Demo/DOMdemoGUI.m
myGUI = DOMdemoGUI;
mlapptools.textAlign(myGUI.TextArea, 'center');
myGUI = DOMdemoGUI;
mlapptools.textAlign(myGUI.TextArea, 'right');