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 |
|
59
|
24 |
$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.5 1994-10-10 03:01:39 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 |
"
|
59
|
45 |
$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.5 1994-10-10 03:01:39 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 |
|
|
55 |
example: default layout (centered)
|
|
56 |
|
59
|
57 |
|v p b1 b2 b3|
|
38
|
58 |
|
59
|
59 |
v := StandardSystemView new.
|
|
60 |
p := HorizontalPanelView 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:300 @ 100.
|
|
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 := HorizontalPanelView in:v.
|
|
75 |
p layout:#left.
|
|
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:300 @ 100.
|
|
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 := HorizontalPanelView in:v.
|
|
90 |
p layout:#right.
|
|
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:300 @ 100.
|
|
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 := HorizontalPanelView 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:300 @ 100.
|
|
111 |
v open
|
38
|
112 |
"
|
|
113 |
! !
|
0
|
114 |
|
|
115 |
!HorizontalPanelView methodsFor:'queries'!
|
|
116 |
|
|
117 |
preferedExtent
|
|
118 |
"return a good extent, one that makes subviews fit"
|
|
119 |
|
59
|
120 |
|sumOfWidths maxHeight maxWidth|
|
0
|
121 |
|
|
122 |
subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace].
|
|
123 |
|
|
124 |
"compute net height needed"
|
|
125 |
|
|
126 |
sumOfWidths := 0.
|
|
127 |
maxHeight := 0.
|
59
|
128 |
maxWidth := 0.
|
0
|
129 |
|
|
130 |
subViews do:[:child |
|
59
|
131 |
sumOfWidths := sumOfWidths + child widthIncludingBorder.
|
|
132 |
maxHeight := maxHeight max:(child heightIncludingBorder).
|
|
133 |
maxWidth := maxWidth max:(child widthIncludingBorder).
|
0
|
134 |
].
|
|
135 |
borderWidth ~~ 0 ifTrue:[
|
59
|
136 |
sumOfWidths := sumOfWidths + (horizontalSpace * 2).
|
|
137 |
maxHeight := maxHeight + (verticalSpace * 2).
|
0
|
138 |
].
|
59
|
139 |
layout == #fit ifTrue:[
|
|
140 |
sumOfWidths := maxWidth * subViews size.
|
|
141 |
borderWidth ~~ 0 ifTrue:[
|
|
142 |
sumOfWidths := sumOfWidths + (verticalSpace * 2).
|
|
143 |
]
|
|
144 |
] ifFalse:[
|
|
145 |
sumOfWidths := sumOfWidths + ((subViews size - 1) * horizontalSpace).
|
|
146 |
].
|
0
|
147 |
|
|
148 |
^ sumOfWidths @ maxHeight
|
|
149 |
! !
|
|
150 |
|
|
151 |
!HorizontalPanelView methodsFor:'layout'!
|
|
152 |
|
|
153 |
setChildPositions
|
|
154 |
"(re)compute position of every child whenever childs are added or
|
|
155 |
my size has changed"
|
|
156 |
|
59
|
157 |
|xpos ypos space sumOfWidths numChilds l wEach|
|
0
|
158 |
|
|
159 |
subViews isNil ifTrue:[^ self].
|
|
160 |
|
|
161 |
space := horizontalSpace.
|
59
|
162 |
numChilds := subViews size.
|
|
163 |
|
|
164 |
layout == #fit ifTrue:[
|
|
165 |
"
|
|
166 |
adjust childs extents and set origins.
|
|
167 |
Be careful to avoid accumulation of rounding errors
|
|
168 |
"
|
|
169 |
wEach := (width - (margin * 2) - (numChilds + 1 * space) + borderWidth) / numChilds.
|
|
170 |
xpos := space + margin - borderWidth.
|
|
171 |
subViews do:[:child |
|
|
172 |
ypos := (height - child heightIncludingBorder) // 2.
|
|
173 |
(ypos < 0) ifTrue:[ypos := 0].
|
|
174 |
|
|
175 |
child origin:(xpos rounded @ ypos)
|
|
176 |
corner:(xpos + wEach - (child borderWidth)) rounded
|
|
177 |
@ (ypos + child height).
|
|
178 |
xpos := xpos + wEach + space
|
|
179 |
].
|
|
180 |
^ self
|
|
181 |
].
|
0
|
182 |
|
|
183 |
"compute net width needed"
|
|
184 |
|
38
|
185 |
sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child widthIncludingBorder].
|
0
|
186 |
|
|
187 |
l := layout.
|
|
188 |
((l == #center) and:[numChilds == 1]) ifTrue:[
|
59
|
189 |
l := #spread
|
0
|
190 |
].
|
|
191 |
|
59
|
192 |
"
|
|
193 |
compute position of leftmost subview and space between them;
|
|
194 |
if they do hardly fit, leave no space between them
|
|
195 |
"
|
38
|
196 |
(sumOfWidths >= (width - (margin * 2))) ifTrue:[
|
59
|
197 |
xpos := 0.
|
|
198 |
space := 0
|
0
|
199 |
] ifFalse: [
|
59
|
200 |
(l == #right) ifTrue:[
|
|
201 |
xpos := width - (space * numChilds) - sumOfWidths.
|
38
|
202 |
"
|
59
|
203 |
borderWidth == 0 ifTrue:[
|
|
204 |
xpos := xpos + space
|
|
205 |
].
|
38
|
206 |
"
|
59
|
207 |
xpos < 0 ifTrue:[
|
|
208 |
space := space min:(width - sumOfWidths) // (numChilds + 1).
|
|
209 |
xpos := width - (space * numChilds) - sumOfWidths.
|
|
210 |
]
|
|
211 |
] ifFalse:[
|
|
212 |
(l == #spread) ifTrue:[
|
|
213 |
space := (width - sumOfWidths) // (numChilds + 1).
|
|
214 |
xpos := space.
|
|
215 |
(space == 0) ifTrue:[
|
|
216 |
xpos := (width - sumOfWidths) // 2
|
|
217 |
]
|
|
218 |
] ifFalse:[
|
|
219 |
(l == #center) ifTrue:[
|
|
220 |
xpos := (width - (sumOfWidths
|
|
221 |
+ ((numChilds - 1) * space))) // 2.
|
|
222 |
xpos < 0 ifTrue:[
|
|
223 |
space := (width - sumOfWidths) // (numChilds + 1).
|
|
224 |
xpos := (width - (sumOfWidths
|
|
225 |
+ ((numChilds - 1) * space))) // 2.
|
|
226 |
]
|
|
227 |
] ifFalse:[
|
|
228 |
"left"
|
|
229 |
space := space min:(width - sumOfWidths) // (numChilds + 1).
|
|
230 |
xpos := space.
|
38
|
231 |
"
|
59
|
232 |
borderWidth == 0 ifTrue:[
|
|
233 |
xpos := 0
|
|
234 |
].
|
38
|
235 |
"
|
59
|
236 |
]
|
|
237 |
]
|
|
238 |
]
|
0
|
239 |
].
|
|
240 |
|
|
241 |
"now set positions"
|
|
242 |
|
|
243 |
subViews do:[:child |
|
59
|
244 |
ypos := (height - child heightIncludingBorder) // 2.
|
|
245 |
(ypos < 0) ifTrue:[ypos := 0].
|
0
|
246 |
|
59
|
247 |
child origin:(xpos @ ypos).
|
|
248 |
xpos := xpos + (child widthIncludingBorder) + space
|
0
|
249 |
]
|
|
250 |
! !
|