Packagefeathers.layout
Classpublic class AnchorLayout
InheritanceAnchorLayout Inheritance starling.events.EventDispatcher
Implements ILayout

Product Version : Feathers 1.1.0

Positions and sizes items by anchoring their edges (or center points) to their parent container or to other items.

See also

How to use AnchorLayout with Feathers containers
AnchorLayoutData


Public Properties
 PropertyDefined By
  requiresLayoutOnScroll : Boolean
[read-only] Determines if the container calls layout() when the scroll position changes.
AnchorLayout
Public Methods
 MethodDefined By
  
Constructor.
AnchorLayout
  
calculateNavigationDestination(items:Vector.<DisplayObject>, index:int, keyCode:uint, bounds:LayoutBoundsResult):int
Using the current index and a key press, calculates the new index.
AnchorLayout
  
getNearestScrollPositionForIndex(index:int, scrollX:Number, scrollY:Number, items:Vector.<DisplayObject>, x:Number, y:Number, width:Number, height:Number, result:Point = null):Point
Calculates the scroll position nearest to the current scroll position that will display the full bounds of the item within the view port.
AnchorLayout
  
getScrollPositionForIndex(index:int, items:Vector.<DisplayObject>, x:Number, y:Number, width:Number, height:Number, result:Point = null):Point
Using the item dimensions, calculates a scroll position that will ensure that the item at a given index will be visible within the specified bounds.
AnchorLayout
  
layout(items:Vector.<DisplayObject>, viewPortBounds:ViewPortBounds = null, result:LayoutBoundsResult = null):LayoutBoundsResult
Positions (and possibly resizes) the supplied items within the optional bounds argument.
AnchorLayout
Events
 Event Summary Defined By
  Dispatched when a property of the layout changes, indicating that a redraw is probably needed.AnchorLayout
Property Detail
requiresLayoutOnScrollproperty
requiresLayoutOnScroll:Boolean  [read-only]

Determines if the container calls layout() when the scroll position changes. Useful for transforming items as the view port scrolls. This value should be true for layouts that implement the IVirtualLayout interface and the useVirtualLayout property is set to true. May also be used by layouts that toggle item visibility as the items scroll into and out of the view port.


Implementation
    public function get requiresLayoutOnScroll():Boolean
Constructor Detail
AnchorLayout()Constructor
public function AnchorLayout()

Constructor.

Method Detail
calculateNavigationDestination()method
public function calculateNavigationDestination(items:Vector.<DisplayObject>, index:int, keyCode:uint, bounds:LayoutBoundsResult):int

Using the current index and a key press, calculates the new index. This might be use to change a list's selectedIndex when a key is pressed.

Parameters

items:Vector.<DisplayObject>
 
index:int
 
keyCode:uint
 
bounds:LayoutBoundsResult

Returns
int
getNearestScrollPositionForIndex()method 
public function getNearestScrollPositionForIndex(index:int, scrollX:Number, scrollY:Number, items:Vector.<DisplayObject>, x:Number, y:Number, width:Number, height:Number, result:Point = null):Point

Calculates the scroll position nearest to the current scroll position that will display the full bounds of the item within the view port. If the item is already fully displayed in the view port, the current scroll position will be returned unchanged.

While the item will be displayed in the view port without being clipped in any way, it may not be placed in the most prominent position possible. To give the item a more prominent location, use getScrollPositionForIndex() instead.

This function should always be called after the layout() function. The width and height arguments are the final bounds of the view port, which may be calculated in the layout() function.

Parameters

index:int
 
scrollX:Number
 
scrollY:Number
 
items:Vector.<DisplayObject>
 
x:Number
 
y:Number
 
width:Number
 
height:Number
 
result:Point (default = null)

Returns
Point
getScrollPositionForIndex()method 
public function getScrollPositionForIndex(index:int, items:Vector.<DisplayObject>, x:Number, y:Number, width:Number, height:Number, result:Point = null):Point

Using the item dimensions, calculates a scroll position that will ensure that the item at a given index will be visible within the specified bounds.

Typically, this function is used to show the item in the most prominent way, such as centering. To scroll a minimum distance required to display the full bounds of the item in the view port, use getNearestScrollPositionForIndex() instead.

This function should always be called after the layout() function. The width and height arguments are the final bounds of the view port, which may be calculated in the layout() function.

Parameters

index:int
 
items:Vector.<DisplayObject>
 
x:Number
 
y:Number
 
width:Number
 
height:Number
 
result:Point (default = null)

Returns
Point
layout()method 
public function layout(items:Vector.<DisplayObject>, viewPortBounds:ViewPortBounds = null, result:LayoutBoundsResult = null):LayoutBoundsResult

Positions (and possibly resizes) the supplied items within the optional bounds argument. If no bounds are specified, the layout algorithm will assume that the bounds start a 0,0 and have unbounded dimensions. Returns the actual bounds of the content, which may be different than the specified bounds.

Note: The items are not absolutely restricted to appear only within the bounds. The bounds can affect positioning, but the algorithm may very well ignore them completely.

If a layout implementation needs to access accurate width and height values from items that are of type IFeathersControl, it must call validate() manually. For performance reasons, the container that is the parent of the items will not call validate() before passing the items to a layout implementation. Meeting this requirement may be as simple as looping through the items at the beginning of layout() and validating all items that are Feathers UI controls:

const itemCount:int = items.length;
for(var i:int = 0; i < itemCount; i++)
{
    var item:IFeathersControl = items[i] as IFeathersControl;
    if(item)
    {
        item.validate();
    }
}

Parameters

items:Vector.<DisplayObject>
 
viewPortBounds:ViewPortBounds (default = null)
 
result:LayoutBoundsResult (default = null)

Returns
LayoutBoundsResult
Event Detail
change Event
Event Object Type: starling.events.Event
Event.type property = starling.events.Event.CHANGE

Dispatched when a property of the layout changes, indicating that a redraw is probably needed.

The properties of the event object have the following values:

PropertyValue
bubblesfalse
currentTargetThe Object that defines the event listener that handles the event. For example, if you use myButton.addEventListener() to register an event listener, myButton is the value of the currentTarget.
datanull
targetThe Object that dispatched the event; it is not always the Object listening for the event. Use the currentTarget property to always access the Object listening for the event.