class MenuBar
package feathers.controls
extends FeathersControl › MeasureSprite › ValidatingSprite
implements IFocusObject, IIndexSelector, IDataSelector<Dynamic>
A menu bar.
The following example sets the data provider, tells the item renderers how to interpret the data, and listens for when an item renderer is triggered:
var menuBar = new MenuBar();
menuBar.dataProvider = new ArrayHierarchicalCollection<MenuItemData>([
{
text: "File",
children: [
{ text: "New" },
{ text: "Open" },
{ separator: true },
{ text: "Save" },
{ text: "Quit" }
]
},
{
text: "Help",
children: [
{ text: "Contents" },
{ text: "About" }
]
}
], (item:MenuItemData) -> item.children);
menuBar.itemToText = (item:MenuItemData) -> {
return item.text;
};
menuBar.itemToSeparator = (item:MenuItemData) -> {
return item.separator;
};
menuBar.addEventListener(MenuEvent.ITEM_TRIGGER, menuBar_itemTriggerHandler);
this.addChild(menuBar);
The example above uses the following custom Haxe typedef.
typedef MenuItemData = {
?text:String,
?children:Array<MenuItemData>,
?separator:Bool
}
Events:
feathers.events.MenuEvent.ITEM_TRIGGER | Dispatched when the user taps or clicks a menu item renderer. The pointer must remain within the bounds of the item renderer on release, or the gesture will be ignored. |
---|---|
feathers.events.MenuEvent.MENU_OPEN | Dispatched when a menu opens. |
feathers.events.MenuEvent.MENU_CLOSE | Dispatched when a menu closes. |
1.4.0
.See also:
feathers.controls.Menu
Static variables
staticfinalread onlyCHILD_VARIANT_ITEM_RENDERER:String = "menuBar_itemRenderer"
The variant used to style the item renderer child components in a theme.
To override this default variant, set the
MenuBar.customItemRendererVariant
property.
1.4.0
.See also:
Constructor
new(?dataProvider:IHierarchicalCollection<Dynamic>, ?itemTriggerListener:MenuEvent ‑> Void)
Creates a new MenuBar
object.
1.4.0
.Variables
backgroundSkin:DisplayObject
The default background skin to display behind the item renderers.
The following example passes a bitmap for the menu bar to use as a background skin:
menuBar.backgroundSkin = new Bitmap(bitmapData);
1.4.0
.See also:
customItemRendererVariant:String
A custom variant to set on all item renderers, instead of
MenuBar.CHILD_VARIANT_ITEM_RENDERER
.
The customItemRendererVariant
will be not be used if the result of
itemRendererRecycler.create()
already has a variant set.
1.4.0
.See also:
dataProvider:IHierarchicalCollection<Dynamic>
The collection of data displayed by the menu 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 item renderers how to interpret the data:
menuBar.dataProvider = new ArrayHierarchicalCollection([
{ text: "Latest Posts" },
{ text: "Profile" },
{ text: "Settings" }
]);
menuBar.itemToText = (item:Dynamic) -> {
return item.text;
};
1.4.0
.See also:
disabledBackgroundSkin:DisplayObject
A background skin to display behind the item renderers when the menu bar is disabled.
The following example gives the menu bar a disabled background skin:
menuBar.disabledBackgroundSkin = new Bitmap(bitmapData);
menuBar.enabled = false;
1.4.0
.See also:
forceItemStateUpdate:Bool
Forces the itemRendererRecycler.update()
method to be called with the
MenuItemState
when the menu 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.4.0
.itemRendererRecycler:AbstractDisplayObjectRecycler<Dynamic, MenuItemState, DisplayObject>
Manages item renderers used by the menu bar.
In the following example, the menu bar uses a custom item renderer class:
menuBar.itemRendererRecycler = DisplayObjectRecycler.withClass(MyCustomItemRenderer);
1.4.0
.layout:ILayout
The layout algorithm used to position and size the item renderers.
By default, if no layout is provided by the time that the menu bar initializes, a default layout that displays items horizontally will be created.
The following example tells the menu bar to use a custom layout:
var layout = new HorizontalDistributedLayout();
layout.maxItemWidth = 300.0;
menuBar.layout = layout;
1.4.0
.separatorRecycler:AbstractDisplayObjectRecycler<Dynamic, MenuItemState, DisplayObject>
Manages item renderers used by the menu bar.
In the following example, the menu bar uses a custom item renderer class:
menuBar.itemRendererRecycler = DisplayObjectRecycler.withClass(MyCustomItemRenderer);
1.4.0
.itemRendererRecyclerIDFunction:(state:MenuItemState) ‑> String
When a menu bar requires multiple item renderer styles, this function is
used to determine which style of item renderer is required for a
specific item. Returns the ID of the item renderer recycler to use for
the item, or null
if the default itemRendererRecycler
should be used.
The following example provides an itemRendererRecyclerIDFunction
:
var regularItemRendererRecycler = DisplayObjectRecycler.withClass(ItemRenderer);
var firstItemRendererRecycler = DisplayObjectRecycler.withClass(MyCustomItemRenderer);
menuBar.setItemRendererRecycler("regular-item", regularItemRendererRecycler);
menuBar.setItemRendererRecycler("first-item", firstItemRendererRecycler);
menuBar.itemRendererRecyclerIDFunction = function(state:MenuItemState):String {
if(state.index == 0) {
return "first-item";
}
return "regular-item";
};
1.4.0
.See also:
`MenuBar.itemRendererRecycler
itemToEnabled:Dynamic ‑> Bool
Determines if an item renderer should be enabled or disabled. By
default, all items are enabled, unless the MenuBar
is disabled. Thi
method may be replaced to provide a custom value for enabled
.
For example, consider the following item:
{ text: "Example Item", disable: true }
If the MenuBar
should disable an item if the disable
field is
true
, a custom implementation of itemToEnabled()
might look like
this:
menuBar.itemToEnabled = (item:Dynamic) -> {
return !item.disable;
};
1.4.0
.itemToSeparator:Dynamic ‑> Bool
Determines if an item represents a separator menu item.
For example, consider the following item:
var fileItems:Array<Dynamic> = [
{ text: "Open" },
{ separator: true },
{ text: "Quit" },
];
If the MenuBar
should display some items as separators, a custom
implementation of itemToSeparator()
might look like this:
menuBar.itemToSeparator = (item:Dynamic) -> {
return Reflect.hasField(item, "separator") && Reflect.field(item, "separator") == true;
};
1.4.0
.itemToText:Dynamic ‑> String
Converts an item to text to display within menu 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 MenuBar
should display the text "Example Item", a custom
implementation of itemToText()
might look like this:
menuBar.itemToText = (item:Dynamic) -> {
return item.text;
};
1.4.0
.Methods
getItemRendererRecycler(id:String):DisplayObjectRecycler<Dynamic, MenuItemState, DisplayObject>
Returns the item renderer recycler associated with a specific ID.
Returns null
if no recycler is associated with the ID.
1.4.0
.See also:
indexToItemRenderer(index:Int):DisplayObject
Returns the current item renderer used to render the item at the
specified index in the data provider. May return null
if an item doesn't
currently have an item renderer.
1.4.0
.itemToItemRenderer(item:Dynamic):DisplayObject
Returns the current item renderer used to render a specific item from
the data provider. May return null
if an item doesn't currently have
an item renderer.
1.4.0
.itemToItemState(item:Dynamic):MenuItemState
Returns a MenuItemState
representing a specific item.
1.4.0
.setItemRendererRecycler(id:String, recycler:AbstractDisplayObjectRecycler<Dynamic, MenuItemState, DisplayObject>):Void
Associates an item renderer recycler with an ID to allow multiple types
of item renderers to be displayed in the menu bar. A custom
itemRendererRecyclerIDFunction
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.4.0
.See also: