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