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