class ToggleButton
package feathers.controls
extends BasicToggleButton › FeathersControl › MeasureSprite › ValidatingSprite
implements IFocusObject, ITextControl
extended by ItemRenderer, Check, Radio
A button that may be selected and deselected when clicked.
The following example creates a toggle button, programmatically selects it, and listens for when the selection changes:
var button = new ToggleButton();
button.text = "Click Me";
button.selected = true;
button.addEventListener(Event.CHANGE, (event) -> {
var button = cast(event.currentTarget, ToggleButton);
trace("toggle button changed: " + button.selected);
});
this.addChild(button);
1.0.0
.See also:
Constructor
Variables
disabledIcon:DisplayObject
The icon to display when the button is disabled, and no higher
priority icon was passed to setIconForState()
for the button's current
state.
In the following example, the button's disabled icon is changed:
button.enabled = false;
button.disabledIcon = new Bitmap(bitmapData);
The next example sets a disabled icon, but also provides an icon for
the ToggleButtonState.DISABLED(true)
state that will be used instead
of the disabled icon:
button.disabledIcon = new Bitmap(bitmapData);
button.setIconForState(ToggleButtonState.DISABLED(true), new Bitmap(bitmapData2));
Note: If the current state is ToggleButtonState.DISABLED(true)
, and
both the disabledIcon
and selectedIcon
are set, the disabledIcon
takes precedence over the selectedIcon
.
1.0.0
.See also:
disabledTextFormat:AbstractTextFormat
The font styles used to render the button's text when the button is disabled.
In the following example, the button's disabled text formatting is customized:
button.enabled = false;
button.disabledTextFormat = new TextFormat("Helvetica", 20, 0xee0000);
The next example sets a disabled text format, but also provides a text
format for the ToggleButtonState.DISABLED(true)
state that will be
used instead of the disabled text format:
button.disabledTextFormat = new TextFormat("Helvetica", 20, 0xee0000);
button.setTextFormatForState(ToggleButtonState.DISABLED(true), new TextFormat("Helvetica", 20, 0xff0000));
Note: If the current state is ToggleButtonState.DISABLED(true)
, and
both the disabledTextFormat
and selectedTextFormat
are set, the
disabledTextFormat
takes precedence over the selectedTextFormat
.
1.0.0
.See also:
embedFonts:Bool
Determines if an embedded font is used or not.
In the following example, the button uses embedded fonts:
button.embedFonts = true;
1.0.0
.See also:
gap:Float
The space, measured in pixels, between the button's icon and its text.
Applies to either horizontal or vertical spacing, depending on the value
of iconPosition
.
If the gap
is set to Math.POSITIVE_INFINITY
, the icon and the text
will be positioned as far apart as possible. In other words, they will
be positioned at the edges of the button (adjusted for padding).
The following example creates a gap of 20 pixels between the icon and the text:
button.text = "Click Me";
button.icon = new Bitmap(bitmapData);
button.gap = 20.0;
1.0.0
.See also:
horizontalAlign:HorizontalAlign
How the content is positioned horizontally (along the x-axis) within the button.
The following example aligns the button's content to the left:
button.verticalAlign = LEFT;
Note: The HorizontalAlign.JUSTIFY
constant is not supported by this
component.
See also:
icon:DisplayObject
The display object to use as the button's icon.
To render a different icon depending on the button's current state,
pass additional icons to setIconForState()
.
The following example gives the button an icon:
button.icon = new Bitmap(bitmapData);
To change the position of the icon relative to the button's text, see
iconPosition
and gap
.
button.icon = new Bitmap(bitmapData);
button.iconPosition = RIGHT;
button.gap = 20.0;
1.0.0
.See also:
iconOffsetX:Float
Offsets the x position of the icon by a certain number of pixels. This does not affect the measurement of the button. The button's width will not get smaller or larger when the icon is offset from its default x position.
The following example offsets the x position of the button's icon by 20 pixels:
button.iconOffsetX = 20.0;
1.0.0
.See also:
iconOffsetY:Float
Offsets the y position of the icon by a certain number of pixels. This does not affect the measurement of the button. The button's height will not get smaller or larger when the icon is offset from its default y position.
The following example offsets the y position of the button's icon by 20 pixels:
button.iconOffsetY = 20.0;
1.0.0
.See also:
iconPosition:RelativePosition
The location of the button's icon, relative to its text.
The following example positions the icon to the right of the text:
button.text = "Click Me";
button.icon = new Bitmap(texture);
button.iconPosition = RIGHT;
1.0.0
.See also:
minGap:Float
If the value of the gap
property is Math.POSITIVE_INFINITY
, meaning
that the gap will fill as much space as possible and position the icon
and text on the edges of the button, the final calculated value of the
gap will not be smaller than the value of the minGap
property.
The following example ensures that the gap is never smaller than 20 pixels:
button.gap = Math.POSITIVE_INFINITY;
button.minGap = 20.0;
1.0.0
.See also:
paddingBottom:Float
The minimum space, in pixels, between the button's bottom edge and the button's content.
In the following example, the button's bottom padding is set to 20 pixels:
button.paddingBottom = 20.0;
1.0.0
.paddingLeft:Float
The minimum space, in pixels, between the button's left edge and the button's content.
In the following example, the button's left padding is set to 20 pixels:
button.paddingLeft = 20.0;
1.0.0
.paddingRight:Float
The minimum space, in pixels, between the button's right edge and the button's content.
In the following example, the button's right padding is set to 20 pixels:
button.paddingRight = 20.0;
1.0.0
.paddingTop:Float
The minimum space, in pixels, between the button's top edge and the button's content.
In the following example, the button's top padding is set to 20 pixels:
button.paddingTop = 20.0;
1.0.0
.selectedIcon:DisplayObject
The icon to display when the button is selected, and no higher
priority icon was passed to setIconForState()
for the button's current
state.
In the following example, the button's selected icon is changed:
button.selected = true;
button.selectedIcon = new Bitmap(bitmapData);
The next example sets a selected icon, but also provides an icon for
the ToggleButtonState.DOWN(true)
state that will be used instead of
the selected icon:
button.selectedIcon = new Bitmap(bitmapData);
button.setIconForState(ToggleButtonState.DOWN(true), new Bitmap(bitmapData2));
Note: If the current state is ToggleButtonState.DISABLED(true)
, and
both the disabledIcon
and selectedIcon
are set, the disabledIcon
takes precedence over the selectedIcon
.
1.0.0
.See also:
selectedTextFormat:AbstractTextFormat
The font styles used to render the button's text when the button is selected.
In the following example, the button's selected text formatting is customized:
button.selected = true;
button.selectedTextFormat = new TextFormat("Helvetica", 20, 0xff0000);
The next example sets a selected text format, but also provides a text
format for the ToggleButtonState.DOWN(true)
state that will be used
instead of the selected text format:
button.selectedTextFormat = new TextFormat("Helvetica", 20, 0xff0000);
button.setTextFormatForState(ToggleButtonState.DOWN(true), new TextFormat("Helvetica", 20, 0xcc0000));
Note: If the current state is ToggleButtonState.DISABLED(true)
, and
both the disabledTextFormat
and selectedTextFormat
are set, the
disabledTextFormat
takes precedence over the selectedTextFormat
.
1.0.0
.See also:
text:String
The text displayed by the button.
The following example sets the button's text:
button.text = "Click Me";
1.0.0
.See also:
textFormat:AbstractTextFormat
The font styles used to render the button's text.
In the following example, the button's text formatting is customized:
button.textFormat = new TextFormat("Helvetica", 20, 0xcc0000);
1.0.0
.See also:
textOffsetX:Float
Offsets the x position of the text by a certain number of pixels. This does not affect the measurement of the button. The button's width will not get smaller or larger when the text is offset from its default x position. Nor does it change the size of the text, so the text may appear outside of the button's bounds if the offset is large enough.
The following example offsets the x position of the button's text by 20 pixels:
button.textOffsetX = 20.0;
1.0.0
.See also:
textOffsetY:Float
Offsets the y position of the text by a certain number of pixels. This does not affect the measurement of the button. The button's height will not get smaller or larger when the text is offset from its default y position. Nor does it change the size of the text, so the text may appear outside of the button's bounds if the offset is large enough.
The following example offsets the y position of the button's text by 20 pixels:
button.textOffsetY = 20.0;
1.0.0
.See also:
verticalAlign:VerticalAlign
How the content is positioned vertically (along the y-axis) within the button.
The following example aligns the button's content to the top:
button.verticalAlign = TOP;
Note: The VerticalAlign.JUSTIFY
constant is not supported by this
component.
See also:
Methods
getIconForState(state:ToggleButtonState):DisplayObject
Gets the icon to be used by the button when its currentState
property
matches the specified state value.
If an icon is not defined for a specific state, returns null
.
1.0.0
.See also:
getTextFormatForState(state:ToggleButtonState):AbstractTextFormat
Gets the text format to be used by the button when its currentState
property matches the specified state value.
If a text format is not defined for a specific state, returns null
.
1.0.0
.See also:
setIconForState(state:ToggleButtonState, icon:DisplayObject):Void
Set the icon to be used by the button when its currentState
property
matches the specified state value.
If an icon is not defined for a specific state, the value of the
textFormat
property will be used instead.
1.0.0
.See also:
setTextFormatForState(state:ToggleButtonState, textFormat:AbstractTextFormat):Void
Set the text format to be used by the button when its currentState
property matches the specified state value.
If a text format is not defined for a specific state, the value of the
textFormat
property will be used instead.
1.0.0
.See also: