author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 03:26:58 +0100 | |
changeset 197 | 00927189c882 |
parent 174 | d80a6cc3f9b2 |
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 |
||
13 |
PanelView subclass:#HorizontalPanelView |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Layout' |
|
18 |
! |
|
19 |
||
38 | 20 |
!HorizontalPanelView 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 |
version |
|
174
d80a6cc3f9b2
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.17 1995-11-11 16:20:33 cg Exp $' |
38 | 38 |
! |
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
a View which arranges its child-views in a horizontal row. |
|
43 |
All real work is done in PanelView - only the layout computation is |
|
44 |
redefined here. |
|
45 |
||
77 | 46 |
The layout is controlled the instance variables: |
47 |
horizontalLayout and verticalLayout |
|
127 | 48 |
in addition to |
49 |
horizontalSpace and verticalSpace. |
|
77 | 50 |
|
133 | 51 |
HorizontalSpace and verticalSpace control the spacing between elements; |
52 |
they default to some 1mm. |
|
53 |
||
62 | 54 |
The horizontal layout can be any of: |
55 |
||
56 |
#left arrange elements at the left |
|
57 |
#leftSpace arrange elements at the left, start with spacing |
|
118 | 58 |
#fixLeft same as #left, but do not reduce spacing in case of no fit |
59 |
#fixLeftSpace same as #leftSpace, but do not reduce spacing in case of no fit |
|
62 | 60 |
#right arrange elements at the right |
61 |
#rightSpace arrange elements at the right, start with spacing |
|
62 |
#center arrange elements in the center |
|
63 |
#spread spread elements evenly |
|
77 | 64 |
#spreadSpace spread elements evenly with spacing at the ends |
133 | 65 |
#fit like #spread, but resize elements for tight packing |
66 |
#fitSpace like #fit, with additional spacing at the far ends |
|
67 |
#leftFit like #left, but extend the last element to the right |
|
68 |
#leftSpaceFit like #leftSpace, but extend the last element to the right |
|
69 |
||
70 |
#leftMax like corresponding non-Max layouts, |
|
71 |
#leftSpaceMax but resize all components to width of widest components |
|
72 |
#rightMax |
|
73 |
#rightSpaceMax |
|
74 |
#centerMax |
|
75 |
#spreadMax |
|
76 |
#spreadSpaceMax |
|
62 | 77 |
|
78 |
the vertical layout can be: |
|
79 |
||
80 |
#top place element at the top |
|
81 |
#topSpace place element at the top, offset by verticalSpace |
|
82 |
#center place it horizontally centered |
|
83 |
#bottom place it at the bottom |
|
84 |
#bottomSpace place it at the bottom, offset by verticalSpace |
|
85 |
#fit resize elements vertically to fit this panel |
|
133 | 86 |
#fitSpace like #fit, but with spacing |
87 |
||
88 |
#topMax like #top, but resize all views vertically to max height |
|
89 |
#topSpaceMax like #topSpace, but resize all views vertically to max height |
|
90 |
#bottomMax like #bottom, but resize all views vertically to max height |
|
91 |
#bottomSpaceMax like #bottomSpace, but resize all views vertically to max height |
|
92 |
#centerMax like #center, but resize all views vertically to max height |
|
62 | 93 |
|
77 | 94 |
The defaults is #center for both directions. |
62 | 95 |
The layout is changed by the messages #verticalLayout: and #horizontalLayout:. |
96 |
For backward compatibility (to times, where only hLayout existed), the simple |
|
133 | 97 |
#layout: does the same as #horizontalLayout:. |
98 |
Do not use this old method; it will vanish and currently outpus a warning. |
|
77 | 99 |
|
127 | 100 |
The panel assumes, that the elements do not resize themselfes, after it |
101 |
became visible. This is not true for all widgets (buttons or labels may |
|
102 |
like to change). If you have changing elements, tell this to the panel |
|
103 |
with 'aPanel elementsChangeSize:true'. In that case, the panel will react |
|
133 | 104 |
to size changes of its elements, and reorganize things. |
127 | 105 |
|
118 | 106 |
By combining Horizontal- and VerticalPanels (i.e. place a hPanel into a |
107 |
vPanel), most layouts should be implementable. |
|
133 | 108 |
However, iff none of these layout/space combinations is exactly what you need |
118 | 109 |
in your application, create a subclass, and redefine the setChildPositions |
110 |
method there. |
|
125 | 111 |
|
112 |
TODO: for completeness, support #fixRight, #fixRightSpace, |
|
113 |
#rightFit, #rightSpaceFit layouts |
|
127 | 114 |
|
115 |
CAVEAT: this class started with #left and no vertical alignments; |
|
133 | 116 |
as time went by, more layouts were added (by users requests) |
117 |
and noew, many layout combinations are possible. |
|
118 |
Reflecting this, the setup should be changed to use different selectors |
|
119 |
for space-on/off, max-resize and alignment |
|
127 | 120 |
(i.e. having more and more layout symbols makes things a bit confusing ...) |
62 | 121 |
" |
122 |
! |
|
123 |
||
124 |
examples |
|
125 |
" |
|
77 | 126 |
These examples show the effect of various horizontalLayout and |
127 |
verticalLayout settings. Try them all. Especially, notice the |
|
128 |
differences between the xxx and xxxSpace layouts and the effect of |
|
129 |
setting different values for the spacing. |
|
130 |
Try resizing the view and see how the elements get rearranged. |
|
131 |
||
118 | 132 |
Most of the examples below place 3 buttons onto a panel; Of course, |
133 |
you can put any other view into a panel ... the last examples show this. |
|
77 | 134 |
|
135 |
||
127 | 136 |
example: default layout (center) |
38 | 137 |
|
59 | 138 |
|v p b1 b2 b3| |
38 | 139 |
|
59 | 140 |
v := StandardSystemView new. |
118 | 141 |
v label:'default: center'. |
77 | 142 |
|
59 | 143 |
p := HorizontalPanelView in:v. |
144 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
145 |
b1 := Button label:'button1' in:p. |
|
146 |
b2 := Button label:'button2' in:p. |
|
147 |
b3 := Button label:'button3' in:p. |
|
148 |
v extent:300 @ 100. |
|
149 |
v open |
|
38 | 150 |
|
0 | 151 |
|
133 | 152 |
example: same (default center layout) with different sized elements |
153 |
||
154 |
|v p b1 b2 b3| |
|
155 |
||
156 |
v := StandardSystemView new. |
|
157 |
v label:'default: center'. |
|
158 |
||
159 |
p := HorizontalPanelView in:v. |
|
160 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
161 |
b1 := Button label:'but1' in:p. b1 font:(b1 font size:8). |
|
162 |
b2 := Button label:'b2' in:p. b2 font:(b1 font size:24). |
|
163 |
b3 := Button label:'button3' in:p. |
|
164 |
v extent:300 @ 100. |
|
165 |
v open |
|
166 |
||
167 |
||
168 |
example: horizontal default (center); vertical centerMax |
|
169 |
||
170 |
|v p b1 b2 b3| |
|
171 |
||
172 |
v := StandardSystemView new. |
|
173 |
v label:'vL=centerMax'. |
|
174 |
p := HorizontalPanelView in:v. |
|
175 |
p verticalLayout:#centerMax. |
|
176 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
177 |
b1 := Button label:'but1' in:p. b1 font:(b1 font size:8). |
|
178 |
b2 := Button label:'b2' in:p. b2 font:(b1 font size:24). |
|
179 |
b3 := Button label:'button3' in:p. |
|
180 |
v extent:300 @ 100. |
|
181 |
v open |
|
182 |
||
183 |
||
184 |
example: horizontal default (center); vertical topMax |
|
185 |
||
186 |
|v p b1 b2 b3| |
|
187 |
||
188 |
v := StandardSystemView new. |
|
189 |
v label:'vL=topMax'. |
|
190 |
p := HorizontalPanelView in:v. |
|
191 |
p verticalLayout:#topMax. |
|
192 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
193 |
b1 := Button label:'but1' in:p. b1 font:(b1 font size:8). |
|
194 |
b2 := Button label:'b2' in:p. b2 font:(b1 font size:24). |
|
195 |
b3 := Button label:'button3' in:p. |
|
196 |
v extent:300 @ 100. |
|
197 |
v open |
|
198 |
||
199 |
||
200 |
example: horizontal default (center); vertical topSpaceMax |
|
201 |
||
202 |
|v p b1 b2 b3| |
|
203 |
||
204 |
v := StandardSystemView new. |
|
205 |
v label:'vL=topSpaceMax'. |
|
206 |
p := HorizontalPanelView in:v. |
|
207 |
p verticalLayout:#topSpaceMax. |
|
208 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
209 |
b1 := Button label:'but1' in:p. b1 font:(b1 font size:8). |
|
210 |
b2 := Button label:'b2' in:p. b2 font:(b1 font size:24). |
|
211 |
b3 := Button label:'button3' in:p. |
|
212 |
v extent:300 @ 100. |
|
213 |
v open |
|
214 |
||
215 |
||
216 |
example: horizontal default (center); vertical bottomMax |
|
217 |
||
218 |
|v p b1 b2 b3| |
|
219 |
||
220 |
v := StandardSystemView new. |
|
221 |
v label:'vL=bottomMax'. |
|
222 |
p := HorizontalPanelView in:v. |
|
223 |
p verticalLayout:#bottomMax. |
|
224 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
225 |
b1 := Button label:'but1' in:p. b1 font:(b1 font size:8). |
|
226 |
b2 := Button label:'b2' in:p. b2 font:(b1 font size:24). |
|
227 |
b3 := Button label:'button3' in:p. |
|
228 |
v extent:300 @ 100. |
|
229 |
v open |
|
230 |
||
231 |
||
232 |
example: horizontal default (center); vertical bottomSpaceMax |
|
233 |
||
234 |
|v p b1 b2 b3| |
|
235 |
||
236 |
v := StandardSystemView new. |
|
237 |
v label:'vL=bottomSpaceMax'. |
|
238 |
p := HorizontalPanelView in:v. |
|
239 |
p verticalLayout:#bottomSpaceMax. |
|
240 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
241 |
b1 := Button label:'but1' in:p. b1 font:(b1 font size:8). |
|
242 |
b2 := Button label:'b2' in:p. b2 font:(b1 font size:24). |
|
243 |
b3 := Button label:'button3' in:p. |
|
244 |
v extent:300 @ 100. |
|
245 |
v open |
|
246 |
||
247 |
||
127 | 248 |
example: left-layout (vertical is default -> center) |
38 | 249 |
|
59 | 250 |
|v p b1 b2 b3| |
38 | 251 |
|
59 | 252 |
v := StandardSystemView new. |
253 |
p := HorizontalPanelView in:v. |
|
118 | 254 |
v label:'hL=left; vL=default (center)'. |
77 | 255 |
|
62 | 256 |
p horizontalLayout:#left. |
59 | 257 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
258 |
b1 := Button label:'button1' in:p. |
|
259 |
b2 := Button label:'button2' in:p. |
|
260 |
b3 := Button label:'button3' in:p. |
|
261 |
v extent:300 @ 100. |
|
262 |
v open |
|
38 | 263 |
|
264 |
||
127 | 265 |
example: left starting with spacing (vertical is default -> center) |
77 | 266 |
|
267 |
|v p b1 b2 b3| |
|
268 |
||
269 |
v := StandardSystemView new. |
|
270 |
p := HorizontalPanelView in:v. |
|
118 | 271 |
v label:'hL=leftSpace; vL=center'. |
77 | 272 |
|
273 |
p horizontalLayout:#leftSpace. |
|
274 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
275 |
b1 := Button label:'button1' in:p. |
|
276 |
b2 := Button label:'button2' in:p. |
|
277 |
b3 := Button label:'button3' in:p. |
|
278 |
v extent:300 @ 100. |
|
279 |
v open |
|
280 |
||
281 |
||
127 | 282 |
example: leftFit-layout (vertical is default -> center) |
38 | 283 |
|
59 | 284 |
|v p b1 b2 b3| |
0 | 285 |
|
59 | 286 |
v := StandardSystemView new. |
287 |
p := HorizontalPanelView in:v. |
|
118 | 288 |
v label:'hL=leftFit; vL=center'. |
77 | 289 |
|
290 |
p horizontalLayout:#leftFit. |
|
291 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
292 |
b1 := Button label:'button1' in:p. |
|
293 |
b2 := Button label:'button2' in:p. |
|
294 |
b3 := Button label:'button3' in:p. |
|
295 |
v extent:300 @ 100. |
|
296 |
v open |
|
297 |
||
298 |
||
127 | 299 |
example: leftSpaceFit-layout (vertical is default -> center) |
77 | 300 |
|
301 |
|v p b1 b2 b3| |
|
302 |
||
303 |
v := StandardSystemView new. |
|
304 |
p := HorizontalPanelView in:v. |
|
118 | 305 |
v label:'hL=leftSpaceFit; vL=center'. |
77 | 306 |
|
307 |
p horizontalLayout:#leftSpaceFit. |
|
308 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
309 |
b1 := Button label:'button1' in:p. |
|
310 |
b2 := Button label:'button2' in:p. |
|
311 |
b3 := Button label:'button3' in:p. |
|
312 |
v extent:300 @ 100. |
|
313 |
v open |
|
314 |
||
315 |
||
127 | 316 |
example: right-layout (vertical is default -> center) |
77 | 317 |
|
318 |
|v p b1 b2 b3| |
|
319 |
||
320 |
v := StandardSystemView new. |
|
321 |
p := HorizontalPanelView in:v. |
|
118 | 322 |
v label:'hL=right; vL=center'. |
77 | 323 |
|
62 | 324 |
p horizontalLayout:#right. |
59 | 325 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
326 |
b1 := Button label:'button1' in:p. |
|
327 |
b2 := Button label:'button2' in:p. |
|
328 |
b3 := Button label:'button3' in:p. |
|
329 |
v extent:300 @ 100. |
|
330 |
v open |
|
38 | 331 |
|
332 |
||
127 | 333 |
example: right with initial spacing (vertical is default -> center) |
77 | 334 |
|
335 |
|v p b1 b2 b3| |
|
336 |
||
337 |
v := StandardSystemView new. |
|
338 |
p := HorizontalPanelView in:v. |
|
118 | 339 |
v label:'hL=rightSpace; vL=center'. |
77 | 340 |
|
341 |
p horizontalLayout:#rightSpace. |
|
342 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
343 |
b1 := Button label:'button1' in:p. |
|
344 |
b2 := Button label:'button2' in:p. |
|
345 |
b3 := Button label:'button3' in:p. |
|
346 |
v extent:300 @ 100. |
|
347 |
v open |
|
348 |
||
349 |
||
127 | 350 |
example: fit-layout (vertical is default -> center) |
38 | 351 |
|
59 | 352 |
|v p b1 b2 b3| |
38 | 353 |
|
59 | 354 |
v := StandardSystemView new. |
355 |
p := HorizontalPanelView in:v. |
|
77 | 356 |
p horizontalLayout:#fit. |
118 | 357 |
v label:'hL=fit; vL=center'. |
77 | 358 |
|
359 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
360 |
b1 := Button label:'button1' in:p. |
|
361 |
b2 := Button label:'button2' in:p. |
|
362 |
b3 := Button label:'button3' in:p. |
|
363 |
v extent:300 @ 100. |
|
364 |
v open |
|
365 |
||
366 |
||
127 | 367 |
example: full fit i.e. no spacing (vertical is default -> center) |
77 | 368 |
|
369 |
|v p b1 b2 b3| |
|
370 |
||
371 |
v := StandardSystemView new. |
|
372 |
p := HorizontalPanelView in:v. |
|
373 |
p horizontalLayout:#fit. |
|
374 |
p horizontalSpace:0. |
|
118 | 375 |
v label:'hL=fit hS=0; vL=center'. |
77 | 376 |
|
377 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
378 |
b1 := Button label:'button1' in:p. |
|
379 |
b2 := Button label:'button2' in:p. |
|
380 |
b3 := Button label:'button3' in:p. |
|
381 |
v extent:300 @ 100. |
|
382 |
v open |
|
383 |
||
384 |
||
127 | 385 |
example: fit with spacing (vertical is default -> center) |
77 | 386 |
|
387 |
|v p b1 b2 b3| |
|
388 |
||
389 |
v := StandardSystemView new. |
|
390 |
p := HorizontalPanelView in:v. |
|
118 | 391 |
v label:'hL=fitSpace; vL=center'. |
77 | 392 |
|
393 |
p horizontalLayout:#fitSpace. |
|
62 | 394 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
395 |
b1 := Button label:'button1' in:p. |
|
396 |
b2 := Button label:'button2' in:p. |
|
397 |
b3 := Button label:'button3' in:p. |
|
398 |
v extent:300 @ 100. |
|
399 |
v open |
|
400 |
||
77 | 401 |
|
127 | 402 |
example: spread-layout (vertical is default -> center) |
77 | 403 |
|
404 |
|v p b1 b2 b3| |
|
405 |
||
406 |
v := StandardSystemView new. |
|
407 |
p := HorizontalPanelView in:v. |
|
408 |
p horizontalLayout:#spread. |
|
118 | 409 |
v label:'hL=spread; vL=center'. |
77 | 410 |
|
411 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
412 |
b1 := Button label:'button1' in:p. |
|
413 |
b2 := Button label:'button2' in:p. |
|
414 |
b3 := Button label:'button3' in:p. |
|
415 |
v extent:300 @ 100. |
|
416 |
v open |
|
417 |
||
418 |
||
127 | 419 |
example: spread with spacing (vertical is default -> center) |
77 | 420 |
|
421 |
|v p b1 b2 b3| |
|
422 |
||
423 |
v := StandardSystemView new. |
|
424 |
p := HorizontalPanelView in:v. |
|
118 | 425 |
v label:'hL=spreadSpace; vL=center'. |
77 | 426 |
|
427 |
p horizontalLayout:#spreadSpace. |
|
428 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
429 |
b1 := Button label:'button1' in:p. |
|
430 |
b2 := Button label:'button2' in:p. |
|
431 |
b3 := Button label:'button3' in:p. |
|
432 |
v extent:300 @ 100. |
|
433 |
v open |
|
434 |
||
435 |
||
436 |
example: spread with spacing; vertical fit |
|
437 |
||
438 |
|v p b1 b2 b3| |
|
439 |
||
440 |
v := StandardSystemView new. |
|
441 |
p := HorizontalPanelView in:v. |
|
118 | 442 |
v label:'hL=spreadSpace; vL=fit'. |
77 | 443 |
|
444 |
p horizontalLayout:#spreadSpace. |
|
445 |
p verticalLayout:#fit. |
|
446 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
447 |
b1 := Button label:'button1' in:p. |
|
448 |
b2 := Button label:'button2' in:p. |
|
449 |
b3 := Button label:'button3' in:p. |
|
450 |
v extent:300 @ 100. |
|
451 |
v open |
|
452 |
||
453 |
||
454 |
example: spread with spacing; vertical fit with spacing |
|
455 |
||
456 |
|v p b1 b2 b3| |
|
457 |
||
458 |
v := StandardSystemView new. |
|
459 |
p := HorizontalPanelView in:v. |
|
118 | 460 |
v label:'hL=spreadSpace; vL=fitSpace'. |
77 | 461 |
|
462 |
p horizontalLayout:#spreadSpace. |
|
463 |
p verticalLayout:#fitSpace. |
|
464 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
465 |
b1 := Button label:'button1' in:p. |
|
466 |
b2 := Button label:'button2' in:p. |
|
467 |
b3 := Button label:'button3' in:p. |
|
468 |
v extent:300 @ 100. |
|
469 |
v open |
|
470 |
||
471 |
||
62 | 472 |
example: fit - top |
473 |
||
474 |
|v p b1 b2 b3| |
|
475 |
||
476 |
v := StandardSystemView new. |
|
477 |
p := HorizontalPanelView in:v. |
|
118 | 478 |
v label:'hL=fit; vL=top'. |
77 | 479 |
|
62 | 480 |
p horizontalLayout:#fit. |
481 |
p verticalLayout:#top. |
|
482 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
483 |
b1 := Button label:'button1' in:p. |
|
484 |
b2 := Button label:'button2' in:p. |
|
485 |
b3 := Button label:'button3' in:p. |
|
486 |
v extent:300 @ 100. |
|
487 |
v open |
|
488 |
||
77 | 489 |
|
490 |
example: fit with initial spacing |
|
491 |
||
492 |
|v p b1 b2 b3| |
|
493 |
||
494 |
v := StandardSystemView new. |
|
495 |
p := HorizontalPanelView in:v. |
|
118 | 496 |
v label:'hL=fitSpace; vL=top'. |
77 | 497 |
|
498 |
p horizontalLayout:#fitSpace. |
|
499 |
p verticalLayout:#top. |
|
500 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
501 |
b1 := Button label:'button1' in:p. |
|
502 |
b2 := Button label:'button2' in:p. |
|
503 |
b3 := Button label:'button3' in:p. |
|
504 |
v extent:300 @ 100. |
|
505 |
v open |
|
506 |
||
507 |
||
508 |
example: fit with initial spacing in both directions |
|
509 |
||
510 |
|v p b1 b2 b3| |
|
511 |
||
512 |
v := StandardSystemView new. |
|
513 |
p := HorizontalPanelView in:v. |
|
118 | 514 |
v label:'hL=fitSpace; vL=fitSpace'. |
77 | 515 |
|
516 |
p horizontalLayout:#fitSpace. |
|
517 |
p verticalLayout:#fitSpace. |
|
518 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
519 |
b1 := Button label:'button1' in:p. |
|
520 |
b2 := Button label:'button2' in:p. |
|
521 |
b3 := Button label:'button3' in:p. |
|
522 |
v extent:300 @ 100. |
|
523 |
v open |
|
524 |
||
525 |
||
526 |
example: fit without spacing in both directions |
|
527 |
||
528 |
|v p b1 b2 b3| |
|
529 |
||
530 |
v := StandardSystemView new. |
|
531 |
p := HorizontalPanelView in:v. |
|
118 | 532 |
v label:'hL=fit hS=0; vL=fit'. |
77 | 533 |
|
534 |
p horizontalLayout:#fit. |
|
535 |
p verticalLayout:#fit. |
|
536 |
p horizontalSpace:0. |
|
537 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
538 |
b1 := Button label:'button1' in:p. |
|
539 |
b2 := Button label:'button2' in:p. |
|
540 |
b3 := Button label:'button3' in:p. |
|
541 |
v extent:300 @ 100. |
|
542 |
v open |
|
543 |
||
544 |
||
545 |
example: fit with initial spacing; top with spacing |
|
546 |
||
547 |
|v p b1 b2 b3| |
|
548 |
||
549 |
v := StandardSystemView new. |
|
550 |
p := HorizontalPanelView in:v. |
|
118 | 551 |
v label:'hL=fitSpace; vL=topSpace'. |
77 | 552 |
|
553 |
p horizontalLayout:#fitSpace. |
|
554 |
p verticalLayout:#topSpace. |
|
555 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
556 |
b1 := Button label:'button1' in:p. |
|
557 |
b2 := Button label:'button2' in:p. |
|
558 |
b3 := Button label:'button3' in:p. |
|
559 |
v extent:300 @ 100. |
|
560 |
v open |
|
561 |
||
562 |
||
62 | 563 |
example: fit - top without spacing |
564 |
||
565 |
|v p b1 b2 b3| |
|
566 |
||
567 |
v := StandardSystemView new. |
|
568 |
p := HorizontalPanelView in:v. |
|
118 | 569 |
v label:'hL=fit; vL=top'. |
77 | 570 |
|
62 | 571 |
p horizontalLayout:#fit. |
572 |
p verticalLayout:#top. |
|
573 |
p horizontalSpace:0. |
|
574 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
575 |
b1 := Button label:'button1' in:p. |
|
576 |
b2 := Button label:'button2' in:p. |
|
577 |
b3 := Button label:'button3' in:p. |
|
578 |
v extent:300 @ 100. |
|
579 |
v open |
|
580 |
||
77 | 581 |
|
62 | 582 |
example: fit - bottom with spacing and bottomSpace |
583 |
||
584 |
|v p b1 b2 b3| |
|
585 |
||
586 |
v := StandardSystemView new. |
|
587 |
p := HorizontalPanelView in:v. |
|
118 | 588 |
v label:'hL=fitSpace; vL=bottomSpace'. |
77 | 589 |
|
590 |
p horizontalLayout:#fitSpace. |
|
62 | 591 |
p verticalLayout:#bottomSpace. |
592 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
593 |
b1 := Button label:'button1' in:p. |
|
594 |
b2 := Button label:'button2' in:p. |
|
595 |
b3 := Button label:'button3' in:p. |
|
596 |
v extent:300 @ 100. |
|
597 |
v open |
|
598 |
||
77 | 599 |
|
62 | 600 |
example: fit no horizontal space - bottom with spacing and bottomSpace |
601 |
||
602 |
|v p b1 b2 b3| |
|
603 |
||
604 |
v := StandardSystemView new. |
|
605 |
p := HorizontalPanelView in:v. |
|
118 | 606 |
v label:'hL=fit; vL=bottomSpace'. |
77 | 607 |
|
62 | 608 |
p horizontalLayout:#fit. |
609 |
p verticalLayout:#bottomSpace. |
|
610 |
p horizontalSpace:0. |
|
59 | 611 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
612 |
b1 := Button label:'button1' in:p. |
|
613 |
b2 := Button label:'button2' in:p. |
|
614 |
b3 := Button label:'button3' in:p. |
|
615 |
v extent:300 @ 100. |
|
616 |
v open |
|
77 | 617 |
|
133 | 618 |
example: leftMax - vertical default |
619 |
||
620 |
|v p b1 b2 b3| |
|
621 |
||
622 |
v := StandardSystemView new. |
|
623 |
p := HorizontalPanelView in:v. |
|
624 |
v label:'hL=leftMax; vL=default'. |
|
625 |
||
626 |
p horizontalLayout:#leftMax. |
|
627 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
628 |
b1 := Button label:'button1' in:p. |
|
629 |
b2 := Button label:'b2' in:p. |
|
630 |
b3 := Button label:'but3' in:p. |
|
631 |
v extent:300 @ 100. |
|
632 |
v open |
|
633 |
||
634 |
||
635 |
example: leftSpaceMax - vertical default |
|
636 |
||
637 |
|v p b1 b2 b3| |
|
638 |
||
639 |
v := StandardSystemView new. |
|
640 |
p := HorizontalPanelView in:v. |
|
641 |
v label:'hL=leftSpaceMax; vL=default'. |
|
642 |
||
643 |
p horizontalLayout:#leftSpaceMax. |
|
644 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
645 |
b1 := Button label:'button1' in:p. |
|
646 |
b2 := Button label:'b2' in:p. |
|
647 |
b3 := Button label:'but3' in:p. |
|
648 |
v extent:300 @ 100. |
|
649 |
v open |
|
650 |
||
651 |
||
652 |
example: rightMax - vertical default |
|
653 |
||
654 |
|v p b1 b2 b3| |
|
655 |
||
656 |
v := StandardSystemView new. |
|
657 |
p := HorizontalPanelView in:v. |
|
658 |
v label:'hL=rightMax; vL=default'. |
|
659 |
||
660 |
p horizontalLayout:#rightMax. |
|
661 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
662 |
b1 := Button label:'button1' in:p. |
|
663 |
b2 := Button label:'b2' in:p. |
|
664 |
b3 := Button label:'but3' in:p. |
|
665 |
v extent:300 @ 100. |
|
666 |
v open |
|
667 |
||
668 |
||
669 |
example: rightSpaceMax - vertical default |
|
670 |
||
671 |
|v p b1 b2 b3| |
|
672 |
||
673 |
v := StandardSystemView new. |
|
674 |
p := HorizontalPanelView in:v. |
|
675 |
v label:'hL=rightSpaceMax; vL=default'. |
|
676 |
||
677 |
p horizontalLayout:#rightSpaceMax. |
|
678 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
679 |
b1 := Button label:'button1' in:p. |
|
680 |
b2 := Button label:'b2' in:p. |
|
681 |
b3 := Button label:'but3' in:p. |
|
682 |
v extent:300 @ 100. |
|
683 |
v open |
|
684 |
||
685 |
||
686 |
example: centerMax - vertical default |
|
687 |
||
688 |
|v p b1 b2 b3| |
|
689 |
||
690 |
v := StandardSystemView new. |
|
691 |
p := HorizontalPanelView in:v. |
|
692 |
v label:'hL=centerMax; vL=default'. |
|
693 |
||
694 |
p horizontalLayout:#centerMax. |
|
695 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
696 |
b1 := Button label:'button1' in:p. |
|
697 |
b2 := Button label:'b2' in:p. |
|
698 |
b3 := Button label:'but3' in:p. |
|
699 |
v extent:300 @ 100. |
|
700 |
v open |
|
701 |
||
702 |
||
703 |
example: spreadMax - vertical default |
|
704 |
||
705 |
|v p b1 b2 b3| |
|
706 |
||
707 |
v := StandardSystemView new. |
|
708 |
p := HorizontalPanelView in:v. |
|
709 |
v label:'hL=spreadMax; vL=default'. |
|
710 |
||
711 |
p horizontalLayout:#spreadMax. |
|
712 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
713 |
b1 := Button label:'button1' in:p. |
|
714 |
b2 := Button label:'b2' in:p. |
|
715 |
b3 := Button label:'but3' in:p. |
|
716 |
v extent:300 @ 100. |
|
717 |
v open |
|
718 |
||
719 |
||
720 |
example: spreadSpaceMax - vertical default |
|
721 |
||
722 |
|v p b1 b2 b3| |
|
723 |
||
724 |
v := StandardSystemView new. |
|
725 |
p := HorizontalPanelView in:v. |
|
726 |
v label:'hL=spreadSpaceMax; vL=default'. |
|
727 |
||
728 |
p horizontalLayout:#spreadSpaceMax. |
|
729 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
730 |
b1 := Button label:'button1' in:p. |
|
731 |
b2 := Button label:'b2' in:p. |
|
732 |
b3 := Button label:'but3' in:p. |
|
733 |
v extent:300 @ 100. |
|
734 |
v open |
|
735 |
||
736 |
||
737 |
example: maximize elements in both directions and center |
|
738 |
||
739 |
|v p b1 b2 b3| |
|
740 |
||
741 |
v := StandardSystemView new. |
|
742 |
v label:'hL=centerMax; vL=centerMax'. |
|
743 |
||
744 |
p := HorizontalPanelView in:v. |
|
745 |
p horizontalLayout:#centerMax. |
|
746 |
p verticalLayout:#centerMax. |
|
747 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
748 |
b1 := Button label:'but1' in:p. b1 font:(b1 font size:8). |
|
749 |
b2 := Button label:'b2' in:p. b2 font:(b1 font size:24). |
|
750 |
b3 := Button label:'button3' in:p. |
|
751 |
v extent:300 @ 100. |
|
752 |
v open |
|
753 |
||
754 |
||
118 | 755 |
example: placing hPanels into a vPanel |
756 |
||
757 |
|v vP hP1 hP2 hP3 b1 b2 b3 b4 b5 b6 b7 b8 b9| |
|
758 |
||
759 |
v := StandardSystemView new. |
|
760 |
vP := VerticalPanelView in:v. |
|
761 |
vP origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
762 |
vP verticalLayout:#fit; |
|
763 |
verticalSpace:0; |
|
764 |
horizontalLayout:#fit. |
|
765 |
||
766 |
hP1 := HorizontalPanelView in:vP. |
|
767 |
hP1 horizontalLayout:#fitSpace; |
|
768 |
verticalLayout:#center. |
|
769 |
b1 := Button label:'button1' in:hP1. |
|
770 |
b2 := Button label:'button2' in:hP1. |
|
771 |
b3 := Button label:'button3' in:hP1. |
|
772 |
||
773 |
hP2 := HorizontalPanelView in:vP. |
|
774 |
hP2 horizontalLayout:#fitSpace; |
|
775 |
verticalLayout:#center. |
|
776 |
b4 := Button label:'button4' in:hP2. |
|
777 |
b5 := Button label:'button5' in:hP2. |
|
778 |
b6 := Button label:'button6' in:hP2. |
|
779 |
||
780 |
hP3 := HorizontalPanelView in:vP. |
|
781 |
hP3 horizontalLayout:#fitSpace; |
|
782 |
verticalLayout:#center. |
|
783 |
b7 := Button label:'button7' in:hP3. |
|
784 |
b8 := Button label:'button8' in:hP3. |
|
785 |
b9 := Button label:'button9' in:hP3. |
|
786 |
||
787 |
v extent:300 @ 300. |
|
788 |
v open |
|
789 |
||
77 | 790 |
example: a browser like table, where the rightmost list |
791 |
extends to the far right. |
|
792 |
||
793 |
|v p l1 l2 l3| |
|
794 |
||
795 |
v := StandardSystemView new. |
|
796 |
p := HorizontalPanelView in:v. |
|
125 | 797 |
v label:'hL=leftFit hS=0; vL=fit'. |
77 | 798 |
|
799 |
p horizontalLayout:#leftFit. |
|
125 | 800 |
p horizontalSpace:0. |
77 | 801 |
p verticalLayout:#fit. |
802 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0). |
|
803 |
||
804 |
l1 := ScrollableView for:FileSelectionList in:p. |
|
805 |
l1 stayInDirectory:true. |
|
806 |
l1 ignoreParentDirectory:true. |
|
807 |
l1 directory:'/'. |
|
808 |
l1 action:[:selection | l2 directory:(l1 selectedPathname)]. |
|
809 |
||
810 |
l2 := ScrollableView for:FileSelectionList in:p. |
|
811 |
l2 stayInDirectory:true. |
|
812 |
l2 directory:nil. |
|
813 |
l2 ignoreParentDirectory:true. |
|
814 |
l2 action:[:selection | l3 directory:(l2 selectedPathname)]. |
|
815 |
||
816 |
l3 := ScrollableView for:FileSelectionList in:p. |
|
817 |
l3 directory:nil. |
|
118 | 818 |
l3 ignoreParentDirectory:false. |
77 | 819 |
v extent:400 @ 300. |
820 |
v open |
|
125 | 821 |
|
822 |
||
823 |
trouble example: self resizing elements may cause trouble |
|
824 |
||
825 |
|v p l1 l2 l3| |
|
826 |
||
827 |
v := StandardSystemView new. |
|
828 |
p := HorizontalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:v. |
|
829 |
||
830 |
l1 := (Label label:'one' in:p) level:-1. |
|
831 |
l2 := (Label label:'two' in:p) level:-1. |
|
832 |
l3 := (Label label:'three' in:p) level:-1. |
|
833 |
||
834 |
v extent:400 @ 300. |
|
835 |
v open. |
|
836 |
||
837 |
(Delay forSeconds:5) wait. |
|
838 |
||
839 |
l1 label:'oneone'. |
|
840 |
l2 label:'twotwo'. |
|
841 |
l3 label:'threethree'. |
|
842 |
||
843 |
||
844 |
fixed trouble example: tell the panel that this situation may happen |
|
845 |
||
846 |
|v p l1 l2 l3| |
|
847 |
||
848 |
v := StandardSystemView new. |
|
849 |
p := HorizontalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:v. |
|
850 |
p elementsChangeSize:true. |
|
851 |
||
852 |
l1 := (Label label:'one' in:p) level:-1. |
|
853 |
l2 := (Label label:'two' in:p) level:-1. |
|
854 |
l3 := (Label label:'three' in:p) level:-1. |
|
855 |
||
856 |
v extent:400 @ 300. |
|
857 |
v open. |
|
858 |
||
859 |
(Delay forSeconds:5) wait. |
|
860 |
||
861 |
l1 label:'oneone'. |
|
862 |
l2 label:'twotwo'. |
|
863 |
l3 label:'threethree'. |
|
38 | 864 |
" |
865 |
! ! |
|
0 | 866 |
|
62 | 867 |
!HorizontalPanelView methodsFor:'accessing'! |
868 |
||
869 |
horizontalLayout |
|
870 |
"return the horizontal layout as symbol. |
|
871 |
the returned value is one of |
|
133 | 872 |
#left arrange elements at the left |
873 |
#leftSpace arrange elements at the left, start with spacing |
|
874 |
#fixLeft same as #left, but do not reduce spacing in case of no fit |
|
875 |
#fixLeftSpace same as #leftSpace, but do not reduce spacing in case of no fit |
|
876 |
#right arrange elements at the right |
|
877 |
#rightSpace arrange elements at the right, start with spacing |
|
878 |
#center arrange elements in the center |
|
879 |
#spread spread elements evenly |
|
880 |
#spreadSpace spread elements evenly with spacing at the ends |
|
881 |
#fit like #spread, but resize elements for tight packing |
|
882 |
#fitSpace like #fit, with additional spacing at the far ends |
|
883 |
#leftFit like #left, but extend the last element to the right |
|
884 |
#leftSpaceFit like #leftSpace, but extend the last element to the right |
|
77 | 885 |
the default is #center |
118 | 886 |
See the class documentation for the meanings. |
62 | 887 |
" |
888 |
||
889 |
^ hLayout |
|
890 |
! |
|
891 |
||
892 |
verticalLayout |
|
893 |
"return the vertical layout as a symbol. |
|
894 |
the returned value is one of |
|
133 | 895 |
#top place element at the top |
896 |
#topSpace place element at the top, offset by verticalSpace |
|
897 |
#center place it horizontally centered |
|
898 |
#bottom place it at the bottom |
|
899 |
#bottomSpace place it at the bottom, offset by verticalSpace |
|
900 |
#fit resize elements vertically to fit this panel |
|
901 |
#fitSpace like #fit, but with spacing |
|
902 |
||
903 |
#topMax like #top, but resize all views vertically to max height |
|
904 |
#topSpaceMax like #topSpace, but resize all views vertically to max height |
|
905 |
#bottomMax like #bottom, but resize all views vertically to max height |
|
906 |
#bottomSpaceMax like #bottomSpace, but resize all views vertically to max height |
|
907 |
#centerMax like #center, but resize all views vertically to max height |
|
77 | 908 |
the default is #center |
118 | 909 |
See the class documentation for the meanings. |
62 | 910 |
" |
911 |
||
912 |
^ vLayout |
|
913 |
! |
|
914 |
||
915 |
horizontalLayout:aSymbol |
|
916 |
"change the horizontal layout as symbol. |
|
917 |
The argument, aSymbol must be one of: |
|
133 | 918 |
#left arrange elements at the left |
919 |
#leftSpace arrange elements at the left, start with spacing |
|
920 |
#fixLeft same as #left, but do not reduce spacing in case of no fit |
|
921 |
#fixLeftSpace same as #leftSpace, but do not reduce spacing in case of no fit |
|
922 |
#right arrange elements at the right |
|
923 |
#rightSpace arrange elements at the right, start with spacing |
|
924 |
#center arrange elements in the center |
|
925 |
#spread spread elements evenly |
|
926 |
#spreadSpace spread elements evenly with spacing at the ends |
|
927 |
#fit like #spread, but resize elements for tight packing |
|
928 |
#fitSpace like #fit, with additional spacing at the far ends |
|
929 |
#leftFit like #left, but extend the last element to the right |
|
930 |
#leftSpaceFit like #leftSpace, but extend the last element to the right |
|
118 | 931 |
the default (if never changed) is #center. |
932 |
See the class documentation for the meanings. |
|
62 | 933 |
" |
934 |
||
935 |
(hLayout ~~ aSymbol) ifTrue:[ |
|
936 |
hLayout := aSymbol. |
|
937 |
self layoutChanged |
|
938 |
] |
|
939 |
! |
|
940 |
||
941 |
verticalLayout:aSymbol |
|
942 |
"change the vertical layout as a symbol. |
|
943 |
The argument, aSymbol must be one of: |
|
133 | 944 |
#top place element at the top |
945 |
#topSpace place element at the top, offset by verticalSpace |
|
946 |
#center place it horizontally centered |
|
947 |
#bottom place it at the bottom |
|
948 |
#bottomSpace place it at the bottom, offset by verticalSpace |
|
949 |
#fit resize elements vertically to fit this panel |
|
950 |
#fitSpace like #fit, but with spacing |
|
951 |
||
952 |
#topMax like #top, but resize all views vertically to max height |
|
953 |
#topSpaceMax like #topSpace, but resize all views vertically to max height |
|
954 |
#bottomMax like #bottom, but resize all views vertically to max height |
|
955 |
#bottomSpaceMax like #bottomSpace, but resize all views vertically to max height |
|
956 |
#centerMax like #center, but resize all views vertically to max height |
|
77 | 957 |
the default (if never changed) is #center |
118 | 958 |
See the class documentation for the meanings. |
62 | 959 |
" |
960 |
||
961 |
(vLayout ~~ aSymbol) ifTrue:[ |
|
962 |
vLayout := aSymbol. |
|
963 |
self layoutChanged |
|
964 |
] |
|
965 |
! |
|
966 |
||
967 |
layout |
|
968 |
"leftover for historic reasons - do not use any more" |
|
969 |
||
130 | 970 |
self obsoleteMethodWarning:'use #horizontalLayout'. |
971 |
^ self horizontalLayout |
|
62 | 972 |
! |
973 |
||
155 | 974 |
layout:something |
975 |
"OBSOLETE compatibility interface. Will vanish. |
|
976 |
leftover for historic reasons - do not use any more. |
|
977 |
In the meantime, try to figure out what is meant ... a kludge" |
|
978 |
||
979 |
something isLayout ifTrue:[^ super layout:something]. |
|
62 | 980 |
|
130 | 981 |
self obsoleteMethodWarning:'use #horizontalLayout:'. |
155 | 982 |
^ self horizontalLayout:something |
983 |
||
984 |
"Modified: 31.8.1995 / 23:07:33 / claus" |
|
62 | 985 |
! ! |
986 |
||
987 |
||
0 | 988 |
!HorizontalPanelView methodsFor:'queries'! |
989 |
||
130 | 990 |
preferredExtent |
0 | 991 |
"return a good extent, one that makes subviews fit" |
992 |
||
59 | 993 |
|sumOfWidths maxHeight maxWidth| |
0 | 994 |
|
995 |
subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace]. |
|
996 |
||
997 |
"compute net height needed" |
|
998 |
||
999 |
sumOfWidths := 0. |
|
1000 |
maxHeight := 0. |
|
59 | 1001 |
maxWidth := 0. |
0 | 1002 |
|
1003 |
subViews do:[:child | |
|
62 | 1004 |
|childsPreference| |
1005 |
||
133 | 1006 |
"/ better to use component's preferredExtent ... |
1007 |
||
130 | 1008 |
childsPreference := child preferredExtent. |
62 | 1009 |
sumOfWidths := sumOfWidths + childsPreference x. |
1010 |
maxHeight := maxHeight max:childsPreference y. |
|
1011 |
maxWidth := maxWidth max:childsPreference x. |
|
1012 |
||
133 | 1013 |
"/ ... instead of actual extent |
62 | 1014 |
"/ sumOfWidths := sumOfWidths + child widthIncludingBorder. |
1015 |
"/ maxHeight := maxHeight max:(child heightIncludingBorder). |
|
1016 |
"/ maxWidth := maxWidth max:(child widthIncludingBorder). |
|
0 | 1017 |
]. |
1018 |
borderWidth ~~ 0 ifTrue:[ |
|
59 | 1019 |
sumOfWidths := sumOfWidths + (horizontalSpace * 2). |
1020 |
maxHeight := maxHeight + (verticalSpace * 2). |
|
0 | 1021 |
]. |
133 | 1022 |
(hLayout == #fit |
1023 |
or:[hLayout == #fitSpace |
|
1024 |
or:[hLayout endsWith:'Max']]) ifTrue:[ |
|
59 | 1025 |
sumOfWidths := maxWidth * subViews size. |
1026 |
borderWidth ~~ 0 ifTrue:[ |
|
131 | 1027 |
sumOfWidths := sumOfWidths + (horizontalSpace * 2). |
59 | 1028 |
] |
1029 |
] ifFalse:[ |
|
1030 |
sumOfWidths := sumOfWidths + ((subViews size - 1) * horizontalSpace). |
|
131 | 1031 |
hLayout == #leftSpace ifTrue:[ |
1032 |
sumOfWidths := sumOfWidths + horizontalSpace |
|
1033 |
] ifFalse:[ |
|
1034 |
((hLayout == #center) or:[hLayout == #spread]) ifTrue:[ |
|
1035 |
sumOfWidths := sumOfWidths + (horizontalSpace * 2) |
|
1036 |
] |
|
1037 |
]. |
|
59 | 1038 |
]. |
0 | 1039 |
|
65 | 1040 |
((vLayout == #topSpace) or:[vLayout == #bottomSpace]) ifTrue:[ |
1041 |
maxHeight := maxHeight + verticalSpace |
|
1042 |
] ifFalse:[ |
|
77 | 1043 |
((vLayout == #fitSpace) or:[vLayout == #center]) ifTrue:[ |
65 | 1044 |
maxHeight := maxHeight + (verticalSpace * 2) |
1045 |
] |
|
1046 |
]. |
|
1047 |
||
0 | 1048 |
^ sumOfWidths @ maxHeight |
1049 |
! ! |
|
1050 |
||
1051 |
!HorizontalPanelView methodsFor:'layout'! |
|
1052 |
||
1053 |
setChildPositions |
|
1054 |
"(re)compute position of every child whenever childs are added or |
|
1055 |
my size has changed" |
|
1056 |
||
133 | 1057 |
|xpos space sumOfWidths numChilds l wEach wInside hL vL resizeToMaxV |
162 | 1058 |
resizeToMaxH maxHeight maxWidth d| |
0 | 1059 |
|
1060 |
subViews isNil ifTrue:[^ self]. |
|
1061 |
||
1062 |
space := horizontalSpace. |
|
59 | 1063 |
numChilds := subViews size. |
77 | 1064 |
wInside := width - (margin * 2) + (borderWidth*2) - subViews last borderWidth. |
59 | 1065 |
|
118 | 1066 |
hL := hLayout. |
1067 |
vL := vLayout. |
|
1068 |
||
133 | 1069 |
resizeToMaxH := false. |
1070 |
(hL endsWith:'Max') ifTrue:[ |
|
1071 |
wEach := maxWidth := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child widthIncludingBorder]. |
|
1072 |
hL := (hL copyWithoutLast:3) asSymbol. |
|
1073 |
resizeToMaxH := true. |
|
1074 |
]. |
|
1075 |
||
118 | 1076 |
hL == #fitSpace ifTrue:[ |
59 | 1077 |
" |
1078 |
adjust childs extents and set origins. |
|
1079 |
Be careful to avoid accumulation of rounding errors |
|
1080 |
" |
|
77 | 1081 |
wEach := (wInside - (numChilds + 1 * space)) / numChilds. |
59 | 1082 |
xpos := space + margin - borderWidth. |
62 | 1083 |
] ifFalse:[ |
118 | 1084 |
hL == #fit ifTrue:[ |
77 | 1085 |
" |
1086 |
adjust childs extents and set origins. |
|
1087 |
Be careful to avoid accumulation of rounding errors |
|
1088 |
" |
|
1089 |
wEach := (wInside - (numChilds - 1 * space)) / numChilds. |
|
1090 |
xpos := margin - borderWidth. |
|
1091 |
] ifFalse:[ |
|
1092 |
" |
|
1093 |
compute net width needed |
|
1094 |
" |
|
133 | 1095 |
resizeToMaxH ifTrue:[ |
1096 |
sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + maxWidth + (child borderWidth*2)]. |
|
1097 |
] ifFalse:[ |
|
1098 |
sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child widthIncludingBorder]. |
|
1099 |
]. |
|
62 | 1100 |
|
118 | 1101 |
l := hL. |
77 | 1102 |
((l == #center) and:[numChilds == 1]) ifTrue:[ |
1103 |
l := #spread |
|
1104 |
]. |
|
1105 |
(l == #spread and:[numChilds == 1]) ifTrue:[ |
|
1106 |
l := #spreadSpace |
|
1107 |
]. |
|
0 | 1108 |
|
77 | 1109 |
" |
1110 |
compute position of leftmost subview and space between them; |
|
1111 |
if they do hardly fit, leave no space between them |
|
1112 |
" |
|
118 | 1113 |
((sumOfWidths >= (width - (margin * 2))) |
1114 |
and:[l ~~ #fixLeftSpace and:[l ~~ #fixLeft]]) ifTrue:[ |
|
77 | 1115 |
xpos := 0. |
1116 |
space := 0 |
|
1117 |
] ifFalse: [ |
|
118 | 1118 |
l == #fixLeftSpace ifTrue:[ |
1119 |
l := #leftSpace |
|
1120 |
] ifFalse:[ |
|
1121 |
l == #fixLeft ifTrue:[ |
|
1122 |
l := #left |
|
1123 |
] |
|
1124 |
]. |
|
77 | 1125 |
((l == #right) or:[l == #rightSpace]) ifTrue:[ |
1126 |
xpos := width - (space * (numChilds - 1)) - sumOfWidths. |
|
62 | 1127 |
" |
77 | 1128 |
borderWidth == 0 ifTrue:[ |
1129 |
xpos := xpos + space |
|
1130 |
]. |
|
1131 |
" |
|
1132 |
l == #rightSpace ifTrue:[ |
|
1133 |
xpos >= space ifTrue:[ |
|
1134 |
xpos := xpos - space |
|
1135 |
] |
|
1136 |
]. |
|
62 | 1137 |
|
77 | 1138 |
xpos < 0 ifTrue:[ |
1139 |
space := space min:(width - sumOfWidths) // (numChilds + 1). |
|
1140 |
xpos := width - (space * numChilds) - sumOfWidths. |
|
59 | 1141 |
] |
1142 |
] ifFalse:[ |
|
77 | 1143 |
(l == #spread) ifTrue:[ |
1144 |
space := (width - sumOfWidths) // (numChilds - 1). |
|
1145 |
xpos := 0. |
|
1146 |
(space == 0) ifTrue:[ |
|
1147 |
xpos := (width - sumOfWidths) // 2 |
|
1148 |
] |
|
1149 |
] ifFalse:[ |
|
1150 |
(l == #spreadSpace) ifTrue:[ |
|
1151 |
space := (width - sumOfWidths) // (numChilds + 1). |
|
1152 |
xpos := space. |
|
1153 |
(space == 0) ifTrue:[ |
|
1154 |
xpos := (width - sumOfWidths) // 2 |
|
62 | 1155 |
] |
77 | 1156 |
] ifFalse:[ |
1157 |
((l == #left) |
|
1158 |
or:[l == #leftSpace |
|
1159 |
or:[l == #leftFit |
|
1160 |
or:[l == #leftSpaceFit]]]) ifTrue:[ |
|
1161 |
space := space min:(width - sumOfWidths) // (numChilds + 1). |
|
118 | 1162 |
(hL == #fixLeft or:[hL == #fixLeftSpace]) ifTrue:[ |
1163 |
space := space max:horizontalSpace. |
|
1164 |
] ifFalse:[ |
|
1165 |
space := space max:0. |
|
1166 |
]. |
|
77 | 1167 |
(l == #leftSpace |
1168 |
or:[l == #leftSpaceFit]) ifTrue:[ |
|
1169 |
xpos := space. |
|
1170 |
] ifFalse:[ |
|
1171 |
xpos := 0 |
|
1172 |
] |
|
1173 |
" |
|
1174 |
borderWidth == 0 ifTrue:[ |
|
1175 |
xpos := 0 |
|
1176 |
]. |
|
1177 |
" |
|
1178 |
] ifFalse:[ |
|
1179 |
"center" |
|
62 | 1180 |
xpos := (width - (sumOfWidths |
77 | 1181 |
+ ((numChilds - 1) * space))) // 2. |
1182 |
xpos < 0 ifTrue:[ |
|
1183 |
space := (width - sumOfWidths) // (numChilds + 1). |
|
1184 |
xpos := (width - (sumOfWidths |
|
1185 |
+ ((numChilds - 1) * space))) // 2. |
|
1186 |
] |
|
62 | 1187 |
] |
77 | 1188 |
] |
62 | 1189 |
] |
59 | 1190 |
] |
77 | 1191 |
]. |
62 | 1192 |
]. |
0 | 1193 |
]. |
1194 |
||
133 | 1195 |
vL := vLayout. |
1196 |
resizeToMaxV := false. |
|
1197 |
(vLayout endsWith:'Max') ifTrue:[ |
|
1198 |
resizeToMaxV := true. |
|
1199 |
maxHeight := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child heightIncludingBorder]. |
|
1200 |
vL == #centerMax ifTrue:[vL := #center]. |
|
1201 |
vL == #bottomMax ifTrue:[vL := #bottom]. |
|
1202 |
vL == #bottomSpaceMax ifTrue:[vL := #bottomSpace]. |
|
1203 |
vL == #topMax ifTrue:[vL := #top]. |
|
1204 |
vL == #topSpaceMax ifTrue:[vL := #topSpace]. |
|
1205 |
]. |
|
1206 |
||
0 | 1207 |
"now set positions" |
1208 |
||
77 | 1209 |
subViews keysAndValuesDo:[:index :child | |
133 | 1210 |
|ypos advance bwChild hChild| |
1211 |
||
1212 |
hChild := child heightIncludingBorder. |
|
1213 |
bwChild := child borderWidth. |
|
1214 |
||
1215 |
resizeToMaxV ifTrue:[ |
|
1216 |
child height:(hChild := maxHeight - (bwChild * 2)). |
|
1217 |
]. |
|
62 | 1218 |
|
118 | 1219 |
vL == #top ifTrue:[ |
62 | 1220 |
ypos := 0 |
1221 |
] ifFalse:[ |
|
118 | 1222 |
vL == #topSpace ifTrue:[ |
62 | 1223 |
ypos := verticalSpace |
1224 |
] ifFalse:[ |
|
118 | 1225 |
vL == #bottom ifTrue:[ |
62 | 1226 |
ypos := height - child heightIncludingBorder |
1227 |
] ifFalse:[ |
|
118 | 1228 |
vL == #bottomSpace ifTrue:[ |
62 | 1229 |
ypos := height - verticalSpace - child heightIncludingBorder. |
1230 |
] ifFalse:[ |
|
118 | 1231 |
vL == #fitSpace ifTrue:[ |
62 | 1232 |
ypos := verticalSpace. |
133 | 1233 |
child height:(height - (verticalSpace + bwChild * 2)) |
62 | 1234 |
] ifFalse:[ |
118 | 1235 |
vL == #fit ifTrue:[ |
77 | 1236 |
ypos := 0. |
133 | 1237 |
child height:(height - (bwChild * 2)) |
77 | 1238 |
] ifFalse:[ |
1239 |
"centered" |
|
1240 |
ypos := (height - child heightIncludingBorder) // 2. |
|
1241 |
] |
|
62 | 1242 |
] |
1243 |
] |
|
1244 |
] |
|
1245 |
] |
|
1246 |
]. |
|
59 | 1247 |
(ypos < 0) ifTrue:[ypos := 0]. |
0 | 1248 |
|
133 | 1249 |
(hL == #fit |
1250 |
or:[hL == #fitSpace |
|
1251 |
or:[resizeToMaxH]]) ifTrue:[ |
|
162 | 1252 |
child sizeFixed ifTrue:[ |
1253 |
d := wEach - (child widthIncludingBorder) // 2. |
|
1254 |
child origin:(xpos truncated + d @ ypos) |
|
1255 |
] ifFalse:[ |
|
1256 |
child origin:(xpos truncated @ ypos) |
|
1257 |
corner:(xpos + wEach - (child borderWidth) - 1) truncated |
|
1258 |
@ (ypos + child height - 1). |
|
1259 |
]. |
|
77 | 1260 |
advance := wEach. |
62 | 1261 |
] ifFalse:[ |
1262 |
child origin:(xpos @ ypos). |
|
77 | 1263 |
advance := child widthIncludingBorder |
1264 |
]. |
|
1265 |
xpos := xpos + advance + space. |
|
1266 |
||
1267 |
index == numChilds ifTrue:[ |
|
1268 |
|x| |
|
1269 |
||
118 | 1270 |
hL == #leftFit ifTrue:[ |
155 | 1271 |
x := width - margin - 1. |
77 | 1272 |
]. |
118 | 1273 |
hL == #leftSpaceFit ifTrue:[ |
155 | 1274 |
x := width - margin - 1 - space |
77 | 1275 |
]. |
1276 |
x notNil ifTrue:[ |
|
155 | 1277 |
subViews last corner:(x @ (ypos + child height - 1)) |
77 | 1278 |
] |
62 | 1279 |
] |
77 | 1280 |
]. |
155 | 1281 |
|
1282 |
"Modified: 4.9.1995 / 18:43:10 / claus" |
|
0 | 1283 |
! ! |