-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflowLayout.sj
93 lines (82 loc) · 3.03 KB
/
flowLayout.sj
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
enum flowLayoutOrientation(
topBottom
leftRight
bottomTop
rightLeft
)
flowLayout #element (
children : array!heap #element()
margin := margin()
orientation := flowLayoutOrientation.leftRight
_rect := rect()
getSize(maxSize : 'size) {
size(maxSize.w, maxSize.h)
}
getRect()'rect { _rect }
setRect(rect_ : 'rect) {
_rect = rect_
innerRect : rect_ - margin
val1 := 0
val2 := 0
valMax := 0
for i : 0 to children.count {
child : children[i]
switch orientation {
flowLayoutOrientation.topBottom {
childSize : child.getSize(size(innerRect.w, innerRect.h))
valMax = valMax.max(childSize.w)
if (val1 + childSize.h > innerRect.h) {
val1 = 0
val2 += valMax
valMax = 0
}
child.setRect(rect(innerRect.x + val2, innerRect.y + val1, childSize.w, childSize.h))
val1 += childSize.h
}
flowLayoutOrientation.bottomTop {
childSize : child.getSize(size(innerRect.w, innerRect.h))
valMax = valMax.max(childSize.w)
if (val1 + childSize.h >= innerRect.h) {
val1 = 0
val2 += valMax
valMax = 0
}
child.setRect(rect(innerRect.x + val2, innerRect.y + innerRect.h - val1 - childSize.h, childSize.w, childSize.h))
val1 += childSize.h
}
flowLayoutOrientation.leftRight {
childSize : child.getSize(size(innerRect.w, innerRect.h))
valMax = valMax.max(childSize.h)
if (val1 + childSize.w > innerRect.w) {
val1 = 0
val2 += valMax
valMax = 0
}
child.setRect(rect(innerRect.x + val1, innerRect.y + val2, childSize.w, childSize.h))
val1 += childSize.w
}
flowLayoutOrientation.rightLeft {
childSize : child.getSize(size(innerRect.w, innerRect.h))
valMax = valMax.max(childSize.h)
if (val1 + childSize.w > innerRect.w) {
val1 = 0
val2 += valMax
valMax = 0
}
child.setRect(rect(innerRect.x + innerRect.w - val1 - childSize.w, innerRect.y + val2, childSize.w, childSize.h))
val1 += childSize.w
}
}
}
void
}
render(scene : 'scene2d) {
for i : 0 to children.count {
child : children[i]
child.render(scene)
}
}
fireMouseEvent(mouseEvent : 'mouseEvent) {
mouseEvent.fireChildren(children)
}
) { this }