Add Dynamic Behavior to Masked Icons
Using Graphical Icon Editor, you can add dynamic behavior to masked block icons:
Render multiple variations of the same block icon using parts.
Hide or unhide elements in the icon based on block parameters or mask parameters.
Position icon elements relatively using layout constraints.
View the evaluated value of a block parameter on the block icon.
Create a block icon that dynamically changes size when you resize the block.
Render Multiple Variations of Same Block Icon Using Parts
Use parts in Graphical Icon Editor to store multiple variations of a block icon in a single file. The parts enable you to efficiently organize multiple variations of an image without the need to keep track of multiple files. Create each variation in a separate part. Each variation is visible based on conditions you place on the block or mask parameters.
Consider a masked Subsystem block with the popup parameter set to
portSelection
. The block icon changes based on the value you select for
portSelection in the Block Parameters dialog box. If you specify the
No. of Ports as 3
, an image of a three-switch port
appears on the block icon. If you specify the No. of Ports as
4
, an image of a four-switch port appears on the block icon
To create block icon variations using parts:
Create a mask on the Subsystem block.
In the Mask Editor, in the Controls pane, click Popup to create a popup parameter. In the Property Editor pane, double-click the cell to the right of Type options and select List of options. Add two rows, specify both the Description and Value for the first row as
3
, and specify both the Description and Value for the second row as4
. Click Save.In the Icon tab, click Drawing Commands and select Graphical.
Create an icon with a four-switch port. Double-click the parts name to rename the part as
Four_switch_port
.Click
to duplicate the part. Modify the duplicated part to show a three-switch port. Rename the part as
Three_switch_port
.To control when a particular parts appears as the block icon, enter parts conditions based on the corresponding block parameters by clicking
. In this example, specify the conditions as
portSelection == 3
forThree_switch_port
andportSelection == 4
for the partFour_switch_port
. Click OK.In the Block Parameters dialog box, change the value of the No. of Ports parameter. Observe how the block icon changes based on the value you select for the parameter.
Hide or Unhide Elements in the Icon Based on Block Parameters or Mask Parameters
Hide or unhide elements in the icon by applying certain conditions to the block parameters.
For example, consider a Gain block with matrix values. The elements in the Gain block appear and disappear based on the conditions set on the block parameter.
Set the condition in the following figure where the element uvec
in
the Gain block is visible only when the value of the Multiplication parameter is Matrix_Ku_Vector
.
Note
Visibility conditions support JavaScript expressions only.
Position Elements Relatively Using Layout Constraints
Layout constraints help you to position each icon element relative to other icon
elements on the canvas or the canvas itself. To set layout constraints on the icon elements,
select the element, right-click and select Set Layout
Constraints
. In the Layout Constraints tab, select the
source and relative elements from the drop-down in the pinning panel. Select the
Source element and the Relative to element. Pin
both the Source element and the Relative to element using the pinning panel. Specify the
Offset. Click More to specify complex conditions
to position the elements.
Click Preview in Model to see the effect of layout constraints.
You can also set complex conditions in layout constraints, for example, you can force the left bracket of the matrix in the mask icon of the Gain block to be three pixels to the left of the first element of the matrix.
To set this complex condition:
Right-click the
leftBracket
and select Set Layout Constraints.In the Layout Constraints tab, click More
Set
matrix.left-3
,matrix.top
, andmatrix.bottom
in Right, Top and Bottom respectively.
Text Parameterization
You can view the evaluated value of a block parameter on the block icon. Enter the block parameter name or a placeholder in Parameter/Value that will return the text or value during simulation. To see the evaluated value of a block parameter on the block icon, preview the icon on the Simulink canvas.
For example, to display a parameter value on a block icon:
Create a mask on the block.
In the Parameters & Dialog tab, create a mask parameter
Speed
and specify the value as120
.On the Icon tab, click Drawing Commands and select Graphical.
Create a text element in the canvas. Right-click the text element and select Parameterize.
In the Text Parameterization panel, select Dynamic Text and enter the parameter name,
Speed
in Parameter/Value.Click Editing Behavior. Select
Parameter
in Edit Handler list and specify the Parameter Name asSpeed
.Click Preview in Model and observe that the value of the parameter is displayed on the icon.
Display Elements That Fit Size of Icon
You can create a block icon that dynamically changes sizes when you resize the block.
To group elements under first-fit, select the element in the canvas, right-click and select Convert to First Fit.
For example, the following figure shows a Gain block with four elements of different sizes grouped under a first-fit element. When you resize the block, the element that fits in the size of the Gain block appears as the icon of the block.
To group elements under first-fit, select the element in the canvas, right-click and select Convert to First Fit.