-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistLayout.sj
63 lines (56 loc) · 2.03 KB
/
listLayout.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
enum listLayoutOrientation(
topBottom
leftRight
bottomTop
rightLeft
)
listLayout #element (
children : array!heap #element()
margin := margin()
orientation := listLayoutOrientation.leftRight
_rect := rect()
getSize(maxSize : 'size) {
size(maxSize.w, maxSize.h)
}
getRect()'rect { _rect }
setRect(rect_ : 'rect) {
_rect = rect_
innerRect : rect_ - margin
val := 0
for i : 0 to children.count {
child : children[i]
switch orientation {
listLayoutOrientation.topBottom {
childSize : child.getSize(size(innerRect.w, innerRect.h - val))
child.setRect(rect(innerRect.x, innerRect.y + val, innerRect.w, childSize.h))
val += childSize.h
}
listLayoutOrientation.bottomTop {
childSize : child.getSize(size(innerRect.w, innerRect.h - val))
child.setRect(rect(innerRect.x, innerRect.y + innerRect.h - val - childSize.h, innerRect.w, childSize.h))
val += childSize.h
}
listLayoutOrientation.leftRight {
childSize : child.getSize(size(innerRect.w - val, innerRect.h))
child.setRect(rect(innerRect.x + val, innerRect.y, childSize.w, innerRect.h))
val += childSize.w
}
listLayoutOrientation.rightLeft {
childSize : child.getSize(size(innerRect.w - val, innerRect.h))
child.setRect(rect(innerRect.x + innerRect.w - val - childSize.w, innerRect.y, childSize.w, innerRect.h))
val += 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 }