Skip to end of metadata
Go to start of metadata

This is a sub-class of Widget

The functions and fields of the widget class are also available for the Switch class. For instance you can assign an actionListener to the Switch which will be called when the value changes.

Constructor

mgf.createSwitch( [font] )

ParameterTypeDescription
fontFontThe font of the label of the button
Contructor example
switch = mgf.createSwitch()

Fields

FieldTypeDescriptionRead/Write
valueBooleanThe current state (true or false) of the switch.Read/Write

Functions

Switch does not support any additional functions.

Actions

ActionValueDescription
Switch value changed1Switch state changed to on.
Switch value changed0Switch state changed to off.

Examples

Example: Switch action listener
-- Execute this function when the switch state is changed
function switchListenerFunction( widget, action )
    print( "Switch state changed: ", action )
  	print( "New state: ", widget.value )
end
 
label = mgf.createLabel( "Change switch" )
 
switch = mgf.createSwitch()
switch.value = true
switch.actionListener = switchListenerFunction
 
panel = mgf.createPanel()
panel:addWidget( label, 0, 100, 240, 30 )
panel:addWidget( switch, 80, 150, 80, 29 )
mgf.setWidget( panel )
  • No labels