Packagefeathers.layout
Classpublic class WaterfallLayout
InheritanceWaterfallLayout Inheritance starling.events.EventDispatcher
Implements IVariableVirtualLayout

A layout with multiple columns of equal width where items may have variable heights. Items are added to the layout in order, but they may be added to any of the available columns. The layout selects the column where the column's height plus the item's height will result in the smallest possible total height.

Beta Layout: This is a new layout, and its APIs may need some changes between now and the next version of Feathers to account for overlooked requirements or other issues. Upgrading to future versions of Feathers may involve manual changes to your code that uses this layout. The Feathers deprecation policy will not go into effect until this component's status is upgraded from beta to stable.

See also

How to use WaterfallLayout with Feathers containers


Public Properties
 PropertyDefined By
  gap : Number
Quickly sets both horizontalGap and verticalGap to the same value.
WaterfallLayout
  hasVariableItemDimensions : Boolean
When the layout is virtualized, and this value is true, the items may have variable height values.
WaterfallLayout
  horizontalAlign : String
The alignment of the items horizontally, on the x-axis.
WaterfallLayout
  horizontalGap : Number
The horizontal space, in pixels, between columns.
WaterfallLayout
  padding : Number
Quickly sets all padding properties to the same value.
WaterfallLayout
  paddingBottom : Number
The space, in pixels, that appears on the bottom, below the items.
WaterfallLayout
  paddingLeft : Number
The minimum space, in pixels, to the left of the items.
WaterfallLayout
  paddingRight : Number
The minimum space, in pixels, to the right of the items.
WaterfallLayout
  paddingTop : Number
The space, in pixels, that appears on top, above the items.
WaterfallLayout
  requestedColumnCount : int
Requests that the layout uses a specific number of columns, if possible.
WaterfallLayout
  requiresLayoutOnScroll : Boolean
[read-only] Determines if the container calls layout() when the scroll position changes.
WaterfallLayout
  typicalItem : DisplayObject
Used internally by a component that supports layout virtualization, such as List, to provide a display object with dimensions that represent a "typical" item in the layout.
WaterfallLayout
  useVirtualLayout : Boolean
Determines if virtual layout should be used.
WaterfallLayout
  verticalGap : Number
The vertical space, in pixels, between items in a column.
WaterfallLayout
Public Methods
 MethodDefined By
  
Constructor.
WaterfallLayout
  
addToVariableVirtualCacheAtIndex(index:int, item:DisplayObject = null):void
Inserts an item in to the cache at the specified index, pushing the old cached value at that index, and all following values, up one index.
WaterfallLayout
  
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.
WaterfallLayout
  
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.
WaterfallLayout
  
getVisibleIndicesAtScrollPosition(scrollX:Number, scrollY:Number, width:Number, height:Number, itemCount:int, result:Vector.<int> = null):Vector.<int>
Used internally by a component, such as List, to determines which indices are visible with the specified view port bounds and scroll position.
WaterfallLayout
  
layout(items:Vector.<DisplayObject>, viewPortBounds:ViewPortBounds = null, result:LayoutBoundsResult = null):LayoutBoundsResult
Positions (and possibly resizes) the supplied items within the optional bounds argument.
WaterfallLayout
  
measureViewPort(itemCount:int, viewPortBounds:ViewPortBounds = null, result:Point = null):Point
Used internally by a component, such as List, to measure the view port based on the typical item dimensions or cached dimensions, if available.
WaterfallLayout
  
Removes an item in to the cache at the specified index, moving the values at following indexes down by one.
WaterfallLayout
  
Clears the cached dimensions for all virtualized indices.
WaterfallLayout
  
resetVariableVirtualCacheAtIndex(index:int, item:DisplayObject = null):void
Clears the cached dimensions for one specific virtualized index.
WaterfallLayout
Events
 Event Summary Defined By
  Dispatched when a property of the layout changes, indicating that a redraw is probably needed.WaterfallLayout
Public Constants
 ConstantDefined By
  HORIZONTAL_ALIGN_CENTER : String = center
[static] The items will be aligned to the center of the bounds.
WaterfallLayout
  HORIZONTAL_ALIGN_LEFT : String = left
[static] The items will be aligned to the left of the bounds.
WaterfallLayout
  HORIZONTAL_ALIGN_RIGHT : String = right
[static] The items will be aligned to the right of the bounds.
WaterfallLayout
Property Detail
gapproperty
gap:Number

Quickly sets both horizontalGap and verticalGap to the same value. The gap getter always returns the value of horizontalGap, but the value of verticalGap may be different.

The default value is 0.


Implementation
    public function get gap():Number
    public function set gap(value:Number):void

See also

hasVariableItemDimensionsproperty 
hasVariableItemDimensions:Boolean

When the layout is virtualized, and this value is true, the items may have variable height values. If false, the items will all share the same height value with the typical item.

The default value is true.


Implementation
    public function get hasVariableItemDimensions():Boolean
    public function set hasVariableItemDimensions(value:Boolean):void
horizontalAlignproperty 
horizontalAlign:String

The alignment of the items horizontally, on the x-axis.

The default value is WaterfallLayout.HORIZONTAL_ALIGN_CENTER.


Implementation
    public function get horizontalAlign():String
    public function set horizontalAlign(value:String):void

See also

horizontalGapproperty 
horizontalGap:Number

The horizontal space, in pixels, between columns.

The default value is 0.


Implementation
    public function get horizontalGap():Number
    public function set horizontalGap(value:Number):void
paddingproperty 
padding:Number

