Navigation: Image Controls >

Image Toggle Button

 

 

 

 

General
An Image Toggle Button control is a GUI control that may be selected to be checked ON or OFF by clicking on it, but unlike the standard one, images are assigned to it. Reading the value of the Image Toggle Button, [controlName], returns a 0 or 1 for OFF and ON respectively for its state property (also the default property). It may be set in code using !controlName=0 or !controlName=1.  Additionally, it may be assigned a hotKey such that using ALT-key will activate the control, and if the key is in the name, it will be underscored, such as using a hotKey of H in control with text of Heater or P in a control with the text of Pump.

Unlike the standard Button, the Image Button is assigned images for the normal view (icon property), the mouse-over or hover image (iconHover property) and the pressed image (iconOn property). These may come from the media directory of MakerPlotJ or any image file on the computer. If you wish to make your interface package portable, please see Portable Interface Packages.


The above shows Heater control is 'OFF' and the Pump is 'ON' (note the difference in image colors), with their hotKey letters underscored.

The style of the control allows the text to be below the image (textBelowIcon property) or trailing the image (textTrailsIcon property). Note that the icon height and width percentage properties as well as the font color may need to be adjusted, or simply select a pre-made one from the palette.

 

Image Toggle Button Creation
Image Toggle Button controls may be placed on the main or children interfaces using the Controls Palette, use F2 to open. When placing it, it will ask for the name of the control, itglb is the recommended prefix for the name, such as itglbPower. It will also ask for the text for the control to have. Once done, click a location or draw to desired size. Like most controls, the font size will be based on the height of the control.

An Image Toggle Button may also be created using code, such as from the file save, the Debug/CLI window, the microcontroller sending the string or other controls.
 !makeImgToggleButton Name, Left, Right (,Width, Height, Text, HotKey)     Parameters in () may be omitted.

If it is to be on a child interface:
 !interfaceName.makeImgToggleButton Name, Left, Right (,Width, Height, Text, HotKey)     Parameters in () may be omitted.

Example:
 !makeImgToggleButton tglbPower, 20,20,25,5,Power,P

Once placed, it may be repositioned and resized by unlocking the interface’s controls, F9, and dragging/sizing it. It may be copied or deleted by placing your mouse pointer over it and using CTRL-C and CTRL-X, and pasted using CTRL-V.

Instructions:
Instructions are used to inform the control to perform some operation. The Image Toggle Button control has no special instructions beyond the basic ones of all controls. See Instructions for more information on instructions.

 

Properties
Properties are the look, ‘feel’, and other characteristics of a control or object. They may be viewed or set using the Debug/CLI or the Interface Editor. Placing the mouse pointer over a control and pressing F3 will open the Interface Editor. Here you may view all accessible properties of the Image Toggle Button control, and modify them as desired. Please see the Interface Editor page for more information on the editor.

Properties may be set in code using:
 !controlName.property=someValue
 The default property, value, may be set with:
 !controlName=someValue

They may be read in code using:
 [controlName.property]
 The default property, state, may be read with: [controlName]

When used in its Event Code, [this] may be used in place of the controlName for reads and writes.

As discussed at the top, the images for normal, hover and on may be changed as well as setting text below or trailing the icon.

 

Update Value
 The update value will cause the control to update to a specified value each time analog, digital or message string are processed.

For example, using [din0] will cause the control’s state to be updated to the left-most (MSB) digital value when a string such as %001 is processed.

Other properties, such as its backColor can be updated by specifying it as the property:
 .backColor=[ain0]   // value from 0 to 2 billion

Math may be used in the Update Value, such as { ![din0] } for inverting the value (0 becomes 1 and 1 becomes 0).

 

Event Code
For an Image Toggle Button, the Event Code will run when the Image Toggle Button is clicked. Please see Event Code for a full discussion on event code. In many cases it may have no code and simply be read by another element’s code or simply be used to set the state of some control’s Boolean property.
 !plot.plotOn=[[this]]
 

The use of !this.someCommand or !this.someProperty in the event code refers to the control that is running it, as does [this.someProperty] or [this] for the control’s name and [[this]] for the control’s default value. This allows controls to have the same generic code for unique purposes and reduce coding issues, such as if the name is changed.

Double-Clicking the text area will open the Code Editor where, like the Debug/CLI, it can provide contextual help and suggestions. Please see the Code Editor page for more information.

The code for the control can be executed from other code in the interface using:
 !controlName.run

Activating the Image Toggle Button with a click or hotKey will trigger its normal event code when clicked.

The control also supports <load> event trigger, which will run its code when the !runLoad instruction is issued which goes to all control or !control.run <load> is used which will trigger the specific control. This could be used to ensure the control is off or on when loaded or to reset it back to a default value:
 <load>![this]=0

The Image Toggle Button also supports event triggers of <on> and <off> representing the new state of the control.

Please see advanced topics on using event triggers and passing data to events.
 <on> ? [this] is on
 <off> ? [this] is off

Supported Event Triggers:
 A ToggleButton click or hotKey, no trigger identifier used.
 <load>  Issued when an interface is finished loading or manually with !runLoad.
 <on>                     Issued when the user selects the control.
 <off>                    Issued when the user de-selects the control.

 

More Information:

There exist multiple means of getting information about specific control values, properties, instructions, and events. The Control Editor shown above has abbreviated descriptions in the right-hand column. Expand the window and column to see more at once.

The Controls Viewer allows users to see detailed on controls. Open using F9 and expand out to find the information of interest including examples of use.

The Debug/CLI and Code Editor also provide contextual help. Please see those pages on using them for help.

 

 

 

 

Copyright © 2024 SelmaWare Solutions, LLC