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