class ButtonBar
package feathers.controls
extends FeathersControl › MeasureSprite › ValidatingSprite
A grouping of buttons.
The following example sets the data provider, tells the buttons how to interpret the data, and listens for when a button is triggered:
var buttonBar = new ButtonBar();
buttonBar.dataProvider = new ArrayCollection([
{ text: "Latest Posts" },
{ text: "Profile" },
{ text: "Settings" }
]);
buttonBar.itemToText = (item:Dynamic) -> {
return item.text;
};
buttonBar.addEventListener(ButtonBarEvent.ITEM_TRIGGER, buttons_itemTriggerHandler);
this.addChild(buttonBar);
Events:
feathers.events.ButtonBarEvent.ITEM_TRIGGER | Dispatched when the user taps or clicks a button. The pointer must remain within the bounds of the tab on release, or the gesture will be ignored. |
---|
1.0.0
.See also:
Static variables
staticfinalread onlyCHILD_VARIANT_BUTTON:String = "buttonBar_button"
The variant used to style the button child components in a theme.
To override this default variant, set the
ButtonBar.customButtonVariant
property.
1.0.0
.See also:
Constructor
new(?dataProvider:IFlatCollection<Dynamic>, ?itemTriggerListener:ButtonBarEvent ‑> Void)
Creates a new ButtonBar
object.
1.0.0
.Variables
backgroundSkin:DisplayObject
The default background skin to display behind the buttons.
The following example passes a bitmap for the button bar to use as a background skin:
buttonBar.backgroundSkin = new Bitmap(bitmapData);
1.0.0
.See also:
buttonRecycler:AbstractDisplayObjectRecycler<Dynamic, ButtonBarItemState, Button>
Manages buttons used by the button bar.
In the following example, the button bar uses a custom button renderer class:
buttonBar.buttonRecycler = DisplayObjectRecycler.withClass(Button);
1.0.0
.customButtonVariant:String
A custom variant to set on all buttons, instead of
ButtonBar.CHILD_VARIANT_BUTTON
.
The customButtonVariant
will be not be used if the result of
buttonRecycler.create()
already has a variant set.
1.0.0
.See also:
dataProvider:IFlatCollection<Dynamic>
The collection of data displayed by the button bar.
Items in the collection must be class instances or anonymous structures. Do not add primitive values (such as strings, booleans, or numeric values) directly to the collection.
Additionally, all items in the collection must be unique object instances. Do not add the same instance to the collection more than once because a runtime exception will be thrown.
The following example passes in a data provider and tells the buttons how to interpret the data:
buttonBar.dataProvider = new ArrayCollection([
{ text: "Latest Posts" },
{ text: "Profile" },
{ text: "Settings" }
]);
buttonBar.itemToText = (item:Dynamic) -> {
return item.text;
};
1.0.0
.See also:
disabledBackgroundSkin:DisplayObject
A background skin to display behind the buttons when the button bar is disabled.
The following example gives the button bar a disabled background skin:
buttonBar.disabledBackgroundSkin = new Bitmap(bitmapData);
buttonBar.enabled = false;
1.0.0
.See also:
forceItemStateUpdate:Bool
Forces the buttonRecycler.update()
method to be called with the
ButtonBarItemState
when the button bar validates, even if the item's
state has not changed since the previous validation.
Before Feathers UI 1.2, update()
was called more frequently, and this
property is provided to enable backwards compatibility, temporarily, to
assist in migration from earlier versions of Feathers UI.
In general, when this property needs to be enabled, its often because of
a missed call to dataProvider.updateAt()
(preferred) or
dataProvider.updateAll()
(less common).
The forceItemStateUpdate
property may be removed in a future major
version, so it is best to avoid relying on it as a long-term solution.
1.2.0
.layout:ILayout
The layout algorithm used to position and size the buttons.
By default, if no layout is provided by the time that the button bar initializes, a default layout that displays items horizontally will be created.
The following example tells the button bar to use a custom layout:
var layout = new HorizontalDistributedLayout();
layout.maxItemWidth = 300.0;
buttonBar.layout = layout;
1.0.0
.buttonRecyclerIDFunction:(state:ButtonBarItemState) ‑> String
When a button bar requires multiple button styles, this function is used
to determine which style of button is required for a specific item.
Returns the ID of the button recycler to use for the item, or null
if
the default buttonRecycler
should be used.
The following example provides an buttonRecyclerIDFunction
:
var regularButtonRecycler = DisplayObjectRecycler.withClass(Button);
var firstButtonRecycler = DisplayObjectRecycler.withClass(MyCustomButton);
buttonBar.setButtonRecycler("regular-button", regularButtonRecycler);
buttonBar.setButtonRecycler("first-button", firstButtonRecycler);
buttonBar.buttonRecyclerIDFunction = function(state:ButtonBarItemState):String {
if(state.index == 0) {
return "first-button";
}
return "regular-button";
};
1.0.0
.See also:
`ButtonBar.buttonRecycler
Methods
getButtonRecycler(id:String):DisplayObjectRecycler<Dynamic, ButtonBarItemState, Button>
Returns the button recycler associated with a specific ID. Returns
null
if no recycler is associated with the ID.
1.0.0
.See also:
indexToButton(index:Int):Button
Returns the current button used to render the item at the specified
index in the data provider. May return null
if an item doesn't
currently have a button.
1.0.0
.itemToButton(item:Dynamic):Button
Returns the current button used to render a specific item from the data
provider. May return null
if an item doesn't currently have a button.
1.0.0
.dynamicitemToEnabled(data:Dynamic):Bool
Determines if a button should be enabled or disabled. By default, all
items are enabled, unless the ButtonBar
is disabled. This method
may be replaced to provide a custom value for enabled
.
For example, consider the following item:
{ text: "Example Item", disable: true }
If the ButtonBar
should disable an item if the disable
field is
true
, a custom implementation of itemToEnabled()
might look like
this:
buttonBar.itemToEnabled = (item:Dynamic) -> {
return !item.disable;
};
1.2.0
.dynamicitemToText(data:Dynamic):String
Converts an item to text to display within button bar. By default, the
toString()
method is called to convert an item to text. This method
may be replaced to provide custom text.
For example, consider the following item:
{ text: "Example Item" }
If the ButtonBar
should display the text "Example Item", a custom
implementation of itemToText()
might look like this:
buttonBar.itemToText = (item:Dynamic) -> {
return item.text;
};
1.0.0
.setButtonRecycler(id:String, recycler:AbstractDisplayObjectRecycler<Dynamic, ButtonBarItemState, Button>):Void
Associates an button recycler with an ID to allow multiple types
of buttons to be displayed in the button bar. A custom
buttonRecyclerIDFunction
may be specified to return the ID of the
recycler to use for a specific item in the data provider.
To clear a recycler, pass in null
as the value.
1.0.0
.See also: