class ToggleSwitch
package feathers.controls
extends FeathersControl › MeasureSprite › ValidatingSprite
implements IFocusObject, IToggle
Similar to a light switch, with on and off states that may be toggled.
An alternative to a Check
, especially on mobile.
The following example creates a toggle switch, programmatically selects it, and listens for when the selection changes:
var toggleSwitch = new ToggleSwitch();
toggleSwitch.selected = true;
toggleSwitch.addEventListener(Event.CHANGE, (event) -> {
var toggleSwitch = cast(event.currentTarget, ToggleSwitch);
trace("toggle switch changed: " + toggleSwitch.selected);
});
this.addChild(toggleSwitch);
Events:
openfl.events.Event.CHANGE | Dispatched when |
---|
1.0.0
.See also:
Constructor
new(selected:Bool = false, ?changeListener:Event ‑> Void)
Creates a new ToggleSwitch
object.
1.0.0
.Variables
disabledTextFormat:AbstractTextFormat
The font styles used to render the toggle switch's text when the toggle switch is disabled.
In the following example, the toggle switch's disabled text formatting is customized:
toggleSwitch.enabled = false;
toggleSwitch.disabledTextFormat = new TextFormat("Helvetica", 20, 0xee0000);
1.3.0
.See also:
embedFonts:Bool
Determines if an embedded font is used or not.
In the following example, the toggle switch uses embedded fonts:
toggleSwitch.embedFonts = true;
1.3.0
.See also:
offText:String
The text displayed by the toggle switch when it is toggled off. If
null
, no text is displayed.
The following example sets the label's off text:
label.offText = "OFF";
1.3.0
.See also:
onText:String
The text displayed by the toggle switch when it is toggled on. If
null
, no text is displayed.
The following example sets the label's on text:
label.onText = "ON";
1.3.0
.See also:
paddingLeft:Float
The minimum space, measured in pixels, between the toggle switch's left edge and the left edge of the thumb.
In the following example, the toggle switch's left padding is set to 20 pixels:
toggleSwitch.paddingLeft = 20.0;
1.0.0
.paddingRight:Float
The minimum space, measured in pixels, between the toggle switch's right edge and the right edge of the thumb.
In the following example, the toggle switch's right padding is set to 20 pixels:
toggleSwitch.paddingRight = 20.0;
1.0.0
.secondaryTrackSkin:DisplayObject
The skin to use for the toggle switch's optional secondary track. If a toggle switch has one track, it will fill the entire length of the toggle switch. If a toggle switch has a track and a secondary track, the primary track will stretch between the left edge of the toggle switch and the location of the slider's thumb, while the secondary track will stretch from the location of the toggle switch's thumb to the right edge of the toggle switch.
In the following example, a track skin and a secondary track skin are passed to the toggle switch:
var skin = new RectangleSkin();
skin.fill = SolidColor(0xaaaaaa);
toggleSwitch.trackSkin = skin;
var skin = new RectangleSkin();
skin.fill = SolidColor(0xcccccc);
toggleSwitch.secondaryTrackSkin = skin;
1.0.0
.See also:
selected:Bool
Indicates if the toggle switch is selected or not.
The following example selects the toggle switch:
toggleSwitch.selected = true;
Note: When changing the selected
property programatically, the
position of the thumb is not animated. To change the selection with
animation, call the setSelectionWithAnimation()
method.
1.0.0
.See also:
textFormat:AbstractTextFormat
The font styles used to render the toggle switch's text.
In the following example, the toggle switch's text formatting is customized:
toggleSwitch.textFormat = new TextFormat("Helvetica", 20, 0xcc0000);
1.3.0
.See also:
thumbSkin:DisplayObject
The skin to use for the toggle switch's thumb.
In the following example, a thumb skin is passed to the toggle switch:
var skin = new RectangleSkin();
skin.fill = SolidColor(0xcccccc);
toggleSwitch.thumbSkin = skin;
1.0.0
.See also:
toggleDuration:Float
The duration, measured in seconds, of the animation when the toggle switch is clicked or tap and the thumb slides to the other side.
In the following example, the duration of the animation that toggles the thumb is set to 500 milliseconds:
toggleSwitch.toggleDuration = 0.5;
1.0.0
.toggleEase:IEasing
The easing function used for the animation when the toggle switch is clicked or tap and the thumb slides to the other side.
In the following example, the ease of the animation that toggles the thumb is customized:
toggleSwitch.toggleEase = Elastic.easeOut;
1.0.0
.trackSkin:DisplayObject
The skin to use for the toggle switch's track.
In the following example, a track skin is passed to the toggle switch:
var skin = new RectangleSkin();
skin.fill = SolidColor(0xcccccc);
toggleSwitch.trackSkin = skin;
1.0.0
.See also:
Methods
setPadding(value:Float):Void
Sets all padding properties to the same value.
1.0.0
.See also:
setSelectionWithAnimation(selected:Bool):Bool
Changes the selected
property and animates the position of the thumb.
1.0.0
.See also: