forked from arpit/openpyro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRowGridLayout.as
More file actions
84 lines (67 loc) · 2.05 KB
/
RowGridLayout.as
File metadata and controls
84 lines (67 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.openPyro.layout
{
import flash.display.DisplayObject;
import org.openPyro.core.UIContainer;
public class RowGridLayout extends AbstractLayout implements ILayout, IContainerMeasurementHelper
{
protected var _numColumns:uint;
protected var _rowHeight:Number = NaN;
protected var _rowGap:Number;
protected var _columnGap:Number;
public function RowGridLayout(numColumns:uint, rowHeight:Number = NaN, rowGap:Number=0, columnGap:Number=0)
{
this._numColumns = numColumns;
_rowHeight = rowHeight;
_rowGap = rowGap
_columnGap = columnGap
}
private var _container:UIContainer
public function set container(c:UIContainer):void
{
_container = c;
}
override public function calculatePositions(children:Array):Array{
layoutDescriptors = [];
if(children.length == 0 ) return [] ;
var nowX:Number = _initX;
var nowY:Number = _initY;
if(isNaN(_rowHeight)){
_rowHeight = DisplayObject(children[0]).height;
}
for(var i:uint=0; i<children.length; i++)
{
var child:DisplayObject = children[i] as DisplayObject;
if(i>0 && (i%_numColumns)==0){
nowY+= _rowHeight+_rowGap;
nowX= _initX;
}
var descriptor:LayoutDescriptor = new LayoutDescriptor(child, nowX, nowY);
layoutDescriptors.push(descriptor);
nowX+=child.width + _columnGap;
}
return layoutDescriptors;
}
public function getMaxWidth(children:Array):Number
{
if(children.length == 0){
return 0
}
var childW:Number = children[0].width;
var w:Number = childW * this._numColumns
return w;
}
public function getMaxHeight(children:Array):Number
{
if(children.length == 0){
return 0
}
var childH:Number = isNaN(_rowHeight)?children[0].height:_rowHeight;
var numRows:int = children.length%_numColumns != 0 ? children.length/_numColumns+1 : children.length/_numColumns
return (numRows*childH+(numRows-1)*_rowGap) ;
}
public function calculateSizes(children:Array, container:UIContainer):void
{
trace("--> calculate new sizes")
}
}
}