How to create switch buttons with changing colors

<< Click to Display Table of Contents >>

Navigation:  How To >

How to create switch buttons with changing colors

You want to create buttons that activate and deactivate certain settings (like a switch). The background color of the button should indicate if the setting is activated or not.

 

Create a button object

Set the property Latching to true

If applicable, put a String Field or a Picture Graphic object into the button (set them to transparent to still see the button background)

Put a script with the following code into the OnPress event of the button:

setProperty(<button_ID>, "Background Color", <"pressed" color in [r,g,b,a] array format>);

Put a script with the following code into the OnRelease event of the button:

setProperty(<button_ID>, "Background Color", <"released" color in [r,g,b,a] array format>);

 

If the button background color shouldn't change directly when the button is pressed but instead after a confirmation message from the CAN bus, put the script on the OnValueChangeByOwner event of the related variable.