3518
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libwidg' }"
|
|
13 |
|
|
14 |
PanelView subclass:#MultiColumnPanelView
|
|
15 |
instanceVariableNames:'columnWidths'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Layout'
|
|
19 |
!
|
|
20 |
|
|
21 |
!MultiColumnPanelView class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
a View which arranges its child-views in a vertical column.
|
|
40 |
All real work is done in PanelView - except the layout computation is
|
|
41 |
redefined here.
|
|
42 |
|
|
43 |
The layout is controlled by the instance variables:
|
|
44 |
horizontalLayout and verticalLayout
|
|
45 |
in addition to
|
|
46 |
horizontalSpace and verticalSpace.
|
|
47 |
|
|
48 |
The vertical layout can be any of:
|
|
49 |
|
|
50 |
#top arrange elements at the top
|
|
51 |
#topSpace arrange elements at the top, start with spacing
|
|
52 |
#bottom arrange elements at the bottom
|
|
53 |
#bottomSpace arrange elements at the bottom, start with spacing
|
|
54 |
#center arrange elements in the center; ignore verticalSpace
|
|
55 |
#spread spread elements evenly; ignore verticalSpace
|
|
56 |
#spreadSpace spread elements evenly with spacing at ends; ignore verticalSpace
|
|
57 |
#fit like #spread, but resize elements for tight packing; ignore verticalSpace
|
|
58 |
#fitSpace like #fit, with spacing; ignore verticalSpace
|
|
59 |
#topFit like #top, but resize the last element to fit
|
|
60 |
#topSpaceFit like #topSpace, but resize the last element to fit
|
|
61 |
#bottomFit like #bottom, but resize the first element to fit
|
|
62 |
#bottomSpaceFit like #bottomSpace, but resize the first element to fit
|
|
63 |
|
|
64 |
the horizontal layout can be:
|
|
65 |
|
|
66 |
#left place element at the left
|
|
67 |
#leftSpace place element at the left, offset by horizontalSpace
|
|
68 |
#center place elements horizontally centered; ignore horizontalSpace
|
|
69 |
#right place it at the right
|
|
70 |
#rightSpace place it at the right, offset by horizontalSpace
|
|
71 |
#fit resize elements horizontally to fit this panel; ignore horizontalSpace
|
|
72 |
#fitSpace like #fit, but add spacing; ignore horizontalSpace
|
|
73 |
|
|
74 |
#leftMax like #left, but resize elements to max of them
|
|
75 |
#leftSpaceMax like #leftSpace, but resize elements
|
|
76 |
#centerMax like #center, but resize elements
|
|
77 |
#rightMax like #right, but resize elements to max of them
|
|
78 |
#rightSpaceMax like #rightSpace, but resize elements
|
|
79 |
|
|
80 |
The defaults is #center for both directions.
|
|
81 |
|
|
82 |
The layout is changed by the messages #verticalLayout: and #horizontalLayout:.
|
|
83 |
For backward compatibility (to times, where only vLayout existed), the simple
|
|
84 |
#layout: does the same as #verticalLayout:. Do not use this old method.
|
|
85 |
|
|
86 |
The panel assumes, that the elements do not resize themselfes, after it
|
|
87 |
became visible. This is not true for all widgets (buttons or labels may
|
|
88 |
like to change). If you have changing elements, tell this to the panel
|
|
89 |
with 'aPanel elementsChangeSize:true'. In that case, the panel will react
|
|
90 |
to size changes, and reorganize things.
|
|
91 |
|
|
92 |
If none of these layout/space combinations is exactly what you need in
|
|
93 |
your application, create a subclass, and redefine the setChildPositions method.
|
|
94 |
|
|
95 |
CAVEAT: this class started with #top and no horizontal alignments;
|
|
96 |
as time went by, more layouts were added and the setup should be changed
|
|
97 |
to use different selectors for space, max-resize and alignment
|
|
98 |
(i.e. having more and more layout symbols makes things a bit confusing ...)
|
|
99 |
|
|
100 |
[see also:]
|
|
101 |
HorizontalPanelView
|
|
102 |
VariableVerticalPanel VariableHorizontalPanel
|
|
103 |
Label
|
|
104 |
|
|
105 |
[author:]
|
|
106 |
Claus Gittinger
|
|
107 |
"
|
|
108 |
!
|
|
109 |
|
|
110 |
examples
|
|
111 |
"
|
|
112 |
These examples demonstrate the effect of different layout
|
|
113 |
settings.
|
|
114 |
You should try more examples, combining spacing and different
|
|
115 |
verticalLayout:/horizontalLayout: combinations.
|
|
116 |
|
|
117 |
|
|
118 |
example: default layout (centered)
|
|
119 |
[exBegin]
|
|
120 |
|v p b1 b2 b3 l1 l2 l3|
|
|
121 |
|
|
122 |
v := StandardSystemView new.
|
|
123 |
v label:'center (default)'.
|
|
124 |
p := MultiColumnPanelView in:v.
|
|
125 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
126 |
p columnWidths:#(0.3 0.7).
|
|
127 |
l1 := Label label:'label1' in:p.
|
|
128 |
b1 := Button label:'button1' in:p.
|
|
129 |
l2 := Label label:'l2' in:p.
|
|
130 |
b2 := Button label:'b2' in:p.
|
|
131 |
l3 := Label label:'lab3' in:p.
|
|
132 |
b3 := Button label:'butt3' in:p.
|
|
133 |
v extent:100 @ 300.
|
|
134 |
v open
|
|
135 |
[exEnd]
|
|
136 |
"
|
|
137 |
! !
|
|
138 |
|
|
139 |
!MultiColumnPanelView methodsFor:'accessing'!
|
|
140 |
|
|
141 |
columnWidths:something
|
|
142 |
something ~= columnWidths ifTrue:[
|
|
143 |
columnWidths := something.
|
|
144 |
self layoutChanged
|
|
145 |
].
|
|
146 |
!
|
|
147 |
|
|
148 |
horizontalLayout
|
|
149 |
"return the horizontal layout as symbol.
|
|
150 |
the returned value is one of
|
|
151 |
#left place element at the left
|
|
152 |
#leftSpace place element at the left, offset by horizontalSpace
|
|
153 |
#center place elements horizontally centered; ignore horizontalSpace
|
|
154 |
#right place it at the right
|
|
155 |
#rightSpace place it at the right, offset by horizontalSpace
|
|
156 |
#fit resize elements horizontally to fit this panel; ignore horizontalSpace
|
|
157 |
#fitSpace like #fit, but add spacing; ignore horizontalSpace
|
|
158 |
|
|
159 |
#leftMax like #left, but resize elements to max of them
|
|
160 |
#leftSpaceMax like #leftSpace, but resize elements
|
|
161 |
#centerMax like #center, but resize elements
|
|
162 |
#rightMax like #right, but resize elements to max of them
|
|
163 |
#rightSpaceMax like #rightSpace, but resize elements
|
|
164 |
the default is #centered
|
|
165 |
"
|
|
166 |
|
|
167 |
^ hLayout
|
|
168 |
!
|
|
169 |
|
|
170 |
horizontalLayout:aSymbol
|
|
171 |
"change the horizontal layout as symbol.
|
|
172 |
The argument, aSymbol must be one of:
|
|
173 |
#left place element at the left
|
|
174 |
#leftSpace place element at the left, offset by horizontalSpace
|
|
175 |
#center place elements horizontally centered; ignore horizontalSpace
|
|
176 |
#right place it at the right
|
|
177 |
#rightSpace place it at the right, offset by horizontalSpace
|
|
178 |
#fit resize elements horizontally to fit this panel; ignore horizontalSpace
|
|
179 |
#fitSpace like #fit, but add spacing; ignore horizontalSpace
|
|
180 |
|
|
181 |
#leftMax like #left, but resize elements to max of them
|
|
182 |
#leftSpaceMax like #leftSpace, but resize elements
|
|
183 |
#centerMax like #center, but resize elements
|
|
184 |
#rightMax like #right, but resize elements to max of them
|
|
185 |
#rightSpaceMax like #rightSpace, but resize elements
|
|
186 |
the default (if never changed) is #centered
|
|
187 |
"
|
|
188 |
|
|
189 |
(hLayout ~~ aSymbol) ifTrue:[
|
|
190 |
hLayout := aSymbol.
|
|
191 |
self layoutChanged
|
|
192 |
]
|
|
193 |
!
|
|
194 |
|
|
195 |
layout:something
|
|
196 |
"OBSOLETE compatibility interface. Will vanish.
|
|
197 |
leftover for historic reasons - do not use any more.
|
|
198 |
In the meantime, try to figure out what is meant ... a kludge"
|
|
199 |
|
|
200 |
<resource:#obsolete>
|
|
201 |
|
|
202 |
something isLayout ifTrue:[^ super layout:something].
|
|
203 |
|
|
204 |
self obsoleteMethodWarning:'use #verticalLayout:'.
|
|
205 |
^ self verticalLayout:something
|
|
206 |
|
|
207 |
"Modified: 31.8.1995 / 23:08:54 / claus"
|
|
208 |
!
|
|
209 |
|
|
210 |
verticalLayout
|
|
211 |
"return the vertical layout as a symbol.
|
|
212 |
the returned value is one of
|
|
213 |
#top arrange elements at the top
|
|
214 |
#topSpace arrange elements at the top, start with spacing
|
|
215 |
#bottom arrange elements at the bottom
|
|
216 |
#bottomSpace arrange elements at the bottom, start with spacing
|
|
217 |
#center arrange elements in the center; ignore verticalSpace
|
|
218 |
#spread spread elements evenly; ignore verticalSpace
|
|
219 |
#spreadSpace spread elements evenly with spacing at ends; ignore verticalSpace
|
|
220 |
#fit like #spread, but resize elements for tight packing; ignore verticalSpace
|
|
221 |
#fitSpace like #fit, with spacing; ignore verticalSpace
|
|
222 |
#topFit like #top, but resize the last element to fit
|
|
223 |
#topSpaceFit like #topSpace, but resize the last element to fit
|
|
224 |
#bottomFit like #bottom, but resize the first element to fit
|
|
225 |
#bottomSpaceFit like #bottomSpace, but extend the first element to fit
|
|
226 |
the default is #centered
|
|
227 |
"
|
|
228 |
|
|
229 |
^ vLayout
|
|
230 |
|
|
231 |
"Modified: 17.8.1997 / 15:20:13 / cg"
|
|
232 |
!
|
|
233 |
|
|
234 |
verticalLayout:aSymbol
|
|
235 |
"change the vertical layout as a symbol.
|
|
236 |
The argument, aSymbol must be one of:
|
|
237 |
#top arrange elements at the top
|
|
238 |
#topSpace arrange elements at the top, start with spacing
|
|
239 |
#bottom arrange elements at the bottom
|
|
240 |
#bottomSpace arrange elements at the bottom, start with spacing
|
|
241 |
#center arrange elements in the center; ignore verticalSpace
|
|
242 |
#spread spread elements evenly; ignore verticalSpace
|
|
243 |
#spreadSpace spread elements evenly with spacing at ends; ignore verticalSpace
|
|
244 |
#fit like #spread, but resize elements for tight packing; ignore verticalSpace
|
|
245 |
#fitSpace like #fit, with spacing; ignore verticalSpace
|
|
246 |
#topFit like #top, but resize the last element to fit
|
|
247 |
#topSpaceFit like #topSpace, but resize the last element to fit
|
|
248 |
#bottomFit like #bottom, but resize the first element to fit
|
|
249 |
#bottomSpaceFit like #bottomSpace, but extend the first element to fit
|
|
250 |
the default (if never changed) is #centered
|
|
251 |
"
|
|
252 |
|
|
253 |
(vLayout ~~ aSymbol) ifTrue:[
|
|
254 |
vLayout := aSymbol.
|
|
255 |
self layoutChanged
|
|
256 |
]
|
|
257 |
|
|
258 |
"Modified: 17.8.1997 / 15:19:58 / cg"
|
|
259 |
! !
|
|
260 |
|
|
261 |
!MultiColumnPanelView methodsFor:'initialization'!
|
|
262 |
|
|
263 |
initialize
|
|
264 |
super initialize.
|
|
265 |
|
|
266 |
hLayout := #fit.
|
|
267 |
vLayout := #top.
|
|
268 |
columnWidths := #(0.5 0.5).
|
|
269 |
! !
|
|
270 |
|
|
271 |
!MultiColumnPanelView methodsFor:'layout'!
|
|
272 |
|
|
273 |
setChildPositions
|
|
274 |
"(re)compute position of every child"
|
|
275 |
|
|
276 |
|xpos ypos space sumOfHeights numChilds l hEach hInside hL vL
|
|
277 |
maxWidth maxHeight resizeToMaxV resizeToMaxH m2 subViews restHeight
|
|
278 |
rowsPerCol maxWidthPerCol col numCols cX cY|
|
|
279 |
|
|
280 |
subViews := self subViewsToConsider.
|
|
281 |
subViews size == 0 ifTrue:[^ self].
|
|
282 |
|
|
283 |
"/ self extentChangedFlag ifTrue:[
|
|
284 |
"/ ext := self computeExtent.
|
|
285 |
"/ width := ext x.
|
|
286 |
"/ height := ext y.
|
|
287 |
"/ ].
|
|
288 |
|
|
289 |
space := verticalSpace.
|
|
290 |
numChilds := subViews size.
|
|
291 |
numCols := columnWidths size max:1.
|
|
292 |
|
|
293 |
m2 := margin * 2.
|
|
294 |
hInside := height - m2 + (borderWidth*2) - subViews last borderWidth.
|
|
295 |
|
|
296 |
hL := hLayout.
|
|
297 |
vL := vLayout.
|
|
298 |
|
|
299 |
rowsPerCol := Array new:numCols withAll:0.
|
|
300 |
maxWidthPerCol := Array new:numCols withAll:0.
|
|
301 |
|
|
302 |
maxHeight := 0.
|
|
303 |
col := 1.
|
|
304 |
subViews do:[:child |
|
|
305 |
|childsW childsH|
|
|
306 |
|
|
307 |
childsW := child widthIncludingBorder.
|
|
308 |
childsH := child heightIncludingBorder.
|
|
309 |
maxHeight := maxHeight max:childsH.
|
|
310 |
maxWidthPerCol at:col put:((maxWidthPerCol at:col) max:childsW).
|
|
311 |
rowsPerCol at:col put:(rowsPerCol at:col)+1.
|
|
312 |
col := col + 1.
|
|
313 |
col > numCols ifTrue:[ col := 1 ].
|
|
314 |
].
|
|
315 |
"/ new
|
|
316 |
xpos := 0.
|
|
317 |
ypos := 0.
|
|
318 |
col := 1.
|
|
319 |
subViews do:[:child |
|
|
320 |
col == numCols ifTrue:[
|
|
321 |
cX := width.
|
|
322 |
] ifFalse:[
|
|
323 |
cX := xpos + (width // numCols).
|
|
324 |
].
|
|
325 |
cY := ypos + maxHeight.
|
|
326 |
|
|
327 |
child origin:(xpos@ypos)"corner:(cX @ cY)".
|
|
328 |
hLayout == #fit ifTrue:[
|
|
329 |
child width:(cX - xpos + 1).
|
|
330 |
].
|
|
331 |
col := col + 1.
|
|
332 |
col > numCols ifTrue:[
|
|
333 |
col := 1.
|
|
334 |
xpos := 0.
|
|
335 |
ypos := cY + verticalSpace.
|
|
336 |
] ifFalse:[
|
|
337 |
xpos := cX + horizontalSpace.
|
|
338 |
].
|
|
339 |
].
|
|
340 |
^ self.
|
|
341 |
|
|
342 |
"/ old
|
|
343 |
|
|
344 |
resizeToMaxV := false.
|
|
345 |
(vL endsWith:'Max') ifTrue:[
|
|
346 |
resizeToMaxV := true.
|
|
347 |
hEach := maxHeight := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child heightIncludingBorder].
|
|
348 |
vL := (vL copyWithoutLast:3) asSymbol.
|
|
349 |
].
|
|
350 |
|
|
351 |
numChilds == 1 ifTrue:[
|
|
352 |
(vL == #topFit or:[vL == #bottomFit]) ifTrue:[
|
|
353 |
vL := #fit
|
|
354 |
].
|
|
355 |
(vL == #topSpaceFit or:[vL == #bottomSpaceFit]) ifTrue:[
|
|
356 |
vL := #fitSpace
|
|
357 |
].
|
|
358 |
].
|
|
359 |
|
|
360 |
vL == #fitSpace ifTrue:[
|
|
361 |
"
|
|
362 |
adjust childs extents and set origins.
|
|
363 |
Be careful to avoid accumulation of rounding errors
|
|
364 |
"
|
|
365 |
hEach := (hInside - ((numChilds + 1) * space)) / numChilds.
|
|
366 |
ypos := space + margin - borderWidth.
|
|
367 |
] ifFalse:[
|
|
368 |
vL == #fit ifTrue:[
|
|
369 |
"
|
|
370 |
adjust childs extents and set origins.
|
|
371 |
Be careful to avoid accumulation of rounding errors
|
|
372 |
"
|
|
373 |
hEach := (hInside - ((numChilds - 1) * space)) / numChilds.
|
|
374 |
ypos := margin - borderWidth.
|
|
375 |
] ifFalse:[
|
|
376 |
l := vL.
|
|
377 |
|
|
378 |
"
|
|
379 |
compute net height needed
|
|
380 |
"
|
|
381 |
resizeToMaxV ifTrue:[
|
|
382 |
sumOfHeights := subViews inject:0 into:[:sumSoFar :child | sumSoFar + maxHeight + (child borderWidth*2)].
|
|
383 |
] ifFalse:[
|
|
384 |
sumOfHeights := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child heightIncludingBorder].
|
|
385 |
|
|
386 |
"/ adjust - do not include height of last(first) element if doing a fit
|
|
387 |
(vL == #topFit or:[vL == #topSpaceFit]) ifTrue:[
|
|
388 |
sumOfHeights := sumOfHeights - subViews last heightIncludingBorder.
|
|
389 |
] ifFalse:[
|
|
390 |
(vL == #bottomFit or:[vL == #bottomSpaceFit]) ifTrue:[
|
|
391 |
sumOfHeights := sumOfHeights - subViews first heightIncludingBorder.
|
|
392 |
]
|
|
393 |
].
|
|
394 |
].
|
|
395 |
|
|
396 |
restHeight := height - sumOfHeights - ((numChilds-1)*space).
|
|
397 |
|
|
398 |
((l == #center) and:[numChilds == 1]) ifTrue:[l := #spread].
|
|
399 |
(l == #spread and:[numChilds == 1]) ifTrue:[l := #spreadSpace].
|
|
400 |
|
|
401 |
"
|
|
402 |
compute position of topmost subview and space between them;
|
|
403 |
if they do hardly fit, leave no space between them
|
|
404 |
"
|
|
405 |
((sumOfHeights >= (height - m2))
|
|
406 |
and:[l ~~ #fixTopSpace and:[l ~~ #fixTop]]) ifTrue:[
|
|
407 |
"
|
|
408 |
if we have not enough space for all the elements,
|
|
409 |
fill them tight, and show what can be shown (at least)
|
|
410 |
"
|
|
411 |
ypos := margin.
|
|
412 |
space := 0
|
|
413 |
] ifFalse:[
|
|
414 |
l == #fixTopSpace ifTrue:[
|
|
415 |
l := #topSpace
|
|
416 |
] ifFalse:[
|
|
417 |
l == #fixTop ifTrue:[
|
|
418 |
l := #top
|
|
419 |
]
|
|
420 |
].
|
|
421 |
((l == #bottom) or:[l == #bottomSpace
|
|
422 |
or:[l == #bottomFit or:[l == #bottomSpaceFit]]]) ifTrue:[
|
|
423 |
ypos := restHeight - (space * (numChilds - 1)).
|
|
424 |
"/
|
|
425 |
"/ borderWidth == 0 ifTrue:[
|
|
426 |
"/ ypos := ypos + space
|
|
427 |
"/ ].
|
|
428 |
"/
|
|
429 |
(l == #bottomSpace
|
|
430 |
or:[l == #bottomSpaceFit]) ifTrue:[
|
|
431 |
ypos >= space ifTrue:[
|
|
432 |
ypos := ypos - space
|
|
433 |
]
|
|
434 |
].
|
|
435 |
ypos := ypos - margin.
|
|
436 |
|
|
437 |
ypos < 0 ifTrue:[
|
|
438 |
space := space min:(restHeight // (numChilds + 1)).
|
|
439 |
ypos := restHeight - (space * numChilds).
|
|
440 |
]
|
|
441 |
] ifFalse: [
|
|
442 |
(l == #spread) ifTrue:[
|
|
443 |
space := (restHeight - m2) // (numChilds - 1).
|
|
444 |
ypos := margin.
|
|
445 |
(space == 0) ifTrue:[
|
|
446 |
ypos := restHeight // 2
|
|
447 |
]
|
|
448 |
] ifFalse: [
|
|
449 |
(l == #spreadSpace) ifTrue:[
|
|
450 |
space := (restHeight - m2) // (numChilds + 1).
|
|
451 |
ypos := space + margin.
|
|
452 |
(space == 0) ifTrue:[
|
|
453 |
ypos := restHeight // 2
|
|
454 |
]
|
|
455 |
] ifFalse: [
|
|
456 |
((l == #top) or:[l == #topSpace
|
|
457 |
or:[l == #topFit or:[l == #topSpaceFit]]]) ifTrue:[
|
|
458 |
space := space min:(restHeight - m2) // (numChilds + 1).
|
|
459 |
(vL == #fixTop or:[vL == #fixTopSpace]) ifTrue:[
|
|
460 |
space := space max:verticalSpace.
|
|
461 |
] ifFalse:[
|
|
462 |
space := space max:0.
|
|
463 |
].
|
|
464 |
(l == #topSpace or:[l == #topSpaceFit]) ifTrue:[
|
|
465 |
ypos := space + margin.
|
|
466 |
] ifFalse:[
|
|
467 |
"/
|
|
468 |
"/ if the very first view has a 0-level AND
|
|
469 |
"/ my level is non-zero, begin with margin
|
|
470 |
"/
|
|
471 |
true "(margin ~~ 0 and:[subViews first level == 0])" ifTrue:[
|
|
472 |
ypos := margin
|
|
473 |
] ifFalse:[
|
|
474 |
ypos := 0
|
|
475 |
]
|
|
476 |
]
|
|
477 |
] ifFalse:[
|
|
478 |
"center"
|
|
479 |
ypos := (restHeight - ((numChilds - 1) * space)) // 2.
|
|
480 |
ypos < 0 ifTrue:[
|
|
481 |
space := restHeight // (numChilds + 1).
|
|
482 |
ypos := (restHeight - ((numChilds - 1) * space)) // 2.
|
|
483 |
]
|
|
484 |
]
|
|
485 |
]
|
|
486 |
]
|
|
487 |
]
|
|
488 |
].
|
|
489 |
].
|
|
490 |
].
|
|
491 |
|
|
492 |
resizeToMaxH := false.
|
|
493 |
(hL endsWith:'Max') ifTrue:[
|
|
494 |
resizeToMaxH := true.
|
|
495 |
maxWidth := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child widthIncludingBorder].
|
|
496 |
hL := (hL copyWithoutLast:3) asSymbol.
|
|
497 |
].
|
|
498 |
|
|
499 |
"
|
|
500 |
now set positions
|
|
501 |
"
|
|
502 |
subViews keysAndValuesDo:[:index :child |
|
|
503 |
|xpos advance bwChild wChild newWChild x2|
|
|
504 |
|
|
505 |
wChild := child widthIncludingBorder.
|
|
506 |
bwChild := child borderWidth.
|
|
507 |
|
|
508 |
elementsChangeSize ifTrue:[
|
|
509 |
"to avoid a recursion when we change the elements size"
|
|
510 |
child removeDependent:self.
|
|
511 |
].
|
|
512 |
resizeToMaxH ifTrue:[
|
|
513 |
child width:(wChild := maxWidth - (bwChild * 2)).
|
|
514 |
].
|
|
515 |
|
|
516 |
hL == #left ifTrue:[
|
|
517 |
xpos := 0 - borderWidth + margin.
|
|
518 |
] ifFalse:[
|
|
519 |
hL == #leftSpace ifTrue:[
|
|
520 |
xpos := horizontalSpace + margin
|
|
521 |
] ifFalse:[
|
|
522 |
hL == #right ifTrue:[
|
|
523 |
xpos := width - wChild - margin
|
|
524 |
] ifFalse:[
|
|
525 |
hL == #rightSpace ifTrue:[
|
|
526 |
xpos := width - horizontalSpace - wChild - margin.
|
|
527 |
] ifFalse:[
|
|
528 |
hL == #fitSpace ifTrue:[
|
|
529 |
xpos := horizontalSpace + margin.
|
|
530 |
newWChild := width - m2 - ((horizontalSpace + bwChild) * 2)
|
|
531 |
] ifFalse:[
|
|
532 |
hL == #fit ifTrue:[
|
|
533 |
newWChild := width "- (bwChild * 2)".
|
|
534 |
borderWidth == 0 ifTrue:[
|
|
535 |
newWChild := newWChild - (bwChild * 2)
|
|
536 |
].
|
|
537 |
true "child level == 0" ifTrue:[
|
|
538 |
xpos := margin - borderWidth.
|
|
539 |
newWChild := newWChild - m2
|
|
540 |
] ifFalse:[
|
|
541 |
xpos := 0 - borderWidth.
|
|
542 |
].
|
|
543 |
] ifFalse:[
|
|
544 |
"centered"
|
|
545 |
xpos := margin + ((width - m2 - wChild) // 2).
|
|
546 |
]
|
|
547 |
]
|
|
548 |
]
|
|
549 |
]
|
|
550 |
]
|
|
551 |
].
|
|
552 |
newWChild notNil ifTrue:[
|
|
553 |
child width:newWChild
|
|
554 |
].
|
|
555 |
|
|
556 |
"/ (xpos < 0) ifTrue:[ xpos := 0 ].
|
|
557 |
|
|
558 |
x2 := xpos + child width - 1.
|
|
559 |
|
|
560 |
(vL == #fit
|
|
561 |
or:[vL == #fitSpace
|
|
562 |
or:[resizeToMaxV]]) ifTrue:[
|
|
563 |
child origin:(xpos @ (ypos rounded))
|
|
564 |
corner:(x2 @ (ypos + hEach - bwChild - 1) rounded).
|
|
565 |
advance := hEach
|
|
566 |
] ifFalse:[
|
|
567 |
child origin:(xpos@ypos).
|
|
568 |
advance := child heightIncludingBorder
|
|
569 |
].
|
|
570 |
|
|
571 |
index == numChilds ifTrue:[
|
|
572 |
|y|
|
|
573 |
|
|
574 |
(vL == #topFit or:[vL == #topSpaceFit]) ifTrue:[
|
|
575 |
y := height - margin - 1.
|
|
576 |
vL == #topSpaceFit ifTrue:[
|
|
577 |
y := y - space
|
|
578 |
].
|
|
579 |
child corner:x2 @ y
|
|
580 |
].
|
|
581 |
].
|
|
582 |
index == 1 ifTrue:[
|
|
583 |
(vL == #bottomFit or:[vL == #bottomSpaceFit]) ifTrue:[
|
|
584 |
ypos := margin + 0 + (child borderWidth * 2) - borderWidth.
|
|
585 |
vL == #bottomSpaceFit ifTrue:[
|
|
586 |
ypos := ypos + space
|
|
587 |
].
|
|
588 |
advance := restHeight.
|
|
589 |
child origin:((child origin x) @ ypos)
|
|
590 |
corner:((child corner x) @ (ypos+advance))
|
|
591 |
].
|
|
592 |
].
|
|
593 |
|
|
594 |
ypos := ypos + advance + space.
|
|
595 |
elementsChangeSize ifTrue:[
|
|
596 |
"reinstall dependency that we removed above"
|
|
597 |
child addDependent:self.
|
|
598 |
].
|
|
599 |
]
|
|
600 |
|
|
601 |
"Modified: / 04-09-1995 / 18:43:29 / claus"
|
|
602 |
"Modified: / 10-10-2007 / 13:47:56 / cg"
|
|
603 |
! !
|
|
604 |
|
|
605 |
!MultiColumnPanelView methodsFor:'queries'!
|
|
606 |
|
|
607 |
preferredExtent
|
|
608 |
"return a good extent, one that makes subviews fit"
|
|
609 |
|
|
610 |
|maxHeight maxWidth maxWidthPerCol w m2 subViews col numCols rowsPerCol|
|
|
611 |
|
|
612 |
"/ If I have an explicit preferredExtent ..
|
|
613 |
|
|
614 |
preferredExtent notNil ifTrue:[
|
|
615 |
^ preferredExtent
|
|
616 |
].
|
|
617 |
|
|
618 |
subViews := self subViewsToConsider.
|
|
619 |
(subViews size == 0) ifTrue:[
|
|
620 |
^ super preferredExtent.
|
|
621 |
].
|
|
622 |
|
|
623 |
"compute net height needed"
|
|
624 |
numCols := columnWidths size.
|
|
625 |
rowsPerCol := Array new:numCols withAll:0.
|
|
626 |
maxWidthPerCol := Array new:numCols withAll:0.
|
|
627 |
|
|
628 |
maxHeight := 0.
|
|
629 |
col := 1.
|
|
630 |
subViews do:[:child |
|
|
631 |
|childsPreference|
|
|
632 |
|
|
633 |
childsPreference := child preferredExtent.
|
|
634 |
maxHeight := maxHeight max:childsPreference y.
|
|
635 |
maxWidthPerCol at:col put:((maxWidthPerCol at:col) max:childsPreference y).
|
|
636 |
rowsPerCol at:col put:(rowsPerCol at:col)+1.
|
|
637 |
col := col + 1.
|
|
638 |
col > numCols ifTrue:[ col := 1 ].
|
|
639 |
].
|
|
640 |
|
|
641 |
borderWidth ~~ 0 ifTrue:[
|
|
642 |
maxWidth := maxWidth + (horizontalSpace * 2).
|
|
643 |
].
|
|
644 |
|
|
645 |
"/ sumOfHeights := sumOfHeights + ((subViews size - 1) * verticalSpace).
|
|
646 |
"/ ((vLayout == #topSpace) or:[vLayout == #bottomSpace]) ifTrue:[
|
|
647 |
"/ sumOfHeights := sumOfHeights + verticalSpace
|
|
648 |
"/ ] ifFalse:[
|
|
649 |
"/ ((vLayout == #center) or:[vLayout == #spread]) ifTrue:[
|
|
650 |
"/ sumOfHeights := sumOfHeights + (verticalSpace * 2)
|
|
651 |
"/ ]
|
|
652 |
"/ ].
|
|
653 |
|
|
654 |
"/ ((hLayout == #leftSpace) or:[hLayout == #rightSpace]) ifTrue:[
|
|
655 |
"/ maxWidth := maxWidth + horizontalSpace
|
|
656 |
"/ ] ifFalse:[
|
|
657 |
"/ ((hLayout == #fitSpace) or:[hLayout == #center]) ifTrue:[
|
|
658 |
"/ maxWidth := maxWidth + (horizontalSpace * 2)
|
|
659 |
"/ ]
|
|
660 |
"/ ].
|
|
661 |
m2 := margin * 2.
|
|
662 |
"/ ^ (maxWidth + m2) @ (sumOfHeights + m2)
|
|
663 |
|
|
664 |
w := maxWidthPerCol inject:0 into:[:sumSoFar :thisWidth | sumSoFar + thisWidth].
|
|
665 |
|
|
666 |
^ (w+m2) @ (rowsPerCol max * maxHeight) + m2
|
|
667 |
|
|
668 |
"Modified: / 17.1.1998 / 00:18:16 / cg"
|
|
669 |
! !
|
|
670 |
|
|
671 |
!MultiColumnPanelView class methodsFor:'documentation'!
|
|
672 |
|
|
673 |
version
|
|
674 |
^ '$Header: /cvs/stx/stx/libwidg/MultiColumnPanelView.st,v 1.1 2007-12-17 11:10:53 cg Exp $'
|
|
675 |
! !
|