author | Claus Gittinger <cg@exept.de> |
Sat, 08 Aug 1998 13:42:06 +0200 | |
changeset 1035 | 308004d24f3d |
parent 949 | 0eb888b21192 |
child 1039 | 4095e7721dad |
permissions | -rw-r--r-- |
88 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
93 | 3 |
All Rights Reserved |
88 | 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 |
||
77 | 13 |
LayoutOrigin subclass:#LayoutFrame |
191 | 14 |
instanceVariableNames:'rightFraction bottomFraction rightOffset bottomOffset' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Geometry' |
|
77 | 18 |
! |
19 |
||
88 | 20 |
!LayoutFrame class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
93 | 25 |
All Rights Reserved |
88 | 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 |
||
93 | 36 |
documentation |
37 |
" |
|
38 |
This class is provided to make porting of existing ST-80 applications |
|
39 |
easier. Instances can be used to control the geometry of a subview, within |
|
40 |
its superview. Like a layoutOrigin, it controls the origin of a component |
|
41 |
by given fraction and offset dimensions; in addition, the bottom-right |
|
42 |
corner is also controlled by corresponding values. Therefore, the components |
|
43 |
preferredExtent is ignored. |
|
44 |
||
45 |
See also: |
|
219 | 46 |
LayoutOrigin AlignmentOrigin Layout |
93 | 47 |
|
229 | 48 |
Notice: |
49 |
this class was implemented using protocol information |
|
50 |
from alpha testers - it may not be complete or compatible to |
|
51 |
the corresponding ST-80 class. |
|
52 |
If you encounter any incompatibilities, please forward a note |
|
53 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
219 | 54 |
|
55 |
[author:] |
|
56 |
Claus Gittinger |
|
229 | 57 |
|
58 |
[see also:] |
|
59 |
View |
|
60 |
LayoutOrigin AlignmentOrigin Layout |
|
61 |
Rectangle Point |
|
94 | 62 |
" |
93 | 63 |
! |
64 |
||
65 |
examples |
|
66 |
" |
|
229 | 67 |
Although the examples below use a button as component, |
68 |
they work of course with any type of subview .... |
|
69 |
||
93 | 70 |
|
229 | 71 |
arrange for the button to be in 0.25 @ 0.25 -> 0.75 @ 0.75. |
72 |
This is the same as with relative origin/corner. |
|
73 |
[exBegin] |
|
74 |
|top button| |
|
93 | 75 |
|
229 | 76 |
top := StandardSystemView new. |
77 |
top extent:300@300. |
|
93 | 78 |
|
229 | 79 |
button := Button label:'component'. |
80 |
top add:button in:(LayoutFrame new |
|
81 |
leftFraction:0.25; |
|
82 |
topFraction:0.25; |
|
83 |
rightFraction:0.75; |
|
84 |
bottomFraction:0.75). |
|
85 |
||
86 |
top open |
|
87 |
[exEnd] |
|
93 | 88 |
|
89 |
||
90 |
like above, but adds additional offset to the origin: |
|
229 | 91 |
This is the same as with relative origin/corner |
92 |
and setting left & right insets. |
|
93 |
[exBegin] |
|
94 |
|top button| |
|
93 | 95 |
|
229 | 96 |
top := StandardSystemView new. |
97 |
top extent:300@300. |
|
93 | 98 |
|
229 | 99 |
button := Button label:'component'. |
100 |
top add:button in:(LayoutFrame new |
|
101 |
leftFraction:0.25; leftOffset:10; |
|
102 |
topFraction:0.25; topOffset:-20; |
|
103 |
rightFraction:0.75; |
|
104 |
bottomFraction:0.75). |
|
93 | 105 |
|
229 | 106 |
top open |
107 |
[exEnd] |
|
93 | 108 |
|
109 |
||
229 | 110 |
like above, with offsets on all edges, |
111 |
actually simulating a constant inset on all four edges: |
|
112 |
[exBegin] |
|
113 |
|top button| |
|
93 | 114 |
|
229 | 115 |
top := StandardSystemView new. |
116 |
top extent:300@300. |
|
93 | 117 |
|
229 | 118 |
button := Button label:'component'. |
119 |
top add:button in:(LayoutFrame new |
|
120 |
leftFraction:0.0; leftOffset:10; |
|
121 |
topFraction:0.0; topOffset:10; |
|
122 |
rightFraction:1.0; rightOffset:-10; |
|
123 |
bottomFraction:1.0; bottomOffset:-10). |
|
93 | 124 |
|
229 | 125 |
top open |
126 |
[exEnd] |
|
93 | 127 |
" |
88 | 128 |
! ! |
129 |
||
426 | 130 |
!LayoutFrame class methodsFor:'instance creation'! |
131 |
||
132 |
leftFraction:lF offset:lO rightFraction:rF offset:rO topFraction:tF offset:tO bottomFraction:bF offset:bO |
|
133 |
"create a new layoutFrame" |
|
134 |
||
135 |
^ self new |
|
136 |
leftFraction:lF offset:lO |
|
137 |
rightFraction:rF offset:rO |
|
138 |
topFraction:tF offset:tO |
|
139 |
bottomFraction:bF offset:bO |
|
140 |
||
141 |
||
142 |
||
545
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
143 |
! |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
144 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
145 |
leftOffset:lO rightOffset:rO topOffset:tO bottomOffset:bO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
146 |
"create a new layoutFrame" |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
147 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
148 |
^ self new |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
149 |
leftOffset:lO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
150 |
rightOffset:rO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
151 |
topOffset:tO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
152 |
bottomOffset:bO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
153 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
154 |
"Created: 18.4.1997 / 20:14:44 / cg" |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
155 |
! |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
156 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
157 |
leftOffset:lO topOffset:tO rightOffset:rO bottomOffset:bO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
158 |
"create a new layoutFrame" |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
159 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
160 |
^ self leftOffset:lO rightOffset:rO topOffset:tO bottomOffset:bO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
161 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
162 |
"Modified: 18.4.1997 / 20:15:23 / cg" |
426 | 163 |
! ! |
164 |
||
77 | 165 |
!LayoutFrame methodsFor:'accessing'! |
166 |
||
126 | 167 |
bottomFraction |
168 |
"return bottomFraction" |
|
169 |
||
170 |
^ bottomFraction |
|
171 |
! |
|
172 |
||
173 |
bottomFraction:something |
|
174 |
"set bottomFraction" |
|
175 |
||
176 |
bottomFraction := something. |
|
177 |
! |
|
178 |
||
179 |
bottomFraction:something offset:o |
|
180 |
"set bottomFraction and offset" |
|
77 | 181 |
|
126 | 182 |
bottomFraction := something. |
183 |
bottomOffset := o |
|
184 |
! |
|
185 |
||
275 | 186 |
bottomInset:pixels |
187 |
"set bottomOffset for an inset at the bottom" |
|
188 |
||
189 |
bottomOffset := pixels negated. |
|
190 |
||
191 |
"Created: 26.5.1996 / 17:38:30 / cg" |
|
192 |
! |
|
193 |
||
126 | 194 |
bottomOffset |
195 |
"return bottomOffset" |
|
196 |
||
197 |
^ bottomOffset |
|
198 |
! |
|
199 |
||
200 |
bottomOffset:something |
|
201 |
"set bottomOffset" |
|
202 |
||
203 |
bottomOffset := something. |
|
77 | 204 |
! |
205 |
||
275 | 206 |
horizontalInset:aNumber |
207 |
"setup the offsets for insetting horizontally the frame aNumber pixels |
|
208 |
at all sides" |
|
209 |
||
210 |
leftOffset := aNumber. |
|
211 |
rightOffset := aNumber negated. |
|
212 |
||
213 |
"Created: 26.5.1996 / 17:39:35 / cg" |
|
214 |
! |
|
215 |
||
216 |
inset:aNumber |
|
217 |
"setup the offsets for insetting the frame aNumber pixels |
|
218 |
at all sides" |
|
219 |
||
220 |
topOffset := leftOffset := aNumber. |
|
221 |
rightOffset := bottomOffset := aNumber negated. |
|
222 |
||
223 |
"Created: 26.5.1996 / 17:36:49 / cg" |
|
224 |
! |
|
225 |
||
425 | 226 |
leftFraction:lF offset:lO rightFraction:rF offset:rO topFraction:tF offset:tO bottomFraction:bF offset:bO |
227 |
"set all fields" |
|
228 |
||
229 |
leftFraction := lF. |
|
230 |
rightFraction := rF. |
|
231 |
topFraction := tF. |
|
232 |
bottomFraction := bF. |
|
233 |
leftOffset := lO. |
|
234 |
rightOffset := rO. |
|
235 |
topOffset := tO. |
|
236 |
bottomOffset := bO. |
|
237 |
||
238 |
! |
|
239 |
||
545
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
240 |
leftOffset:lO rightOffset:rO topOffset:tO bottomOffset:bO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
241 |
"set all offset fields" |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
242 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
243 |
leftOffset := lO. |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
244 |
rightOffset := rO. |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
245 |
topOffset := tO. |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
246 |
bottomOffset := bO. |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
247 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
248 |
"Created: 18.4.1997 / 20:16:08 / cg" |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
249 |
! |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
250 |
|
77 | 251 |
rightFraction |
252 |
"return rightFraction" |
|
253 |
||
254 |
^ rightFraction |
|
255 |
! |
|
256 |
||
126 | 257 |
rightFraction:something |
258 |
"set rightFraction" |
|
77 | 259 |
|
126 | 260 |
rightFraction := something. |
77 | 261 |
! |
262 |
||
263 |
rightFraction:something offset:o |
|
264 |
"set rightFraction and offset" |
|
265 |
||
266 |
rightFraction := something. |
|
267 |
rightOffset := o |
|
268 |
! |
|
269 |
||
275 | 270 |
rightInset:pixels |
271 |
"set rightOffset for an inset at the right" |
|
272 |
||
273 |
rightOffset := pixels negated. |
|
274 |
||
275 |
"Created: 26.5.1996 / 17:38:38 / cg" |
|
276 |
! |
|
277 |
||
126 | 278 |
rightOffset |
279 |
"return rightOffset" |
|
77 | 280 |
|
126 | 281 |
^ rightOffset |
77 | 282 |
! |
283 |
||
126 | 284 |
rightOffset:something |
285 |
"set rightOffset" |
|
286 |
||
287 |
rightOffset := something. |
|
275 | 288 |
! |
289 |
||
290 |
verticalInset:aNumber |
|
291 |
"setup the offsets for insetting vertically the frame aNumber pixels |
|
292 |
at all sides" |
|
293 |
||
294 |
topOffset := aNumber. |
|
295 |
bottomOffset := aNumber negated. |
|
296 |
||
297 |
"Created: 26.5.1996 / 17:39:50 / cg" |
|
126 | 298 |
! ! |
299 |
||
300 |
!LayoutFrame methodsFor:'converting'! |
|
301 |
||
302 |
fromLiteralArrayEncoding:encoding |
|
303 |
"read my values from an encoding. |
|
304 |
The encoding is supposed to be of the form: |
|
305 |
(LayoutFrame orgOffsX relOrgX orgOffsY relOrgY cornOffsX relCornX cornOffsY relCornY) |
|
306 |
This is the reverse to literalArrayEncoding." |
|
77 | 307 |
|
126 | 308 |
leftOffset := encoding at:2. |
309 |
leftFraction := encoding at:3. |
|
310 |
topOffset := encoding at:4. |
|
311 |
topFraction := encoding at:5. |
|
312 |
rightOffset := encoding at:6. |
|
313 |
rightFraction := encoding at:7. |
|
314 |
bottomOffset := encoding at:8. |
|
315 |
bottomFraction := encoding at:9. |
|
316 |
||
317 |
" |
|
318 |
LayoutFrame new fromLiteralArrayEncoding:#(#LayoutFrame 70 0 2 0 0 1 25 0 ) |
|
319 |
#(#LayoutFrame 70 0 2 0 0 1 25 0 ) decodeAsLiteralArray |
|
320 |
" |
|
77 | 321 |
! |
322 |
||
126 | 323 |
literalArrayEncoding |
191 | 324 |
"encode myself as an array, from which a copy of the receiver |
325 |
can be reconstructed with #decodeAsLiteralArray. |
|
126 | 326 |
The encoding is: |
191 | 327 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY cornOffsX relCornX cornOffsY relCornY)" |
77 | 328 |
|
126 | 329 |
^ super literalArrayEncoding |
330 |
, (Array |
|
191 | 331 |
with:rightOffset |
332 |
with:rightFraction |
|
333 |
with:bottomOffset |
|
334 |
with:bottomFraction) |
|
77 | 335 |
|
126 | 336 |
"Modified: 1.9.1995 / 02:43:35 / claus" |
191 | 337 |
"Modified: 22.4.1996 / 13:00:17 / cg" |
77 | 338 |
! ! |
339 |
||
126 | 340 |
!LayoutFrame methodsFor:'initialization'! |
341 |
||
342 |
initialize |
|
343 |
leftOffset := rightOffset := bottomOffset := topOffset := 0. |
|
344 |
leftFraction := topFraction := 0. |
|
468 | 345 |
"/ bottomFraction := rightFraction := 1. |
346 |
bottomFraction := rightFraction := 0. |
|
347 |
||
348 |
"Modified: 1.3.1997 / 16:12:50 / cg" |
|
126 | 349 |
! ! |
77 | 350 |
|
83 | 351 |
!LayoutFrame methodsFor:'printing & storing'! |
352 |
||
353 |
displayString |
|
700 | 354 |
"return a printed representation of the receiver for displaying" |
355 |
||
83 | 356 |
^ (self class name) , '(' |
700 | 357 |
, 'l: ' , leftFraction displayString |
358 |
, '+' , leftOffset displayString |
|
359 |
, ' t: ' , topFraction displayString |
|
360 |
, '+' , topOffset displayString |
|
361 |
, ' r: ' , rightFraction displayString |
|
362 |
, '+' , rightOffset displayString |
|
363 |
, ' b: ' , bottomFraction displayString |
|
364 |
, '+' , bottomOffset displayString |
|
365 |
, ')' |
|
366 |
||
367 |
"Modified: 20.9.1997 / 11:40:14 / cg" |
|
83 | 368 |
! ! |
369 |
||
77 | 370 |
!LayoutFrame methodsFor:'queries'! |
371 |
||
126 | 372 |
corner |
373 |
^ rightFraction asFloat @ bottomFraction asFloat |
|
374 |
! |
|
375 |
||
416 | 376 |
isLayoutFrame |
377 |
"return true, if this is a layoutFrame" |
|
378 |
||
379 |
^ true |
|
380 |
||
381 |
||
382 |
! |
|
383 |
||
949
0eb888b21192
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
384 |
rectangleRelativeTo:superRectangle preferred:prefRectHolder |
229 | 385 |
"compute the rectangle represented by the receiver, |
386 |
given the superViews rectangle and the views preferredExtent." |
|
387 |
||
498 | 388 |
|x1 y1 x2 y2 superWidth superHeight| |
77 | 389 |
|
390 |
leftOffset isNil ifTrue:[ |
|
229 | 391 |
x1 := 0 |
77 | 392 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
393 |
x1 := leftOffset value |
77 | 394 |
]. |
395 |
topOffset isNil ifTrue:[ |
|
229 | 396 |
y1 := 0 |
77 | 397 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
398 |
y1 := topOffset value |
77 | 399 |
]. |
400 |
rightOffset isNil ifTrue:[ |
|
229 | 401 |
x2 := 0 |
77 | 402 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
403 |
x2 := rightOffset value |
77 | 404 |
]. |
405 |
bottomOffset isNil ifTrue:[ |
|
229 | 406 |
y2 := 0 |
77 | 407 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
408 |
y2 := bottomOffset value |
77 | 409 |
]. |
498 | 410 |
|
77 | 411 |
leftFraction notNil ifTrue:[ |
498 | 412 |
superWidth := superRectangle width. |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
413 |
x1 := x1 + (superWidth * leftFraction value) |
77 | 414 |
]. |
415 |
topFraction notNil ifTrue:[ |
|
498 | 416 |
superHeight := superRectangle height. |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
417 |
y1 := y1 + (superHeight * topFraction value) |
77 | 418 |
]. |
419 |
rightFraction notNil ifTrue:[ |
|
498 | 420 |
superWidth isNil ifTrue:[superWidth := superRectangle width]. |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
421 |
x2 := x2 + (superWidth * rightFraction value) |
77 | 422 |
]. |
423 |
bottomFraction notNil ifTrue:[ |
|
498 | 424 |
superHeight isNil ifTrue:[superHeight := superRectangle height]. |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
425 |
y2 := y2 + (superHeight * bottomFraction value) |
77 | 426 |
]. |
242 | 427 |
^ Rectangle left:x1 top:y1 right:x2 bottom:y2 |
83 | 428 |
|
429 |
" |
|
430 |
|superRect lF| |
|
431 |
||
498 | 432 |
superRect := 0@0 corner:99@99. |
83 | 433 |
lF := (LayoutFrame new). |
434 |
lF leftFraction:0.25; |
|
229 | 435 |
topFraction:0.25; |
436 |
rightFraction:0.75; |
|
437 |
bottomFraction:0.75. |
|
83 | 438 |
lF rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
439 |
" |
|
229 | 440 |
|
949
0eb888b21192
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
441 |
"Created: / 6.3.1997 / 21:07:51 / cg" |
0eb888b21192
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
442 |
"Modified: / 27.5.1998 / 10:19:18 / cg" |
77 | 443 |
! ! |
100 | 444 |
|
126 | 445 |
!LayoutFrame class methodsFor:'documentation'! |
100 | 446 |
|
126 | 447 |
version |
949
0eb888b21192
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
448 |
^ '$Header: /cvs/stx/stx/libview2/LayoutFrame.st,v 1.24 1998-05-27 09:21:30 cg Exp $' |
100 | 449 |
! ! |