0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
PanelView subclass:#VerticalPanelView
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Layout'
|
|
18 |
!
|
|
19 |
|
|
20 |
VerticalPanelView comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
22 |
All Rights Reserved
|
|
23 |
|
38
|
24 |
$Header: /cvs/stx/stx/libwidg/VerticalPanelView.st,v 1.4 1994-08-07 13:23:33 claus Exp $
|
|
25 |
'!
|
|
26 |
|
|
27 |
!VerticalPanelView class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
|
45 |
$Header: /cvs/stx/stx/libwidg/VerticalPanelView.st,v 1.4 1994-08-07 13:23:33 claus Exp $
|
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
a View which arranges its child-views in a vertical column.
|
|
52 |
All real work is done in PanelView - only the layout computation is
|
|
53 |
redefined here.
|
|
54 |
|
|
55 |
example: default layout (centered)
|
|
56 |
|
|
57 |
|v p b1 b2 b3|
|
|
58 |
|
|
59 |
v := StandardSystemView new.
|
|
60 |
p := VerticalPanelView in:v.
|
|
61 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
62 |
b1 := Button label:'button1' in:p.
|
|
63 |
b2 := Button label:'button2' in:p.
|
|
64 |
b3 := Button label:'button3' in:p.
|
|
65 |
v extent:100 @ 300.
|
|
66 |
v open
|
|
67 |
|
0
|
68 |
|
38
|
69 |
example: left-layout
|
|
70 |
|
|
71 |
|v p b1 b2 b3|
|
|
72 |
|
|
73 |
v := StandardSystemView new.
|
|
74 |
p := VerticalPanelView in:v.
|
|
75 |
p layout:#top.
|
|
76 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
77 |
b1 := Button label:'button1' in:p.
|
|
78 |
b2 := Button label:'button2' in:p.
|
|
79 |
b3 := Button label:'button3' in:p.
|
|
80 |
v extent:100 @ 300.
|
|
81 |
v open
|
|
82 |
|
|
83 |
|
|
84 |
example: right-layout
|
|
85 |
|
|
86 |
|v p b1 b2 b3|
|
0
|
87 |
|
38
|
88 |
v := StandardSystemView new.
|
|
89 |
p := VerticalPanelView in:v.
|
|
90 |
p layout:#bottom.
|
|
91 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
92 |
b1 := Button label:'button1' in:p.
|
|
93 |
b2 := Button label:'button2' in:p.
|
|
94 |
b3 := Button label:'button3' in:p.
|
|
95 |
v extent:100 @ 300.
|
|
96 |
v open
|
|
97 |
|
|
98 |
|
|
99 |
example: spread-layout
|
|
100 |
|
|
101 |
|v p b1 b2 b3|
|
|
102 |
|
|
103 |
v := StandardSystemView new.
|
|
104 |
p := VerticalPanelView in:v.
|
|
105 |
p layout:#spread.
|
|
106 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
107 |
b1 := Button label:'button1' in:p.
|
|
108 |
b2 := Button label:'button2' in:p.
|
|
109 |
b3 := Button label:'button3' in:p.
|
|
110 |
v extent:100 @ 300.
|
|
111 |
v open
|
|
112 |
"
|
|
113 |
! !
|
0
|
114 |
|
|
115 |
!VerticalPanelView methodsFor:'queries'!
|
|
116 |
|
|
117 |
preferedExtent
|
|
118 |
"return a good extent, one that makes subviews fit"
|
|
119 |
|
|
120 |
|sumOfHeights maxWidth|
|
|
121 |
|
|
122 |
subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace].
|
|
123 |
|
|
124 |
"compute net height needed"
|
|
125 |
|
|
126 |
sumOfHeights := 0.
|
|
127 |
maxWidth := 0.
|
|
128 |
|
|
129 |
subViews do:[:child |
|
|
130 |
sumOfHeights := sumOfHeights + child heightIncludingBorder.
|
|
131 |
maxWidth := maxWidth max:(child widthIncludingBorder)
|
|
132 |
].
|
|
133 |
borderWidth ~~ 0 ifTrue:[
|
|
134 |
sumOfHeights := sumOfHeights + (horizontalSpace * 2).
|
|
135 |
maxWidth := maxWidth + (horizontalSpace * 2).
|
|
136 |
].
|
|
137 |
sumOfHeights := sumOfHeights + ((subViews size - 1) * verticalSpace).
|
|
138 |
|
|
139 |
^ maxWidth @ sumOfHeights
|
|
140 |
! !
|
|
141 |
|
|
142 |
!VerticalPanelView methodsFor:'layout'!
|
|
143 |
|
|
144 |
setChildPositions
|
|
145 |
"(re)compute position of every child"
|
|
146 |
|
|
147 |
|xpos ypos space sumOfHeights numChilds l|
|
|
148 |
|
|
149 |
subViews isNil ifTrue:[^ self].
|
|
150 |
|
|
151 |
space := verticalSpace.
|
|
152 |
|
|
153 |
"compute net height needed"
|
|
154 |
|
38
|
155 |
sumOfHeights := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child heightIncludingBorder].
|
0
|
156 |
numChilds := subViews size.
|
|
157 |
|
|
158 |
l := layout.
|
|
159 |
((l == #center) and:[numChilds == 1]) ifTrue:[
|
|
160 |
l := #spread
|
|
161 |
].
|
|
162 |
|
|
163 |
"compute position of topmost subview and space between them;
|
|
164 |
if they do hardly fit, leave no space between them "
|
|
165 |
|
38
|
166 |
(sumOfHeights >= (height - (margin * 2))) ifTrue:[
|
0
|
167 |
ypos := 0.
|
|
168 |
space := 0
|
|
169 |
] ifFalse:[
|
|
170 |
(l == #bottom) ifTrue:[
|
38
|
171 |
ypos := height - (space * numChilds) - sumOfHeights.
|
|
172 |
"
|
0
|
173 |
borderWidth == 0 ifTrue:[
|
38
|
174 |
ypos := ypos + space
|
0
|
175 |
].
|
38
|
176 |
"
|
|
177 |
ypos < 0 ifTrue:[
|
|
178 |
space := space min:(height - sumOfHeights) // (numChilds + 1).
|
|
179 |
ypos := height - (space * numChilds) - sumOfHeights.
|
|
180 |
]
|
0
|
181 |
] ifFalse: [
|
|
182 |
(l == #spread) ifTrue:[
|
|
183 |
space := (height - sumOfHeights) // (numChilds + 1).
|
|
184 |
ypos := space.
|
|
185 |
(space == 0) ifTrue:[
|
|
186 |
ypos := (height - sumOfHeights) // 2
|
|
187 |
]
|
|
188 |
] ifFalse: [
|
|
189 |
(l == #center) ifTrue:[
|
|
190 |
ypos := (height - (sumOfHeights
|
38
|
191 |
+ ((numChilds - 1) * space))) // 2.
|
|
192 |
ypos < 0 ifTrue:[
|
|
193 |
space := (height - sumOfHeights) // (numChilds + 1).
|
|
194 |
ypos := (height - (sumOfHeights
|
|
195 |
+ ((numChilds - 1) * space))) // 2.
|
|
196 |
]
|
0
|
197 |
] ifFalse:[
|
38
|
198 |
"
|
0
|
199 |
borderWidth == 0 ifTrue:[
|
|
200 |
ypos := 0
|
|
201 |
] ifFalse:[
|
|
202 |
ypos := verticalSpace
|
38
|
203 |
].
|
|
204 |
"
|
|
205 |
space := space min:(height - sumOfHeights) // (numChilds + 1).
|
|
206 |
ypos := space.
|
0
|
207 |
]
|
|
208 |
]
|
|
209 |
]
|
|
210 |
].
|
|
211 |
|
38
|
212 |
|
0
|
213 |
"now set positions"
|
|
214 |
|
|
215 |
subViews do:[:childView |
|
|
216 |
xpos := (width - childView widthIncludingBorder) // 2.
|
|
217 |
(xpos < 0) ifTrue:[ xpos := 0 ].
|
|
218 |
|
|
219 |
childView origin:(xpos@ypos).
|
|
220 |
ypos := ypos + (childView heightIncludingBorder) + space
|
|
221 |
]
|
|
222 |
! !
|