0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
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
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
63
|
24 |
$Header: /cvs/stx/stx/libwidg/VerticalPanelView.st,v 1.6 1994-11-17 14:38:46 claus Exp $
|
38
|
25 |
'!
|
|
26 |
|
|
27 |
!VerticalPanelView class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
38
|
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 |
"
|
63
|
45 |
$Header: /cvs/stx/stx/libwidg/VerticalPanelView.st,v 1.6 1994-11-17 14:38:46 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
a View which arranges its child-views in a vertical column.
|
63
|
52 |
All real work is done in PanelView - except the layout computation is
|
38
|
53 |
redefined here.
|
|
54 |
|
63
|
55 |
The layout is controlled by two instance variables.
|
|
56 |
The vertical layout can be any of:
|
|
57 |
|
|
58 |
#top arrange elements at the top
|
|
59 |
#topSpace arrange elements at the top, start with spacing
|
|
60 |
#bottom arrange elements at the bottom
|
|
61 |
#bottomSpace arrange elements at the bottom, start with spacing
|
|
62 |
#center arrange elements in the center
|
|
63 |
#spread spread elements evenly
|
|
64 |
#fit like spread, but resize elements for tight packing
|
|
65 |
|
|
66 |
the horizontal layout can be:
|
|
67 |
|
|
68 |
#left place element at the left
|
|
69 |
#leftSpace place element at the left, offset by horizontalSpace
|
|
70 |
#center place it horizontally centered
|
|
71 |
#right place it at the right
|
|
72 |
#rightSpace place it at the right, offset by horizontalSpace
|
|
73 |
#fit resize elements horizontally to fit this panel
|
|
74 |
|
|
75 |
The defaults is #centered for both directions.
|
|
76 |
The layout is changed by the messages #verticalLayout: and #horizontalLayout:.
|
|
77 |
For backward compatibility (to times, where only vLayout existed), the simple
|
|
78 |
#layout: does the same as #verticalLayout:. Do not use this old method.
|
|
79 |
"
|
|
80 |
!
|
|
81 |
|
|
82 |
examples
|
|
83 |
"
|
38
|
84 |
example: default layout (centered)
|
|
85 |
|
59
|
86 |
|v p b1 b2 b3|
|
38
|
87 |
|
59
|
88 |
v := StandardSystemView new.
|
|
89 |
p := VerticalPanelView in:v.
|
|
90 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
91 |
b1 := Button label:'button1' in:p.
|
|
92 |
b2 := Button label:'button2' in:p.
|
|
93 |
b3 := Button label:'button3' in:p.
|
|
94 |
v extent:100 @ 300.
|
|
95 |
v open
|
38
|
96 |
|
0
|
97 |
|
63
|
98 |
example: top-layout
|
38
|
99 |
|
59
|
100 |
|v p b1 b2 b3|
|
38
|
101 |
|
59
|
102 |
v := StandardSystemView new.
|
|
103 |
p := VerticalPanelView in:v.
|
63
|
104 |
p verticalLayout:#top.
|
59
|
105 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
106 |
b1 := Button label:'button1' in:p.
|
|
107 |
b2 := Button label:'button2' in:p.
|
|
108 |
b3 := Button label:'button3' in:p.
|
|
109 |
v extent:100 @ 300.
|
|
110 |
v open
|
38
|
111 |
|
|
112 |
|
63
|
113 |
example: bottom-layout
|
38
|
114 |
|
59
|
115 |
|v p b1 b2 b3|
|
0
|
116 |
|
59
|
117 |
v := StandardSystemView new.
|
|
118 |
p := VerticalPanelView in:v.
|
63
|
119 |
p verticalLayout:#bottom.
|
59
|
120 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
121 |
b1 := Button label:'button1' in:p.
|
|
122 |
b2 := Button label:'button2' in:p.
|
|
123 |
b3 := Button label:'button3' in:p.
|
|
124 |
v extent:100 @ 300.
|
|
125 |
v open
|
38
|
126 |
|
|
127 |
|
|
128 |
example: spread-layout
|
|
129 |
|
59
|
130 |
|v p b1 b2 b3|
|
38
|
131 |
|
59
|
132 |
v := StandardSystemView new.
|
|
133 |
p := VerticalPanelView in:v.
|
63
|
134 |
p verticalLayout:#spread.
|
|
135 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
136 |
b1 := Button label:'button1' in:p.
|
|
137 |
b2 := Button label:'button2' in:p.
|
|
138 |
b3 := Button label:'button3' in:p.
|
|
139 |
v extent:100 @ 300.
|
|
140 |
v open
|
|
141 |
|
|
142 |
example: from top, each at left:
|
|
143 |
|
|
144 |
|v p b1 b2 b3|
|
|
145 |
|
|
146 |
v := StandardSystemView new.
|
|
147 |
p := VerticalPanelView in:v.
|
|
148 |
p verticalLayout:#top.
|
|
149 |
p horizontalLayout:#left.
|
|
150 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
151 |
b1 := Button label:'button1' in:p.
|
|
152 |
b2 := Button label:'button2' in:p.
|
|
153 |
b3 := Button label:'button3' in:p.
|
|
154 |
v extent:100 @ 300.
|
|
155 |
v open
|
|
156 |
|
|
157 |
example: centered, right:
|
|
158 |
|
|
159 |
|v p b1 b2 b3|
|
|
160 |
|
|
161 |
v := StandardSystemView new.
|
|
162 |
p := VerticalPanelView in:v.
|
|
163 |
p verticalLayout:#centered.
|
|
164 |
p horizontalLayout:#right.
|
59
|
165 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
166 |
b1 := Button label:'button1' in:p.
|
|
167 |
b2 := Button label:'button2' in:p.
|
|
168 |
b3 := Button label:'button3' in:p.
|
|
169 |
v extent:100 @ 300.
|
|
170 |
v open
|
63
|
171 |
|
|
172 |
you should try more examples, combining spacing and different
|
|
173 |
verticalLayout:/horizontalLayout: combinations.
|
38
|
174 |
"
|
|
175 |
! !
|
0
|
176 |
|
63
|
177 |
!VerticalPanelView methodsFor:'accessing'!
|
|
178 |
|
|
179 |
horizontalLayout
|
|
180 |
"return the horizontal layout as symbol.
|
|
181 |
the returned value is one of
|
|
182 |
#left
|
|
183 |
#leftSpace
|
|
184 |
#center
|
|
185 |
#right
|
|
186 |
#rightSpace
|
|
187 |
#fit
|
|
188 |
the default is #centered
|
|
189 |
"
|
|
190 |
|
|
191 |
^ hLayout
|
|
192 |
!
|
|
193 |
|
|
194 |
verticalLayout
|
|
195 |
"return the vertical layout as a symbol.
|
|
196 |
the returned value is one of
|
|
197 |
#top
|
|
198 |
#topSpace
|
|
199 |
#spread
|
|
200 |
#fit
|
|
201 |
#center
|
|
202 |
#bottom
|
|
203 |
#bottomSpace
|
|
204 |
the default is #centered
|
|
205 |
"
|
|
206 |
|
|
207 |
^ vLayout
|
|
208 |
!
|
|
209 |
|
|
210 |
horizontalLayout:aSymbol
|
|
211 |
"change the horizontal layout as symbol.
|
|
212 |
The argument, aSymbol must be one of:
|
|
213 |
#left
|
|
214 |
#leftSpace
|
|
215 |
#center
|
|
216 |
#right
|
|
217 |
#rightSpace
|
|
218 |
#fit
|
|
219 |
the default (if never changed) is #centered
|
|
220 |
"
|
|
221 |
|
|
222 |
(hLayout ~~ aSymbol) ifTrue:[
|
|
223 |
hLayout := aSymbol.
|
|
224 |
self layoutChanged
|
|
225 |
]
|
|
226 |
!
|
|
227 |
|
|
228 |
verticalLayout:aSymbol
|
|
229 |
"change the vertical layout as a symbol.
|
|
230 |
The argument, aSymbol must be one of:
|
|
231 |
#top
|
|
232 |
#topSpace
|
|
233 |
#spread
|
|
234 |
#fit
|
|
235 |
#center
|
|
236 |
#bottom
|
|
237 |
#bottomSpace
|
|
238 |
the default (if never changed) is #centered
|
|
239 |
"
|
|
240 |
|
|
241 |
(vLayout ~~ aSymbol) ifTrue:[
|
|
242 |
vLayout := aSymbol.
|
|
243 |
self layoutChanged
|
|
244 |
]
|
|
245 |
!
|
|
246 |
|
|
247 |
layout
|
|
248 |
"leftover for historic reasons - do not use any more"
|
|
249 |
|
|
250 |
self verticalLayout
|
|
251 |
!
|
|
252 |
|
|
253 |
layout:aSymbol
|
|
254 |
"leftover for historic reasons - do not use any more"
|
|
255 |
|
|
256 |
self verticalLayout:aSymbol
|
|
257 |
! !
|
|
258 |
|
|
259 |
|
0
|
260 |
!VerticalPanelView methodsFor:'queries'!
|
|
261 |
|
|
262 |
preferedExtent
|
|
263 |
"return a good extent, one that makes subviews fit"
|
|
264 |
|
59
|
265 |
|sumOfHeights maxWidth maxHeight|
|
0
|
266 |
|
|
267 |
subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace].
|
|
268 |
|
|
269 |
"compute net height needed"
|
|
270 |
|
|
271 |
sumOfHeights := 0.
|
|
272 |
maxWidth := 0.
|
|
273 |
|
|
274 |
subViews do:[:child |
|
63
|
275 |
|childsPreference|
|
|
276 |
|
|
277 |
childsPreference := child preferedExtent.
|
|
278 |
sumOfHeights := sumOfHeights + childsPreference y.
|
|
279 |
maxHeight := maxHeight max:childsPreference y.
|
|
280 |
maxWidth := maxWidth max:childsPreference x.
|
|
281 |
|
|
282 |
"/ sumOfHeights := sumOfHeights + child heightIncludingBorder.
|
|
283 |
"/ maxWidth := maxWidth max:(child widthIncludingBorder).
|
|
284 |
"/ maxHeight := maxHeight max:(child heightIncludingBorder).
|
0
|
285 |
].
|
|
286 |
borderWidth ~~ 0 ifTrue:[
|
59
|
287 |
sumOfHeights := sumOfHeights + (horizontalSpace * 2).
|
|
288 |
maxWidth := maxWidth + (horizontalSpace * 2).
|
0
|
289 |
].
|
|
290 |
sumOfHeights := sumOfHeights + ((subViews size - 1) * verticalSpace).
|
|
291 |
|
|
292 |
^ maxWidth @ sumOfHeights
|
|
293 |
! !
|
|
294 |
|
|
295 |
!VerticalPanelView methodsFor:'layout'!
|
|
296 |
|
|
297 |
setChildPositions
|
|
298 |
"(re)compute position of every child"
|
|
299 |
|
63
|
300 |
|ypos space sumOfHeights numChilds l hEach|
|
0
|
301 |
|
|
302 |
subViews isNil ifTrue:[^ self].
|
|
303 |
|
|
304 |
space := verticalSpace.
|
63
|
305 |
numChilds := subViews size.
|
0
|
306 |
|
63
|
307 |
vLayout == #fit ifTrue:[
|
59
|
308 |
"
|
|
309 |
adjust childs extents and set origins.
|
|
310 |
Be careful to avoid accumulation of rounding errors
|
|
311 |
"
|
|
312 |
hEach := (height - (margin * 2) - (numChilds + 1 * space) + borderWidth) / numChilds.
|
|
313 |
ypos := space + margin - borderWidth.
|
63
|
314 |
] ifFalse:[
|
|
315 |
|
|
316 |
"
|
|
317 |
compute net height needed
|
|
318 |
"
|
|
319 |
sumOfHeights := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child heightIncludingBorder].
|
|
320 |
|
|
321 |
l := vLayout.
|
|
322 |
((l == #center) and:[numChilds == 1]) ifTrue:[
|
|
323 |
l := #spread
|
|
324 |
].
|
|
325 |
|
|
326 |
"
|
|
327 |
compute position of topmost subview and space between them;
|
|
328 |
if they do hardly fit, leave no space between them
|
|
329 |
"
|
|
330 |
(sumOfHeights >= (height - (margin * 2))) ifTrue:[
|
|
331 |
"
|
|
332 |
if we have not enough space for all the elements,
|
|
333 |
fill them tight, and show what can be shown (at least)
|
|
334 |
"
|
|
335 |
ypos := 0.
|
|
336 |
space := 0
|
|
337 |
] ifFalse:[
|
|
338 |
((l == #bottom) or:[l == #bottomSpace]) ifTrue:[
|
|
339 |
ypos := height - (space * numChilds) - sumOfHeights.
|
|
340 |
"
|
|
341 |
borderWidth == 0 ifTrue:[
|
|
342 |
ypos := ypos + space
|
|
343 |
].
|
|
344 |
"
|
|
345 |
l == #bottomSpace ifTrue:[
|
|
346 |
ypos > space ifTrue:[
|
|
347 |
ypos := ypos - space
|
|
348 |
]
|
|
349 |
].
|
59
|
350 |
|
63
|
351 |
ypos < 0 ifTrue:[
|
|
352 |
space := space min:(height - sumOfHeights) // (numChilds + 1).
|
|
353 |
ypos := height - (space * numChilds) - sumOfHeights.
|
|
354 |
]
|
|
355 |
] ifFalse: [
|
|
356 |
(l == #spread) ifTrue:[
|
|
357 |
space := (height - sumOfHeights) // (numChilds + 1).
|
|
358 |
ypos := space.
|
|
359 |
(space == 0) ifTrue:[
|
|
360 |
ypos := (height - sumOfHeights) // 2
|
|
361 |
]
|
|
362 |
] ifFalse: [
|
|
363 |
((l == #top) or:[l == #topSpace]) ifTrue:[
|
|
364 |
"
|
|
365 |
borderWidth == 0 ifTrue:[
|
|
366 |
ypos := 0
|
|
367 |
] ifFalse:[
|
|
368 |
ypos := verticalSpace
|
|
369 |
].
|
|
370 |
"
|
|
371 |
space := space min:(height - sumOfHeights) // (numChilds + 1).
|
|
372 |
l == #topSpace ifTrue:[
|
|
373 |
ypos := space.
|
|
374 |
] ifFalse:[
|
|
375 |
ypos := 0
|
|
376 |
]
|
|
377 |
] ifFalse:[
|
|
378 |
"center"
|
|
379 |
ypos := (height - (sumOfHeights
|
|
380 |
+ ((numChilds - 1) * space))) // 2.
|
|
381 |
ypos < 0 ifTrue:[
|
|
382 |
space := (height - sumOfHeights) // (numChilds + 1).
|
|
383 |
ypos := (height - (sumOfHeights
|
|
384 |
+ ((numChilds - 1) * space))) // 2.
|
|
385 |
]
|
|
386 |
]
|
|
387 |
]
|
|
388 |
]
|
|
389 |
].
|
|
390 |
].
|
|
391 |
|
|
392 |
"
|
|
393 |
now set positions
|
|
394 |
"
|
|
395 |
subViews do:[:child |
|
|
396 |
|xpos|
|
|
397 |
|
|
398 |
hLayout == #left ifTrue:[
|
|
399 |
xpos := 0
|
|
400 |
] ifFalse:[
|
|
401 |
hLayout == #leftSpace ifTrue:[
|
|
402 |
xpos := horizontalSpace
|
|
403 |
] ifFalse:[
|
|
404 |
hLayout == #right ifTrue:[
|
|
405 |
xpos := width - child widthIncludingBorder
|
|
406 |
] ifFalse:[
|
|
407 |
hLayout == #rightSpace ifTrue:[
|
|
408 |
xpos := width - horizontalSpace - child widthIncludingBorder.
|
|
409 |
] ifFalse:[
|
|
410 |
hLayout == #fit ifTrue:[
|
|
411 |
xpos := horizontalSpace.
|
|
412 |
child width:(width - (horizontalSpace + child borderWidth * 2))
|
|
413 |
] ifFalse:[
|
|
414 |
"centered"
|
|
415 |
xpos := (width - child widthIncludingBorder) // 2.
|
|
416 |
]
|
|
417 |
]
|
|
418 |
]
|
|
419 |
]
|
|
420 |
].
|
|
421 |
(xpos < 0) ifTrue:[ xpos := 0 ].
|
|
422 |
|
|
423 |
vLayout == #fit ifTrue:[
|
59
|
424 |
child origin:(xpos @ ypos rounded)
|
|
425 |
corner:(xpos + (child width))
|
|
426 |
@ (ypos + hEach - (child borderWidth)) rounded.
|
|
427 |
ypos := ypos + hEach + "(child borderWidth * 2) +" space
|
63
|
428 |
] ifFalse:[
|
|
429 |
child origin:(xpos@ypos).
|
|
430 |
ypos := ypos + (child heightIncludingBorder) + space
|
59
|
431 |
]
|
0
|
432 |
]
|
|
433 |
! !
|