-
Notifications
You must be signed in to change notification settings - Fork 0
/
centerLayout.sj
56 lines (48 loc) · 1.42 KB
/
centerLayout.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
centerLayout #element (
children : array!heap #element()
margin := margin()
centerX := empty'f32
centery := empty'f32
_rect := rect()
getSize(maxSize : 'size) {
size := size()
innerSize : maxSize - margin
for i : 0 to children.count {
child : children[i]
size = size.max(child.getSize(innerSize))
}
size + margin
}
getRect()'rect { _rect }
setRect(rect_ : 'rect) {
_rect = rect_
innerRect : _rect - margin
for i : 0 to children.count {
child : children[i]
childSize : child.getSize(size(innerRect.w, innerRect.h))
x := innerRect.x
w := innerRect.w
ifValid centerX {
x = innerRect.x + ((innerRect.w - childSize.w) as f32 * centerX) as i32
w = childSize.w
}
y := innerRect.y
h := innerRect.h
ifValid centerY {
y = innerRect.y + ((innerRect.h - childSize.h) as f32 * centerY) as i32
h = childSize.h
}
child.setRect(rect(x, y, w, h))
}
void
}
render(scene : 'scene2d) {
for i : 0 to children.count {
child : children[i]
child.render(scene)
}
}
fireMouseEvent(mouseEvent : 'mouseEvent) {
mouseEvent.fireChildren(children)
}
) { this }