author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 17:23:54 +0100 | |
changeset 174 | d80a6cc3f9b2 |
parent 155 | d6f3836d2b51 |
child 202 | 01f3cbb8e20e |
permissions | -rw-r--r-- |
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 |
||
125 | 13 |
'From Smalltalk/X, Version:2.10.5 on 9-may-1995 at 12:07:08 pm'! |
14 |
||
0 | 15 |
PanelView subclass:#VerticalPanelView |
125 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Layout' |
|
0 | 20 |
! |
21 |
||
38 | 22 |
!VerticalPanelView class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 27 |
All Rights Reserved |
38 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
version |
|
174
d80a6cc3f9b2
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
155
diff
changeset
|
39 |
^ '$Header: /cvs/stx/stx/libwidg/VerticalPanelView.st,v 1.15 1995-11-11 16:23:31 cg Exp $' |
38 | 40 |
! |
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
a View which arranges its child-views in a vertical column. |
|
63 | 45 |
All real work is done in PanelView - except the layout computation is |
38 | 46 |
redefined here. |
47 |
||
127 | 48 |
The layout is controlled by the instance variables: |
77 | 49 |
horizontalLayout and verticalLayout |
127 | 50 |
in addition to |
51 |
horizontalSpace and verticalSpace. |
|
77 | 52 |
|
63 | 53 |
The vertical layout can be any of: |
54 |
||
55 |
#top arrange elements at the top |
|
56 |
#topSpace arrange elements at the top, start with spacing |
|
57 |
#bottom arrange elements at the bottom |
|
58 |
#bottomSpace arrange elements at the bottom, start with spacing |
|
127 | 59 |
#center arrange elements in the center; ignore verticalSpace |
60 |
#spread spread elements evenly; ignore verticalSpace |
|
61 |
#spreadSpace spread elements evenly with spacing at ends; ignore verticalSpace |
|
133 | 62 |
#fit like #spread, but resize elements for tight packing; ignore verticalSpace |
63 |
#fitSpace like #fit, with spacing; ignore verticalSpace |
|
64 |
#topFit like #top, but extend the last element to the bottom |
|
65 |
#topSpaceFit like #topSpace, but extend the last element to the bottom |
|
63 | 66 |
|
67 |
the horizontal layout can be: |
|
68 |
||
69 |
#left place element at the left |
|
70 |
#leftSpace place element at the left, offset by horizontalSpace |
|
127 | 71 |
#center place elements horizontally centered; ignore horizontalSpace |
63 | 72 |
#right place it at the right |
73 |
#rightSpace place it at the right, offset by horizontalSpace |
|
127 | 74 |
#fit resize elements horizontally to fit this panel; ignore horizontalSpace |
133 | 75 |
#fitSpace like #fit, but add spacing; ignore horizontalSpace |
127 | 76 |
|
77 |
#leftMax like #left, but resize elements to max of them |
|
78 |
#leftSpaceMax like #leftSpace, but resize elements |
|
79 |
#centerMax like #center, but resize elements |
|
80 |
#rightMax like #right, but resize elements to max of them |
|
81 |
#rightSpaceMax like #rightSpace, but resize elements |
|
63 | 82 |
|
77 | 83 |
The defaults is #center for both directions. |
127 | 84 |
|
63 | 85 |
The layout is changed by the messages #verticalLayout: and #horizontalLayout:. |
86 |
For backward compatibility (to times, where only vLayout existed), the simple |
|
87 |
#layout: does the same as #verticalLayout:. Do not use this old method. |
|
77 | 88 |
|
127 | 89 |
The panel assumes, that the elements do not resize themselfes, after it |
90 |
became visible. This is not true for all widgets (buttons or labels may |
|
91 |
like to change). If you have changing elements, tell this to the panel |
|
92 |
with 'aPanel elementsChangeSize:true'. In that case, the panel will react |
|
93 |
to size changes, and reorganize things. |
|
94 |
||
77 | 95 |
If none of these layout/space combinations is exactly what you need in |
96 |
your application, create a subclass, and redefine the setChildPositions method. |
|
127 | 97 |
|
98 |
CAVEAT: this class started with #top and no horizontal alignments; |
|
99 |
as time went by, more layouts were added and the setup should be changed |
|
100 |
to use different selectors for space, max-resize and alignment |
|
101 |
(i.e. having more and more layout symbols makes things a bit confusing ...) |
|
63 | 102 |
" |
103 |
! |
|
104 |
||
105 |
examples |
|
106 |
" |
|
77 | 107 |
These examples demonstrate the effect of different layout |
108 |
settings. |
|
109 |
You should try more examples, combining spacing and different |
|
110 |
verticalLayout:/horizontalLayout: combinations. |
|
111 |
||
112 |
||
38 | 113 |
example: default layout (centered) |
114 |
||
127 | 115 |
|v p b1 b2 b3| |
116 |
||
117 |
v := StandardSystemView new. |
|
118 |
v label:'center (default)'. |
|
119 |
p := VerticalPanelView in:v. |
|
120 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
121 |
b1 := Button label:'button1' in:p. |
|
122 |
b2 := Button label:'b2' in:p. |
|
123 |
b3 := Button label:'butt3' in:p. |
|
124 |
v extent:100 @ 300. |
|
125 |
v open |
|
126 |
||
127 |
||
128 |
example: horizontal centerMax |
|
129 |
||
130 |
|v p b1 b2 b3| |
|
131 |
||
132 |
v := StandardSystemView new. |
|
133 |
v label:'hL=centerMax'. |
|
134 |
p := VerticalPanelView in:v. |
|
135 |
p horizontalLayout:#centerMax. |
|
136 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
137 |
b1 := Button label:'button1' in:p. |
|
138 |
b2 := Button label:'b2' in:p. |
|
139 |
b3 := Button label:'butt3' in:p. |
|
140 |
v extent:100 @ 300. |
|
141 |
v open |
|
142 |
||
143 |
||
144 |
example: horizontal leftMax |
|
145 |
||
146 |
|v p b1 b2 b3| |
|
147 |
||
148 |
v := StandardSystemView new. |
|
149 |
v label:'hL=leftMax'. |
|
150 |
p := VerticalPanelView in:v. |
|
151 |
p horizontalLayout:#leftMax. |
|
152 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
153 |
b1 := Button label:'button1' in:p. |
|
154 |
b2 := Button label:'b2' in:p. |
|
155 |
b3 := Button label:'butt3' in:p. |
|
156 |
v extent:100 @ 300. |
|
157 |
v open |
|
158 |
||
38 | 159 |
|
127 | 160 |
example: horizontal leftSpaceMax |
161 |
||
162 |
|v p b1 b2 b3| |
|
163 |
||
164 |
v := StandardSystemView new. |
|
165 |
v label:'hL=leftMax'. |
|
166 |
p := VerticalPanelView in:v. |
|
167 |
p horizontalLayout:#leftSpaceMax. |
|
168 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
169 |
b1 := Button label:'button1' in:p. |
|
170 |
b2 := Button label:'b2' in:p. |
|
171 |
b3 := Button label:'butt3' in:p. |
|
172 |
v extent:100 @ 300. |
|
173 |
v open |
|
174 |
||
175 |
||
176 |
example: horizontal rightMax |
|
177 |
||
178 |
|v p b1 b2 b3| |
|
179 |
||
180 |
v := StandardSystemView new. |
|
181 |
v label:'hL=rightMax'. |
|
182 |
p := VerticalPanelView in:v. |
|
183 |
p horizontalLayout:#rightMax. |
|
184 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
185 |
b1 := Button label:'button1' in:p. |
|
186 |
b2 := Button label:'b2' in:p. |
|
187 |
b3 := Button label:'butt3' in:p. |
|
188 |
v extent:100 @ 300. |
|
189 |
v open |
|
190 |
||
191 |
||
192 |
example: horizontal rightSpaceMax |
|
193 |
||
194 |
|v p b1 b2 b3| |
|
195 |
||
196 |
v := StandardSystemView new. |
|
197 |
v label:'hL=rightMaxSpace'. |
|
198 |
p := VerticalPanelView in:v. |
|
199 |
p horizontalLayout:#rightSpaceMax. |
|
200 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
201 |
b1 := Button label:'button1' in:p. |
|
202 |
b2 := Button label:'b2' in:p. |
|
203 |
b3 := Button label:'butt3' in:p. |
|
204 |
v extent:100 @ 300. |
|
205 |
v open |
|
38 | 206 |
|
0 | 207 |
|
63 | 208 |
example: top-layout |
38 | 209 |
|
127 | 210 |
|v p b1 b2 b3| |
211 |
||
212 |
v := StandardSystemView new. |
|
213 |
v label:'vL=top; hL=center (default)'. |
|
214 |
p := VerticalPanelView in:v. |
|
215 |
p verticalLayout:#top. |
|
216 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
217 |
b1 := Button label:'button1' in:p. |
|
218 |
b2 := Button label:'butt2' in:p. |
|
219 |
b3 := Button label:'button3' in:p. |
|
220 |
v extent:100 @ 300. |
|
221 |
v open |
|
222 |
||
38 | 223 |
|
127 | 224 |
example: topSpace-layout |
225 |
||
226 |
|v p b1 b2 b3| |
|
227 |
||
228 |
v := StandardSystemView new. |
|
229 |
v label:'vL=topSpace; hL=center (default)'. |
|
230 |
p := VerticalPanelView in:v. |
|
231 |
p verticalLayout:#topSpace. |
|
232 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
233 |
b1 := Button label:'button1' in:p. |
|
234 |
b2 := Button label:'butt2' in:p. |
|
235 |
b3 := Button label:'button3' in:p. |
|
236 |
v extent:100 @ 300. |
|
237 |
v open |
|
38 | 238 |
|
239 |
||
77 | 240 |
example: top-layout; horizontal fit |
241 |
||
127 | 242 |
|v p b1 b2 b3| |
77 | 243 |
|
127 | 244 |
v := StandardSystemView new. |
245 |
p := VerticalPanelView in:v. |
|
246 |
v label:'vL=top; hL=fit'. |
|
247 |
p verticalLayout:#top. |
|
248 |
p horizontalLayout:#fit. |
|
249 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
250 |
b1 := Button label:'button1' in:p. |
|
251 |
b2 := Button label:'butt2' in:p. |
|
252 |
b3 := Button label:'button3' in:p. |
|
253 |
v extent:100 @ 300. |
|
254 |
v open |
|
77 | 255 |
|
256 |
||
257 |
example: top-layout; horizontal fit with space |
|
258 |
||
127 | 259 |
|v p b1 b2 b3| |
77 | 260 |
|
127 | 261 |
v := StandardSystemView new. |
262 |
v label:'vL=top; hL=fitSpace'. |
|
263 |
p := VerticalPanelView in:v. |
|
264 |
p verticalLayout:#top. |
|
265 |
p horizontalLayout:#fitSpace. |
|
266 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
267 |
b1 := Button label:'button1' in:p. |
|
268 |
b2 := Button label:'butt2' in:p. |
|
269 |
b3 := Button label:'button3' in:p. |
|
270 |
v extent:100 @ 300. |
|
271 |
v open |
|
77 | 272 |
|
273 |
||
127 | 274 |
example: topSpace-layout; horizontal fit with space |
77 | 275 |
|
127 | 276 |
|v p b1 b2 b3| |
77 | 277 |
|
127 | 278 |
v := StandardSystemView new. |
279 |
v label:'vL=topSpace; hL=fitSpace'. |
|
280 |
p := VerticalPanelView in:v. |
|
281 |
p verticalLayout:#topSpace. |
|
282 |
p horizontalLayout:#fitSpace. |
|
283 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
284 |
b1 := Button label:'button1' in:p. |
|
285 |
b2 := Button label:'butt2' in:p. |
|
286 |
b3 := Button label:'button3' in:p. |
|
287 |
v extent:100 @ 300. |
|
288 |
v open |
|
77 | 289 |
|
290 |
||
63 | 291 |
example: bottom-layout |
38 | 292 |
|
127 | 293 |
|v p b1 b2 b3| |
0 | 294 |
|
127 | 295 |
v := StandardSystemView new. |
296 |
v label:'vL=bottom; hL=center (default)'. |
|
297 |
p := VerticalPanelView in:v. |
|
298 |
p verticalLayout:#bottom. |
|
299 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
300 |
b1 := Button label:'button1' in:p. |
|
301 |
b2 := Button label:'butt2' in:p. |
|
302 |
b3 := Button label:'button3' in:p. |
|
303 |
v extent:100 @ 300. |
|
304 |
v open |
|
38 | 305 |
|
306 |
||
77 | 307 |
example: bottomSpace-layout |
308 |
||
127 | 309 |
|v p b1 b2 b3| |
77 | 310 |
|
127 | 311 |
v := StandardSystemView new. |
312 |
v label:'vL=bottomSpace; hL=center (default)'. |
|
313 |
p := VerticalPanelView in:v. |
|
314 |
p verticalLayout:#bottomSpace. |
|
315 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
316 |
b1 := Button label:'button1' in:p. |
|
317 |
b2 := Button label:'butt2' in:p. |
|
318 |
b3 := Button label:'button3' in:p. |
|
319 |
v extent:100 @ 300. |
|
320 |
v open |
|
77 | 321 |
|
322 |
||
133 | 323 |
example: topFit-layout |
324 |
||
325 |
|v p b1 b2 b3| |
|
326 |
||
327 |
v := StandardSystemView new. |
|
328 |
v label:'vL=topFit; hL=center (default)'. |
|
329 |
p := VerticalPanelView in:v. |
|
330 |
p verticalLayout:#topFit. |
|
331 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
332 |
b1 := Button label:'button1' in:p. |
|
333 |
b2 := Button label:'butt2' in:p. |
|
334 |
b3 := Button label:'button3' in:p. |
|
335 |
v extent:100 @ 300. |
|
336 |
v open |
|
337 |
||
338 |
||
339 |
example: topSpaceFit-layout; combined with horizontal #fitSpace |
|
340 |
||
341 |
|v p b1 b2 b3| |
|
342 |
||
343 |
v := StandardSystemView new. |
|
344 |
v label:'vL=topFit; hL=center (default)'. |
|
345 |
p := VerticalPanelView in:v. |
|
346 |
p verticalLayout:#topSpaceFit. |
|
347 |
p horizontalLayout:#fitSpace. |
|
348 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
349 |
b1 := Button label:'button1' in:p. |
|
350 |
b2 := Button label:'butt2' in:p. |
|
351 |
b3 := Button label:'button3' in:p. |
|
352 |
v extent:100 @ 300. |
|
353 |
v open |
|
354 |
||
355 |
||
38 | 356 |
example: spread-layout |
357 |
||
127 | 358 |
|v p b1 b2 b3| |
38 | 359 |
|
127 | 360 |
v := StandardSystemView new. |
361 |
v label:'vL=spread; hL=center (default)'. |
|
362 |
p := VerticalPanelView in:v. |
|
363 |
p verticalLayout:#spread. |
|
364 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
365 |
b1 := Button label:'button1' in:p. |
|
366 |
b2 := Button label:'butt2' in:p. |
|
367 |
b3 := Button label:'button3' in:p. |
|
368 |
v extent:100 @ 300. |
|
369 |
v open |
|
63 | 370 |
|
77 | 371 |
|
372 |
example: spreadSpace-layout |
|
373 |
||
127 | 374 |
|v p b1 b2 b3| |
77 | 375 |
|
127 | 376 |
v := StandardSystemView new. |
377 |
v label:'vL=spreadSpace; hL=center (default)'. |
|
378 |
p := VerticalPanelView in:v. |
|
379 |
p verticalLayout:#spreadSpace. |
|
380 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
381 |
b1 := Button label:'button1' in:p. |
|
382 |
b2 := Button label:'butt2' in:p. |
|
383 |
b3 := Button label:'button3' in:p. |
|
384 |
v extent:100 @ 300. |
|
385 |
v open |
|
77 | 386 |
|
387 |
||
388 |
example: fit-layout |
|
389 |
||
127 | 390 |
|v p b1 b2 b3| |
77 | 391 |
|
127 | 392 |
v := StandardSystemView new. |
393 |
v label:'vL=fit; hL=center (default)'. |
|
394 |
p := VerticalPanelView in:v. |
|
395 |
p verticalLayout:#fit. |
|
396 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
397 |
b1 := Button label:'button1' in:p. |
|
398 |
b2 := Button label:'butt2' in:p. |
|
399 |
b3 := Button label:'button3' in:p. |
|
400 |
v extent:100 @ 300. |
|
401 |
v open |
|
77 | 402 |
|
403 |
||
404 |
example: fitSpace-layout |
|
405 |
||
127 | 406 |
|v p b1 b2 b3| |
77 | 407 |
|
127 | 408 |
v := StandardSystemView new. |
409 |
v label:'vL=fitSpace; hL=center (default)'. |
|
410 |
p := VerticalPanelView in:v. |
|
411 |
p verticalLayout:#fitSpace. |
|
412 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
413 |
b1 := Button label:'button1' in:p. |
|
414 |
b2 := Button label:'butt2' in:p. |
|
415 |
b3 := Button label:'button3' in:p. |
|
416 |
v extent:100 @ 300. |
|
417 |
v open |
|
77 | 418 |
|
419 |
||
420 |
example: fully fitSpace |
|
421 |
||
127 | 422 |
|v p b1 b2 b3| |
77 | 423 |
|
127 | 424 |
v := StandardSystemView new. |
425 |
v label:'vL=fitSpace; hL=fitSpace'. |
|
426 |
p := VerticalPanelView in:v. |
|
427 |
p verticalLayout:#fitSpace. |
|
428 |
p horizontalLayout:#fitSpace. |
|
429 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
430 |
b1 := Button label:'button1' in:p. |
|
431 |
b2 := Button label:'butt2' in:p. |
|
432 |
b3 := Button label:'button3' in:p. |
|
433 |
v extent:100 @ 300. |
|
434 |
v open |
|
77 | 435 |
|
436 |
||
131 | 437 |
example: combine fully fitSpace with scaling button labels |
438 |
||
439 |
|v p b1 b2 b3| |
|
440 |
||
441 |
v := StandardSystemView new. |
|
442 |
v label:'vL=fitSpace; hL=fitSpace'. |
|
443 |
p := VerticalPanelView in:v. |
|
444 |
p verticalLayout:#fitSpace. |
|
445 |
p horizontalLayout:#fitSpace. |
|
446 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
447 |
b1 := Button label:'button1' in:p. |
|
448 |
b1 adjust:#fit. |
|
449 |
b2 := Button label:'butt2' in:p. |
|
450 |
b2 adjust:#fit. |
|
451 |
b3 := Button label:'button3' in:p. |
|
452 |
b3 adjust:#fit. |
|
453 |
v extent:100 @ 300. |
|
454 |
v open |
|
455 |
||
456 |
||
63 | 457 |
example: from top, each at left: |
458 |
||
127 | 459 |
|v p b1 b2 b3| |
63 | 460 |
|
127 | 461 |
v := StandardSystemView new. |
462 |
v label:'vL=top; hL=left'. |
|
463 |
p := VerticalPanelView in:v. |
|
464 |
p verticalLayout:#top. |
|
465 |
p horizontalLayout:#left. |
|
466 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
467 |
b1 := Button label:'button1' in:p. |
|
468 |
b2 := Button label:'butt2' in:p. |
|
469 |
b3 := Button label:'button3' in:p. |
|
470 |
v extent:100 @ 300. |
|
471 |
v open |
|
63 | 472 |
|
77 | 473 |
|
127 | 474 |
example: center, right: |
63 | 475 |
|
127 | 476 |
|v p b1 b2 b3| |
63 | 477 |
|
127 | 478 |
v := StandardSystemView new. |
479 |
v label:'vL=center; hL=right'. |
|
480 |
p := VerticalPanelView in:v. |
|
481 |
p verticalLayout:#center. |
|
482 |
p horizontalLayout:#right. |
|
483 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
484 |
b1 := Button label:'button1' in:p. |
|
485 |
b2 := Button label:'butt2' in:p. |
|
486 |
b3 := Button label:'button3' in:p. |
|
487 |
v extent:100 @ 300. |
|
488 |
v open |
|
63 | 489 |
|
77 | 490 |
|
491 |
example: a panel in a panel |
|
492 |
||
127 | 493 |
|v hp p b1 b2 b3| |
77 | 494 |
|
127 | 495 |
v := StandardSystemView new. |
63 | 496 |
|
127 | 497 |
hp := HorizontalPanelView in:v. |
498 |
hp verticalLayout:#fit. |
|
499 |
hp horizontalLayout:#fitSpace. |
|
500 |
hp origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
63 | 501 |
|
127 | 502 |
1 to:3 do:[:i | |
503 |
p := VerticalPanelView in:hp. |
|
504 |
p borderWidth:0. |
|
505 |
p verticalLayout:#fitSpace. |
|
506 |
p horizontalLayout:#fit. |
|
507 |
b1 := Button label:('button1-' , i printString) in:p. |
|
508 |
b2 := Button label:('butt2-' , i printString) in:p. |
|
509 |
b3 := Button label:('button3-' , i printString) in:p. |
|
510 |
]. |
|
63 | 511 |
|
127 | 512 |
v extent:300 @ 100. |
513 |
v open |
|
514 |
||
0 | 515 |
|
125 | 516 |
example: checkToggles in a panel |
0 | 517 |
|
127 | 518 |
|panel| |
63 | 519 |
|
127 | 520 |
panel := VerticalPanelView new. |
521 |
panel horizontalLayout:#left. |
|
63 | 522 |
|
127 | 523 |
panel add:((CheckBox on:true asValue) label:'this is toggle number 1'; resize). |
524 |
panel add:((CheckBox on:false asValue) label:'nr 2 '; resize). |
|
525 |
panel add:((CheckBox on:true asValue) label:'number 3 '; resize). |
|
0 | 526 |
|
130 | 527 |
panel extent:(panel preferredExtent). |
127 | 528 |
panel open |
125 | 529 |
" |
0 | 530 |
! ! |
531 |
||
532 |
!VerticalPanelView methodsFor:'layout'! |
|
533 |
||
534 |
setChildPositions |
|
535 |
"(re)compute position of every child" |
|
536 |
||
127 | 537 |
|ypos space sumOfHeights numChilds l hEach hInside maxWidth resizeToMax hL| |
0 | 538 |
|
539 |
subViews isNil ifTrue:[^ self]. |
|
540 |
||
541 |
space := verticalSpace. |
|
63 | 542 |
numChilds := subViews size. |
77 | 543 |
hInside := height - (margin * 2) + (borderWidth*2) - subViews last borderWidth. |
0 | 544 |
|
77 | 545 |
vLayout == #fitSpace ifTrue:[ |
59 | 546 |
" |
547 |
adjust childs extents and set origins. |
|
548 |
Be careful to avoid accumulation of rounding errors |
|
549 |
" |
|
77 | 550 |
hEach := (hInside - (numChilds + 1 * space)) / numChilds. |
59 | 551 |
ypos := space + margin - borderWidth. |
63 | 552 |
] ifFalse:[ |
77 | 553 |
vLayout == #fit ifTrue:[ |
63 | 554 |
" |
77 | 555 |
adjust childs extents and set origins. |
556 |
Be careful to avoid accumulation of rounding errors |
|
63 | 557 |
" |
77 | 558 |
hEach := (hInside - (numChilds - 1 * space)) / numChilds. |
559 |
ypos := margin - borderWidth. |
|
63 | 560 |
] ifFalse:[ |
77 | 561 |
" |
562 |
compute net height needed |
|
563 |
" |
|
564 |
sumOfHeights := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child heightIncludingBorder]. |
|
565 |
||
566 |
l := vLayout. |
|
567 |
((l == #center) and:[numChilds == 1]) ifTrue:[ |
|
568 |
l := #spread |
|
569 |
]. |
|
570 |
(l == #spread and:[numChilds == 1]) ifTrue:[ |
|
571 |
l := #spreadSpace |
|
572 |
]. |
|
59 | 573 |
|
77 | 574 |
" |
575 |
compute position of topmost subview and space between them; |
|
576 |
if they do hardly fit, leave no space between them |
|
577 |
" |
|
133 | 578 |
((sumOfHeights >= (height - (margin * 2))) |
579 |
and:[l ~~ #fixTopSpace and:[l ~~ #fixTop]]) ifTrue:[ |
|
77 | 580 |
" |
133 | 581 |
if we have not enough space for all the elements, |
77 | 582 |
fill them tight, and show what can be shown (at least) |
583 |
" |
|
584 |
ypos := 0. |
|
585 |
space := 0 |
|
586 |
] ifFalse:[ |
|
133 | 587 |
l == #fixTopSpace ifTrue:[ |
588 |
l := #topSpace |
|
589 |
] ifFalse:[ |
|
590 |
l == #fixTop ifTrue:[ |
|
591 |
l := #top |
|
592 |
] |
|
593 |
]. |
|
77 | 594 |
((l == #bottom) or:[l == #bottomSpace]) ifTrue:[ |
595 |
ypos := height - (space * (numChilds - 1)) - sumOfHeights. |
|
596 |
" |
|
597 |
borderWidth == 0 ifTrue:[ |
|
598 |
ypos := ypos + space |
|
599 |
]. |
|
600 |
" |
|
601 |
l == #bottomSpace ifTrue:[ |
|
602 |
ypos >= space ifTrue:[ |
|
603 |
ypos := ypos - space |
|
604 |
] |
|
605 |
]. |
|
606 |
||
607 |
ypos < 0 ifTrue:[ |
|
608 |
space := space min:(height - sumOfHeights) // (numChilds + 1). |
|
609 |
ypos := height - (space * numChilds) - sumOfHeights. |
|
63 | 610 |
] |
611 |
] ifFalse: [ |
|
77 | 612 |
(l == #spread) ifTrue:[ |
613 |
space := (height - sumOfHeights) // (numChilds - 1). |
|
614 |
ypos := 0. |
|
615 |
(space == 0) ifTrue:[ |
|
616 |
ypos := (height - sumOfHeights) // 2 |
|
617 |
] |
|
618 |
] ifFalse: [ |
|
619 |
(l == #spreadSpace) ifTrue:[ |
|
620 |
space := (height - sumOfHeights) // (numChilds + 1). |
|
621 |
ypos := space. |
|
622 |
(space == 0) ifTrue:[ |
|
623 |
ypos := (height - sumOfHeights) // 2 |
|
624 |
] |
|
625 |
] ifFalse: [ |
|
133 | 626 |
((l == #top) |
627 |
or:[l == #topSpace |
|
628 |
or:[l == #topFit |
|
629 |
or:[l == #topSpaceFit]]]) ifTrue:[ |
|
77 | 630 |
space := space min:(height - sumOfHeights) // (numChilds + 1). |
133 | 631 |
(vLayout == #fixTop or:[vLayout == #fixTopSpace]) ifTrue:[ |
632 |
space := space max:verticalSpace. |
|
633 |
] ifFalse:[ |
|
634 |
space := space max:0. |
|
635 |
]. |
|
636 |
(l == #topSpace |
|
637 |
or:[l == #topSpaceFit]) ifTrue:[ |
|
77 | 638 |
ypos := space. |
639 |
] ifFalse:[ |
|
640 |
ypos := 0 |
|
641 |
] |
|
63 | 642 |
] ifFalse:[ |
77 | 643 |
"center" |
644 |
ypos := (height - (sumOfHeights |
|
645 |
+ ((numChilds - 1) * space))) // 2. |
|
646 |
ypos < 0 ifTrue:[ |
|
647 |
space := (height - sumOfHeights) // (numChilds + 1). |
|
648 |
ypos := (height - (sumOfHeights |
|
649 |
+ ((numChilds - 1) * space))) // 2. |
|
650 |
] |
|
63 | 651 |
] |
77 | 652 |
] |
63 | 653 |
] |
654 |
] |
|
77 | 655 |
]. |
63 | 656 |
]. |
657 |
]. |
|
658 |
||
127 | 659 |
hL := hLayout. |
660 |
resizeToMax := false. |
|
661 |
(hLayout endsWith:'Max') ifTrue:[ |
|
662 |
resizeToMax := true. |
|
663 |
maxWidth := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child widthIncludingBorder]. |
|
664 |
hL == #centerMax ifTrue:[hL := #center]. |
|
665 |
hL == #rightMax ifTrue:[hL := #right]. |
|
666 |
hL == #rightSpaceMax ifTrue:[hL := #rightSpace]. |
|
667 |
hL == #leftMax ifTrue:[hL := #left]. |
|
668 |
hL == #leftSpaceMax ifTrue:[hL := #leftSpace]. |
|
669 |
]. |
|
670 |
||
63 | 671 |
" |
672 |
now set positions |
|
673 |
" |
|
133 | 674 |
subViews keysAndValuesDo:[:index :child | |
125 | 675 |
|xpos bwChild wChild| |
676 |
||
677 |
wChild := child widthIncludingBorder. |
|
678 |
bwChild := child borderWidth. |
|
63 | 679 |
|
127 | 680 |
resizeToMax ifTrue:[ |
681 |
child width:(wChild := maxWidth - (bwChild * 2)). |
|
682 |
]. |
|
683 |
||
684 |
hL == #left ifTrue:[ |
|
63 | 685 |
xpos := 0 |
686 |
] ifFalse:[ |
|
127 | 687 |
hL == #leftSpace ifTrue:[ |
63 | 688 |
xpos := horizontalSpace |
689 |
] ifFalse:[ |
|
127 | 690 |
hL == #right ifTrue:[ |
125 | 691 |
xpos := width - wChild |
63 | 692 |
] ifFalse:[ |
127 | 693 |
hL == #rightSpace ifTrue:[ |
125 | 694 |
xpos := width - horizontalSpace - wChild. |
63 | 695 |
] ifFalse:[ |
127 | 696 |
hL == #fitSpace ifTrue:[ |
63 | 697 |
xpos := horizontalSpace. |
125 | 698 |
child width:(width - (horizontalSpace + bwChild * 2)) |
63 | 699 |
] ifFalse:[ |
127 | 700 |
hL == #fit ifTrue:[ |
77 | 701 |
xpos := 0. |
125 | 702 |
child width:(width - (bwChild * 2)) |
77 | 703 |
] ifFalse:[ |
127 | 704 |
"centered" |
705 |
xpos := (width - wChild) // 2. |
|
77 | 706 |
] |
63 | 707 |
] |
708 |
] |
|
709 |
] |
|
710 |
] |
|
711 |
]. |
|
712 |
(xpos < 0) ifTrue:[ xpos := 0 ]. |
|
713 |
||
133 | 714 |
(vLayout == #fit |
715 |
or:[vLayout == #fitSpace]) ifTrue:[ |
|
59 | 716 |
child origin:(xpos @ ypos rounded) |
155 | 717 |
corner:(xpos + (child width - 1)) |
718 |
@ (ypos + hEach - bwChild - 1) rounded. |
|
77 | 719 |
ypos := ypos + hEach + space |
63 | 720 |
] ifFalse:[ |
721 |
child origin:(xpos@ypos). |
|
722 |
ypos := ypos + (child heightIncludingBorder) + space |
|
133 | 723 |
]. |
724 |
||
725 |
index == numChilds ifTrue:[ |
|
726 |
|y| |
|
727 |
||
728 |
vLayout == #topFit ifTrue:[ |
|
155 | 729 |
y := height - margin - 1. |
133 | 730 |
]. |
731 |
vLayout == #topSpaceFit ifTrue:[ |
|
155 | 732 |
y := height - margin - 1 - space |
133 | 733 |
]. |
734 |
y notNil ifTrue:[ |
|
155 | 735 |
subViews last corner:(xpos + child width - 1) @ y |
133 | 736 |
] |
59 | 737 |
] |
0 | 738 |
] |
155 | 739 |
|
740 |
"Modified: 4.9.1995 / 18:43:29 / claus" |
|
0 | 741 |
! ! |
125 | 742 |
|
743 |
!VerticalPanelView methodsFor:'accessing'! |
|
744 |
||
745 |
horizontalLayout |
|
746 |
"return the horizontal layout as symbol. |
|
747 |
the returned value is one of |
|
133 | 748 |
#left place element at the left |
749 |
#leftSpace place element at the left, offset by horizontalSpace |
|
750 |
#center place elements horizontally centered; ignore horizontalSpace |
|
751 |
#right place it at the right |
|
752 |
#rightSpace place it at the right, offset by horizontalSpace |
|
753 |
#fit resize elements horizontally to fit this panel; ignore horizontalSpace |
|
754 |
#fitSpace like #fit, but add spacing; ignore horizontalSpace |
|
755 |
||
756 |
#leftMax like #left, but resize elements to max of them |
|
757 |
#leftSpaceMax like #leftSpace, but resize elements |
|
758 |
#centerMax like #center, but resize elements |
|
759 |
#rightMax like #right, but resize elements to max of them |
|
760 |
#rightSpaceMax like #rightSpace, but resize elements |
|
125 | 761 |
the default is #centered |
762 |
" |
|
763 |
||
764 |
^ hLayout |
|
765 |
! |
|
766 |
||
767 |
horizontalLayout:aSymbol |
|
768 |
"change the horizontal layout as symbol. |
|
769 |
The argument, aSymbol must be one of: |
|
133 | 770 |
#left place element at the left |
771 |
#leftSpace place element at the left, offset by horizontalSpace |
|
772 |
#center place elements horizontally centered; ignore horizontalSpace |
|
773 |
#right place it at the right |
|
774 |
#rightSpace place it at the right, offset by horizontalSpace |
|
775 |
#fit resize elements horizontally to fit this panel; ignore horizontalSpace |
|
776 |
#fitSpace like #fit, but add spacing; ignore horizontalSpace |
|
777 |
||
778 |
#leftMax like #left, but resize elements to max of them |
|
779 |
#leftSpaceMax like #leftSpace, but resize elements |
|
780 |
#centerMax like #center, but resize elements |
|
781 |
#rightMax like #right, but resize elements to max of them |
|
782 |
#rightSpaceMax like #rightSpace, but resize elements |
|
125 | 783 |
the default (if never changed) is #centered |
784 |
" |
|
785 |
||
786 |
(hLayout ~~ aSymbol) ifTrue:[ |
|
787 |
hLayout := aSymbol. |
|
788 |
self layoutChanged |
|
789 |
] |
|
790 |
! |
|
791 |
||
792 |
verticalLayout |
|
793 |
"return the vertical layout as a symbol. |
|
794 |
the returned value is one of |
|
133 | 795 |
#top arrange elements at the top |
796 |
#topSpace arrange elements at the top, start with spacing |
|
797 |
#bottom arrange elements at the bottom |
|
798 |
#bottomSpace arrange elements at the bottom, start with spacing |
|
799 |
#center arrange elements in the center; ignore verticalSpace |
|
800 |
#spread spread elements evenly; ignore verticalSpace |
|
801 |
#spreadSpace spread elements evenly with spacing at ends; ignore verticalSpace |
|
802 |
#fit like #spread, but resize elements for tight packing; ignore verticalSpace |
|
803 |
#fitSpace like #fit, with spacing; ignore verticalSpace |
|
804 |
#topFit like #top, but extend the last element to the bottom |
|
805 |
#topSpaceFit like #topSpace, but extend the last element to the bottom |
|
125 | 806 |
the default is #centered |
807 |
" |
|
808 |
||
809 |
^ vLayout |
|
810 |
! |
|
811 |
||
812 |
verticalLayout:aSymbol |
|
813 |
"change the vertical layout as a symbol. |
|
814 |
The argument, aSymbol must be one of: |
|
133 | 815 |
#top arrange elements at the top |
816 |
#topSpace arrange elements at the top, start with spacing |
|
817 |
#bottom arrange elements at the bottom |
|
818 |
#bottomSpace arrange elements at the bottom, start with spacing |
|
819 |
#center arrange elements in the center; ignore verticalSpace |
|
820 |
#spread spread elements evenly; ignore verticalSpace |
|
821 |
#spreadSpace spread elements evenly with spacing at ends; ignore verticalSpace |
|
822 |
#fit like #spread, but resize elements for tight packing; ignore verticalSpace |
|
823 |
#fitSpace like #fit, with spacing; ignore verticalSpace |
|
824 |
#topFit like #top, but extend the last element to the bottom |
|
825 |
#topSpaceFit like #topSpace, but extend the last element to the bottom |
|
125 | 826 |
the default (if never changed) is #centered |
827 |
" |
|
828 |
||
829 |
(vLayout ~~ aSymbol) ifTrue:[ |
|
830 |
vLayout := aSymbol. |
|
831 |
self layoutChanged |
|
832 |
] |
|
833 |
! |
|
834 |
||
155 | 835 |
layout:something |
836 |
"OBSOLETE compatibility interface. Will vanish. |
|
837 |
leftover for historic reasons - do not use any more. |
|
838 |
In the meantime, try to figure out what is meant ... a kludge" |
|
839 |
||
840 |
something isLayout ifTrue:[^ super layout:something]. |
|
125 | 841 |
|
130 | 842 |
self obsoleteMethodWarning:'use #verticalLayout:'. |
155 | 843 |
^ self verticalLayout:something |
844 |
||
845 |
"Modified: 31.8.1995 / 23:08:54 / claus" |
|
125 | 846 |
! |
847 |
||
848 |
layout |
|
849 |
"leftover for historic reasons - do not use any more" |
|
850 |
||
130 | 851 |
self obsoleteMethodWarning:'use #verticalLayout'. |
852 |
^ self verticalLayout |
|
125 | 853 |
! ! |
854 |
||
855 |
!VerticalPanelView methodsFor:'queries'! |
|
856 |
||
130 | 857 |
preferredExtent |
125 | 858 |
"return a good extent, one that makes subviews fit" |
859 |
||
860 |
|sumOfHeights maxWidth maxHeight| |
|
861 |
||
862 |
subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace]. |
|
863 |
||
864 |
"compute net height needed" |
|
865 |
||
866 |
sumOfHeights := 0. |
|
867 |
maxWidth := 0. |
|
868 |
maxHeight := 0. |
|
869 |
||
870 |
subViews do:[:child | |
|
127 | 871 |
|childsPreference| |
125 | 872 |
|
130 | 873 |
childsPreference := child preferredExtent. |
127 | 874 |
sumOfHeights := sumOfHeights + childsPreference y. |
875 |
maxHeight := maxHeight max:childsPreference y. |
|
876 |
maxWidth := maxWidth max:childsPreference x. |
|
125 | 877 |
|
878 |
"/ sumOfHeights := sumOfHeights + child heightIncludingBorder. |
|
879 |
"/ maxWidth := maxWidth max:(child widthIncludingBorder). |
|
880 |
"/ maxHeight := maxHeight max:(child heightIncludingBorder). |
|
881 |
]. |
|
882 |
borderWidth ~~ 0 ifTrue:[ |
|
127 | 883 |
sumOfHeights := sumOfHeights + (horizontalSpace * 2). |
884 |
maxWidth := maxWidth + (horizontalSpace * 2). |
|
125 | 885 |
]. |
886 |
(vLayout == #fit or:[vLayout == #fitSpace]) ifTrue:[ |
|
127 | 887 |
sumOfHeights := maxHeight * subViews size. |
888 |
borderWidth ~~ 0 ifTrue:[ |
|
889 |
sumOfHeights := sumOfHeights + (verticalSpace * 2). |
|
890 |
] |
|
125 | 891 |
] ifFalse:[ |
127 | 892 |
sumOfHeights := sumOfHeights + ((subViews size - 1) * verticalSpace). |
131 | 893 |
vLayout == #topSpace ifTrue:[ |
894 |
sumOfHeights := sumOfHeights + verticalSpace |
|
895 |
] ifFalse:[ |
|
896 |
((vLayout == #center) or:[vLayout == #spread]) ifTrue:[ |
|
897 |
sumOfHeights := sumOfHeights + (verticalSpace * 2) |
|
898 |
] |
|
899 |
]. |
|
125 | 900 |
]. |
901 |
||
902 |
((hLayout == #leftSpace) or:[hLayout == #rightSpace]) ifTrue:[ |
|
127 | 903 |
maxWidth := maxWidth + horizontalSpace |
125 | 904 |
] ifFalse:[ |
127 | 905 |
((hLayout == #fitSpace) or:[hLayout == #center]) ifTrue:[ |
906 |
maxWidth := maxWidth + (horizontalSpace * 2) |
|
907 |
] |
|
125 | 908 |
]. |
909 |
^ maxWidth @ sumOfHeights |
|
910 |
! ! |
|
911 |