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