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