forked from arpit/openpyro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVLayout.as
More file actions
91 lines (76 loc) · 2.31 KB
/
VLayout.as
File metadata and controls
91 lines (76 loc) · 2.31 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
85
86
87
88
89
90
91
package org.openPyro.layout{
import flash.display.DisplayObject;
import org.openPyro.core.MeasurableControl;
import org.openPyro.core.UIContainer;
/* import org.openPyro.effects.EffectDescriptor;
import org.openPyro.effects.PyroEffect;*/
public class VLayout extends AbstractLayout implements ILayout, IContainerMeasurementHelper{
private var _vGap:Number = 0;
public function VLayout(vGap:Number=0){
_vGap = vGap;
}
protected var _container:UIContainer;
public function set container(container:UIContainer):void
{
_container = container;
}
public function getMaxWidth(children:Array):Number
{
var maxW:Number=0;
for(var i:uint=0; i<children.length; i++)
{
if(DisplayObject(children[i]).width > maxW)
{
maxW = DisplayObject(children[i]).width
}
}
return maxW;
}
public function getMaxHeight(children:Array):Number
{
var nowY:Number=_initY;
for(var i:uint=0; i<children.length; i++){
var c:DisplayObject = children[i] as DisplayObject;
nowY+=c.height;
nowY+=this._vGap
}
return nowY-_vGap;
}
override public function calculatePositions(children:Array):Array{
super.calculatePositions(children);
var nowY:Number=_initY;
var child:DisplayObject
for(var i:uint=0; i<children.length; i++){
child = children[i] as DisplayObject;
var descriptor:LayoutDescriptor = new LayoutDescriptor(child, _initX, nowY);
layoutDescriptors.push(descriptor);
nowY += child.height+_vGap;
}
return layoutDescriptors;
}
/**
*Find all the children with explicitWidth/ explicit Height set
*This part depends on the layout since HLayout will start trimming
*the objects available h space, and v layout will do the same
*for vertically available space
**/
public function calculateSizes(children:Array,container:UIContainer):void
{
for(var i:int = 0; i<children.length; i++)
{
initY = container.padding.top;
if(i>0){
container.explicitlyAllocatedHeight+=_vGap;
}
if(children[i] is MeasurableControl)
{
var sizeableChild:MeasurableControl = MeasurableControl(children[i]);
if(isNaN(sizeableChild.percentUnusedHeight) && isNaN(sizeableChild.percentHeight))
{
container.explicitlyAllocatedHeight+=sizeableChild.height;
}
}
}
}
}
}