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:#VerticalPanelView
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Layout'
|
|
18 |
!
|
|
19 |
|
|
20 |
VerticalPanelView comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
59
|
24 |
$Header: /cvs/stx/stx/libwidg/VerticalPanelView.st,v 1.5 1994-10-10 03:03:18 claus Exp $
|
38
|
25 |
'!
|
|
26 |
|
|
27 |
!VerticalPanelView 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 |
"
|
59
|
45 |
$Header: /cvs/stx/stx/libwidg/VerticalPanelView.st,v 1.5 1994-10-10 03:03:18 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
a View which arranges its child-views in a vertical column.
|
|
52 |
All real work is done in PanelView - only the layout computation is
|
|
53 |
redefined here.
|
|
54 |
|
|
55 |
example: default layout (centered)
|
|
56 |
|
59
|
57 |
|v p b1 b2 b3|
|
38
|
58 |
|
59
|
59 |
v := StandardSystemView new.
|
|
60 |
p := VerticalPanelView in:v.
|
|
61 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
62 |
b1 := Button label:'button1' in:p.
|
|
63 |
b2 := Button label:'button2' in:p.
|
|
64 |
b3 := Button label:'button3' in:p.
|
|
65 |
v extent:100 @ 300.
|
|
66 |
v open
|
38
|
67 |
|
0
|
68 |
|
38
|
69 |
example: left-layout
|
|
70 |
|
59
|
71 |
|v p b1 b2 b3|
|
38
|
72 |
|
59
|
73 |
v := StandardSystemView new.
|
|
74 |
p := VerticalPanelView in:v.
|
|
75 |
p layout:#top.
|
|
76 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
77 |
b1 := Button label:'button1' in:p.
|
|
78 |
b2 := Button label:'button2' in:p.
|
|
79 |
b3 := Button label:'button3' in:p.
|
|
80 |
v extent:100 @ 300.
|
|
81 |
v open
|
38
|
82 |
|
|
83 |
|
|
84 |
example: right-layout
|
|
85 |
|
59
|
86 |
|v p b1 b2 b3|
|
0
|
87 |
|
59
|
88 |
v := StandardSystemView new.
|
|
89 |
p := VerticalPanelView in:v.
|
|
90 |
p layout:#bottom.
|
|
91 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
92 |
b1 := Button label:'button1' in:p.
|
|
93 |
b2 := Button label:'button2' in:p.
|
|
94 |
b3 := Button label:'button3' in:p.
|
|
95 |
v extent:100 @ 300.
|
|
96 |
v open
|
38
|
97 |
|
|
98 |
|
|
99 |
example: spread-layout
|
|
100 |
|
59
|
101 |
|v p b1 b2 b3|
|
38
|
102 |
|
59
|
103 |
v := StandardSystemView new.
|
|
104 |
p := VerticalPanelView in:v.
|
|
105 |
p layout:#spread.
|
|
106 |
p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
|
|
107 |
b1 := Button label:'button1' in:p.
|
|
108 |
b2 := Button label:'button2' in:p.
|
|
109 |
b3 := Button label:'button3' in:p.
|
|
110 |
v extent:100 @ 300.
|
|
111 |
v open
|
38
|
112 |
"
|
|
113 |
! !
|
0
|
114 |
|
|
115 |
!VerticalPanelView methodsFor:'queries'!
|
|
116 |
|
|
117 |
preferedExtent
|
|
118 |
"return a good extent, one that makes subviews fit"
|
|
119 |
|
59
|
120 |
|sumOfHeights maxWidth maxHeight|
|
0
|
121 |
|
|
122 |
subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace].
|
|
123 |
|
|
124 |
"compute net height needed"
|
|
125 |
|
|
126 |
sumOfHeights := 0.
|
|
127 |
maxWidth := 0.
|
|
128 |
|
|
129 |
subViews do:[:child |
|
59
|
130 |
sumOfHeights := sumOfHeights + child heightIncludingBorder.
|
|
131 |
maxWidth := maxWidth max:(child widthIncludingBorder).
|
|
132 |
maxHeight := maxHeight max:(child heightIncludingBorder).
|
0
|
133 |
].
|
|
134 |
borderWidth ~~ 0 ifTrue:[
|
59
|
135 |
sumOfHeights := sumOfHeights + (horizontalSpace * 2).
|
|
136 |
maxWidth := maxWidth + (horizontalSpace * 2).
|
0
|
137 |
].
|
|
138 |
sumOfHeights := sumOfHeights + ((subViews size - 1) * verticalSpace).
|
|
139 |
|
|
140 |
^ maxWidth @ sumOfHeights
|
|
141 |
! !
|
|
142 |
|
|
143 |
!VerticalPanelView methodsFor:'layout'!
|
|
144 |
|
|
145 |
setChildPositions
|
|
146 |
"(re)compute position of every child"
|
|
147 |
|
59
|
148 |
|xpos ypos space sumOfHeights numChilds l hEach|
|
0
|
149 |
|
|
150 |
subViews isNil ifTrue:[^ self].
|
|
151 |
|
|
152 |
space := verticalSpace.
|
|
153 |
|
59
|
154 |
numChilds := subViews size.
|
|
155 |
layout == #fit ifTrue:[
|
|
156 |
"
|
|
157 |
adjust childs extents and set origins.
|
|
158 |
Be careful to avoid accumulation of rounding errors
|
|
159 |
"
|
|
160 |
hEach := (height - (margin * 2) - (numChilds + 1 * space) + borderWidth) / numChilds.
|
|
161 |
ypos := space + margin - borderWidth.
|
|
162 |
subViews do:[:child |
|
|
163 |
xpos := (width - child widthIncludingBorder) // 2.
|
|
164 |
(xpos < 0) ifTrue:[xpos := 0].
|
|
165 |
|
|
166 |
child origin:(xpos @ ypos rounded)
|
|
167 |
corner:(xpos + (child width))
|
|
168 |
@ (ypos + hEach - (child borderWidth)) rounded.
|
|
169 |
ypos := ypos + hEach + "(child borderWidth * 2) +" space
|
|
170 |
].
|
|
171 |
^ self
|
|
172 |
].
|
|
173 |
|
0
|
174 |
"compute net height needed"
|
|
175 |
|
38
|
176 |
sumOfHeights := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child heightIncludingBorder].
|
0
|
177 |
|
|
178 |
l := layout.
|
|
179 |
((l == #center) and:[numChilds == 1]) ifTrue:[
|
59
|
180 |
l := #spread
|
0
|
181 |
].
|
|
182 |
|
|
183 |
"compute position of topmost subview and space between them;
|
|
184 |
if they do hardly fit, leave no space between them "
|
|
185 |
|
38
|
186 |
(sumOfHeights >= (height - (margin * 2))) ifTrue:[
|
59
|
187 |
ypos := 0.
|
|
188 |
space := 0
|
0
|
189 |
] ifFalse:[
|
59
|
190 |
(l == #bottom) ifTrue:[
|
|
191 |
ypos := height - (space * numChilds) - sumOfHeights.
|
38
|
192 |
"
|
59
|
193 |
borderWidth == 0 ifTrue:[
|
|
194 |
ypos := ypos + space
|
|
195 |
].
|
38
|
196 |
"
|
59
|
197 |
ypos < 0 ifTrue:[
|
|
198 |
space := space min:(height - sumOfHeights) // (numChilds + 1).
|
|
199 |
ypos := height - (space * numChilds) - sumOfHeights.
|
|
200 |
]
|
|
201 |
] ifFalse: [
|
|
202 |
(l == #spread) ifTrue:[
|
|
203 |
space := (height - sumOfHeights) // (numChilds + 1).
|
|
204 |
ypos := space.
|
|
205 |
(space == 0) ifTrue:[
|
|
206 |
ypos := (height - sumOfHeights) // 2
|
|
207 |
]
|
|
208 |
] ifFalse: [
|
|
209 |
(l == #center) ifTrue:[
|
|
210 |
ypos := (height - (sumOfHeights
|
|
211 |
+ ((numChilds - 1) * space))) // 2.
|
|
212 |
ypos < 0 ifTrue:[
|
|
213 |
space := (height - sumOfHeights) // (numChilds + 1).
|
|
214 |
ypos := (height - (sumOfHeights
|
|
215 |
+ ((numChilds - 1) * space))) // 2.
|
|
216 |
]
|
|
217 |
] ifFalse:[
|
38
|
218 |
"
|
59
|
219 |
borderWidth == 0 ifTrue:[
|
|
220 |
ypos := 0
|
|
221 |
] ifFalse:[
|
|
222 |
ypos := verticalSpace
|
|
223 |
].
|
38
|
224 |
"
|
59
|
225 |
space := space min:(height - sumOfHeights) // (numChilds + 1).
|
|
226 |
ypos := space.
|
|
227 |
]
|
|
228 |
]
|
|
229 |
]
|
0
|
230 |
].
|
|
231 |
|
38
|
232 |
|
0
|
233 |
"now set positions"
|
|
234 |
|
|
235 |
subViews do:[:childView |
|
59
|
236 |
xpos := (width - childView widthIncludingBorder) // 2.
|
|
237 |
(xpos < 0) ifTrue:[ xpos := 0 ].
|
0
|
238 |
|
59
|
239 |
childView origin:(xpos@ypos).
|
|
240 |
ypos := ypos + (childView heightIncludingBorder) + space
|
0
|
241 |
]
|
|
242 |
! !
|