Quickly sets all padding properties to the same value. The padding getter always returns the value of paddingTop, but the other padding values may be different.

The default value is 0.


Implementation
    public function get padding():Number
    public function set padding(value:Number):void

See also

paddingBottomproperty 
paddingBottom:Number

The space, in pixels, that appears on the bottom, below the items.

The default value is 0.


Implementation
    public function get paddingBottom():Number
    public function set paddingBottom(value:Number):void
paddingLeftproperty 
paddingLeft:Number

The minimum space, in pixels, to the left of the items.

The default value is 0.


Implementation
    public function get paddingLeft():Number
    public function set paddingLeft(value:Number):void
paddingRightproperty 
paddingRight:Number

The minimum space, in pixels, to the right of the items.

The default value is 0.


Implementation
    public function get paddingRight():Number
    public function set paddingRight(value:Number):void
paddingTopproperty 
paddingTop:Number

The space, in pixels, that appears on top, above the items.

The default value is 0.


Implementation
    public function get paddingTop():Number
    public function set paddingTop(value:Number):void
requestedColumnCountproperty 
requestedColumnCount:int

Requests that the layout uses a specific number of columns, if possible. Set to 0 to calculate the maximum of columns that will fit in the available space.

If the view port's explicit or maximum width is not large enough to fit the requested number of columns, it will use fewer. If the view port doesn't have an explicit width and the maximum width is equal to Number.POSITIVE_INFINITY, the width will be calculated automatically to fit the exact number of requested columns.

The default value is 0.


Implementation
    public function get requestedColumnCount():int
    public function set requestedColumnCount(value:int):void
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
typicalItemproperty 
typicalItem:DisplayObject

Used internally by a component that supports layout virtualization, such as List, to provide a display object with dimensions that represent a "typical" item in the layout. These dimensions will be used to fill in blanks for the layout when an item is virtual and isn't actually on the display list. If you are simply passing a layout to a component, setting this property will have no effect. It is meant to be used by the component, and the component will replace any value you pass to this property.


Implementation
    public function get typicalItem():DisplayObject
    public function set typicalItem(value:DisplayObject):void
useVirtualLayoutproperty 
useVirtualLayout:Boolean

Determines if virtual layout should be used. Some components don't support virtual layouts, and they will always change this property to false. In those cases, the virtual layout options will be ignored.

The default value is true.


Implementation
    public function get useVirtualLayout():Boolean
    public function set useVirtualLayout(value:Boolean):void
verticalGapproperty 
verticalGap:Number

The vertical space, in pixels, between items in a column.

The default value is 0.


Implementation
    public function get verticalGap():Number
    public function set verticalGap(value:Number):void
Constructor Detail
WaterfallLayout()Constructor
public function WaterfallLayout()

Constructor.

Method Detail
addToVariableVirtualCacheAtIndex()method
public function addToVariableVirtualCacheAtIndex(index:int, item:DisplayObject = null):void

Inserts an item in to the cache at the specified index, pushing the old cached value at that index, and all following values, up one index.

Parameters

index:int
 
item:DisplayObject (default = null)

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
getVisibleIndicesAtScrollPosition()method 
public function getVisibleIndicesAtScrollPosition(scrollX:Number, scrollY:Number, width:Number, height:Number, itemCount:int, result:Vector.<int> = null):Vector.<int>

Used internally by a component, such as List, to determines which indices are visible with the specified view port bounds and scroll position. Indices that aren't returned are typically not displayed and can be replaced virtually. Uses the typical items dimensions, or cached dimensions, if available.

This function is meant to be called by the List or other component that uses the virtual layout. If you're simply creating a layout for a List or another component, do not call this function. It is meant for developers creating custom components only.

Parameters

scrollX:Number
 
scrollY:Number
 
width:Number
 
height:Number
 
itemCount:int
 
result:Vector.<int> (default = null)

Returns
Vector.<int>
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
measureViewPort()method 
public function measureViewPort(itemCount:int, viewPortBounds:ViewPortBounds = null, result:Point = null):Point

Used internally by a component, such as List, to measure the view port based on the typical item dimensions or cached dimensions, if available.

This function is meant to be called by the List or other component that uses the virtual layout. If you're simply creating a layout for a List or another component, do not call this function. It is meant for developers creating custom components only.

Parameters

itemCount:int
 
viewPortBounds:ViewPortBounds (default = null)
 
result:Point (default = null)

Returns
Point
removeFromVariableVirtualCacheAtIndex()method 
public function removeFromVariableVirtualCacheAtIndex(index:int):void

Removes an item in to the cache at the specified index, moving the values at following indexes down by one.

Parameters

index:int

resetVariableVirtualCache()method 
public function resetVariableVirtualCache():void

Clears the cached dimensions for all virtualized indices.

resetVariableVirtualCacheAtIndex()method 
public function resetVariableVirtualCacheAtIndex(index:int, item:DisplayObject = null):void

Clears the cached dimensions for one specific virtualized index.

Parameters

index:int
 
item:DisplayObject (default = null)

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.

Constant Detail
HORIZONTAL_ALIGN_CENTERConstant
public static const HORIZONTAL_ALIGN_CENTER:String = center

The items will be aligned to the center of the bounds.

See also

HORIZONTAL_ALIGN_LEFTConstant 
public static const HORIZONTAL_ALIGN_LEFT:String = left

The items will be aligned to the left of the bounds.

See also

HORIZONTAL_ALIGN_RIGHTConstant 
public static const HORIZONTAL_ALIGN_RIGHT:String = right

The items will be aligned to the right of the bounds.

See also