-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathHorizontalLayout.hx
107 lines (89 loc) · 3.79 KB
/
HorizontalLayout.hx
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package haxe.ui.layouts;
import haxe.ui.geom.Size;
class HorizontalLayout extends DefaultLayout {
public function new() {
super();
_calcFullWidths = true;
_roundFullWidths = true;
}
private override function repositionChildren() {
var xpos = paddingLeft;
var usableSize = this.usableSize;
var visibleChildren = component.childComponents.length;
for (child in component.childComponents) {
if (child.includeInLayout == false) {
visibleChildren--;
continue;
}
}
var evenlySpace = false;
var aroundSpace = false;
var betweenSpace = false;
if (component.style != null) {
if (component.style.justifyContent == "space-between" ) betweenSpace = true;
// The empty space before the first and after the last item equals half of the spacing between the items
if (component.style.justifyContent == "space-evenly" ) evenlySpace = true;
// The empty space before the first and after the last item equals the spacing between the items
if (component.style.justifyContent == "space-around") aroundSpace = true;
}
var spacing:Float = horizontalSpacing;
if (betweenSpace) {
spacing = usableSize.width / (visibleChildren - 1) + horizontalSpacing;
}
else if (aroundSpace){
spacing = (usableSize.width + horizontalSpacing * (visibleChildren - 1)) / visibleChildren ;
}
else if (evenlySpace){
spacing = (usableSize.width + horizontalSpacing * (visibleChildren - 1)) / (visibleChildren + 1) ;
}
for (child in component.childComponents) {
if (child.includeInLayout == false) {
continue;
}
var ypos:Float = 0;
switch (verticalAlign(child)) {
case "center":
ypos = ((usableSize.height - child.componentHeight) / 2) + paddingTop + marginTop(child) - marginBottom(child);
case "bottom":
if (child.componentHeight < component.componentHeight) {
ypos = component.componentHeight - (child.componentHeight + paddingBottom + marginTop(child));
}
default:
ypos = paddingTop + marginTop(child);
}
if (aroundSpace) {
child.moveComponent(xpos + spacing / 2 + marginLeft(child), ypos);
}
else if (evenlySpace) {
child.moveComponent(xpos + spacing + marginLeft(child), ypos);
}
else {
child.moveComponent(xpos + marginLeft(child), ypos);
}
if (child.componentWidth > 0) xpos += child.componentWidth + spacing;
}
}
private override function get_usableSize():Size {
var size:Size = super.get_usableSize();
var visibleChildren = component.childComponents.length;
for (child in component.childComponents) {
if (child.includeInLayout == false) {
visibleChildren--;
continue;
}
if (child.componentWidth > 0 && (child.percentWidth == null || hasFixedMinWidth(child) == true)) { // means its a fixed width, ie, not a % sized control
if (!hasFixedMinPercentWidth(child)) {
size.width -= child.componentWidth + marginLeft(child) + marginRight(child);
}
}
}
if (visibleChildren > 1) {
size.width -= horizontalSpacing * (visibleChildren - 1);
}
if (size.width <= 0) {
size.width = 0;
visibleChildren--;
}
return size;
}
}