-
Notifications
You must be signed in to change notification settings - Fork 0
/
borderLayout.sj
104 lines (87 loc) · 3.05 KB
/
borderLayout.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
94
95
96
97
98
99
100
101
102
103
104
enum borderPosition (
fill
left
right
top
bottom
)
#borderChild(
getPosition()'borderPosition
)
borderChild #element #borderChild (
child : 'heap #element
position := borderPosition.fill
_rect := rect()
getPosition() { position }
getSize(maxSize : 'size) {
child.getSize(maxSize)
}
getRect()'rect { _rect }
setRect(rect_ : 'rect) {
_rect = rect_
child.setRect(_rect)
void
}
render(scene : 'scene2d) {
child.render(scene)
}
fireMouseEvent(mouseEvent : 'mouseEvent)'bool {
child.fireMouseEvent(mouseEvent)
}
) { this }
borderLayout #element (
children : array!heap #element()
margin := margin()
_rect := rect()
getSize(maxSize : 'size) {
size(maxSize.w, maxSize.h)
}
getRect()'rect { _rect }
setRect(rect_ : 'rect) {
_rect = rect_
remaining := rect_ - margin
for i : 0 to children.count {
child : children[i]
borderChild : child as heap #borderChild?
position : borderChild?.getPosition()?:(borderPosition.fill)
if position != borderPosition.fill {
childSize : child.getSize(size(remaining.w, remaining.h))
if position == borderPosition.left {
child.setRect(rect(remaining.x, remaining.y, childSize.w, remaining.h))
remaining = rect(remaining.x + childSize.w, remaining.y, remaining.w - childSize.w, remaining.h)
void
} else if position == borderPosition.right {
child.setRect(rect(remaining.x + remaining.w - childSize.w, remaining.y, childSize.w, remaining.h))
remaining = rect(remaining.x, remaining.y, remaining.w - childSize.w, remaining.h)
void
} else if position == borderPosition.top {
child.setRect(rect(remaining.x, remaining.y, remaining.w, childSize.h))
remaining = rect(remaining.x, remaining.y + childSize.h, remaining.w, remaining.h - childSize.h)
void
} else if position == borderPosition.bottom {
child.setRect(rect(remaining.x, remaining.y + remaining.h - childSize.h, remaining.w, childSize.h))
remaining = rect(remaining.x, remaining.y, remaining.w, remaining.h - childSize.h)
void
}
}
}
for i : 0 to children.count {
child2 : children[i]
borderChild2 : child2 as heap #borderChild?
position2 : borderChild2?.getPosition()?:(borderPosition.fill)
if position2 == borderPosition.fill {
child2.setRect(remaining)
}
}
void
}
render(scene : 'scene2d) {
for i : 0 to children.count {
child : children[i]
child.render(scene)
}
}
fireMouseEvent(mouseEvent : 'mouseEvent)'bool {
mouseEvent.fireChildren(children)
}
) { this }