author | tz |
Sat, 07 Feb 1998 16:57:39 +0100 | |
changeset 834 | ac1655bd31bb |
parent 700 | 67f1dccb8333 |
child 949 | 0eb888b21192 |
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 |
||
700 | 13 |
'From Smalltalk/X, Version:3.1.10 on 20-sep-1997 at 12:00:17 am' ! |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
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 |
||
545
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
242 |
leftOffset:lO rightOffset:rO topOffset:tO bottomOffset:bO |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
243 |
"set all offset fields" |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
244 |
|
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
245 |
leftOffset := lO. |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
246 |
rightOffset := rO. |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
247 |
topOffset := tO. |
0b9d704baeae
more access & inst-creation methods
Claus Gittinger <cg@exept.de>
parents:
498
diff
changeset
|
248 |
bottomOffset := bO. |
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 |
"Created: 18.4.1997 / 20:16:08 / cg" |
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 |
|
77 | 253 |
rightFraction |
254 |
"return rightFraction" |
|
255 |
||
256 |
^ rightFraction |
|
257 |
! |
|
258 |
||
126 | 259 |
rightFraction:something |
260 |
"set rightFraction" |
|
77 | 261 |
|
126 | 262 |
rightFraction := something. |
77 | 263 |
! |
264 |
||
265 |
rightFraction:something offset:o |
|
266 |
"set rightFraction and offset" |
|
267 |
||
268 |
rightFraction := something. |
|
269 |
rightOffset := o |
|
270 |
! |
|
271 |
||
275 | 272 |
rightInset:pixels |
273 |
"set rightOffset for an inset at the right" |
|
274 |
||
275 |
rightOffset := pixels negated. |
|
276 |
||
277 |
"Created: 26.5.1996 / 17:38:38 / cg" |
|
278 |
! |
|
279 |
||
126 | 280 |
rightOffset |
281 |
"return rightOffset" |
|
77 | 282 |
|
126 | 283 |
^ rightOffset |
77 | 284 |
! |
285 |
||
126 | 286 |
rightOffset:something |
287 |
"set rightOffset" |
|
288 |
||
289 |
rightOffset := something. |
|
275 | 290 |
! |
291 |
||
292 |
verticalInset:aNumber |
|
293 |
"setup the offsets for insetting vertically the frame aNumber pixels |
|
294 |
at all sides" |
|
295 |
||
296 |
topOffset := aNumber. |
|
297 |
bottomOffset := aNumber negated. |
|
298 |
||
299 |
"Created: 26.5.1996 / 17:39:50 / cg" |
|
126 | 300 |
! ! |
301 |
||
302 |
!LayoutFrame methodsFor:'converting'! |
|
303 |
||
304 |
fromLiteralArrayEncoding:encoding |
|
305 |
"read my values from an encoding. |
|
306 |
The encoding is supposed to be of the form: |
|
307 |
(LayoutFrame orgOffsX relOrgX orgOffsY relOrgY cornOffsX relCornX cornOffsY relCornY) |
|
308 |
This is the reverse to literalArrayEncoding." |
|
77 | 309 |
|
126 | 310 |
leftOffset := encoding at:2. |
311 |
leftFraction := encoding at:3. |
|
312 |
topOffset := encoding at:4. |
|
313 |
topFraction := encoding at:5. |
|
314 |
rightOffset := encoding at:6. |
|
315 |
rightFraction := encoding at:7. |
|
316 |
bottomOffset := encoding at:8. |
|
317 |
bottomFraction := encoding at:9. |
|
318 |
||
319 |
" |
|
320 |
LayoutFrame new fromLiteralArrayEncoding:#(#LayoutFrame 70 0 2 0 0 1 25 0 ) |
|
321 |
#(#LayoutFrame 70 0 2 0 0 1 25 0 ) decodeAsLiteralArray |
|
322 |
" |
|
77 | 323 |
! |
324 |
||
126 | 325 |
literalArrayEncoding |
191 | 326 |
"encode myself as an array, from which a copy of the receiver |
327 |
can be reconstructed with #decodeAsLiteralArray. |
|
126 | 328 |
The encoding is: |
191 | 329 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY cornOffsX relCornX cornOffsY relCornY)" |
77 | 330 |
|
126 | 331 |
^ super literalArrayEncoding |
332 |
, (Array |
|
191 | 333 |
with:rightOffset |
334 |
with:rightFraction |
|
335 |
with:bottomOffset |
|
336 |
with:bottomFraction) |
|
77 | 337 |
|
126 | 338 |
"Modified: 1.9.1995 / 02:43:35 / claus" |
191 | 339 |
"Modified: 22.4.1996 / 13:00:17 / cg" |
77 | 340 |
! ! |
341 |
||
126 | 342 |
!LayoutFrame methodsFor:'initialization'! |
343 |
||
344 |
initialize |
|
345 |
leftOffset := rightOffset := bottomOffset := topOffset := 0. |
|
346 |
leftFraction := topFraction := 0. |
|
468 | 347 |
"/ bottomFraction := rightFraction := 1. |
348 |
bottomFraction := rightFraction := 0. |
|
349 |
||
350 |
"Modified: 1.3.1997 / 16:12:50 / cg" |
|
126 | 351 |
! ! |
77 | 352 |
|
83 | 353 |
!LayoutFrame methodsFor:'printing & storing'! |
354 |
||
355 |
displayString |
|
700 | 356 |
"return a printed representation of the receiver for displaying" |
357 |
||
83 | 358 |
^ (self class name) , '(' |
700 | 359 |
, 'l: ' , leftFraction displayString |
360 |
, '+' , leftOffset displayString |
|
361 |
, ' t: ' , topFraction displayString |
|
362 |
, '+' , topOffset displayString |
|
363 |
, ' r: ' , rightFraction displayString |
|
364 |
, '+' , rightOffset displayString |
|
365 |
, ' b: ' , bottomFraction displayString |
|
366 |
, '+' , bottomOffset displayString |
|
367 |
, ')' |
|
368 |
||
369 |
"Modified: 20.9.1997 / 11:40:14 / cg" |
|
83 | 370 |
! ! |
371 |
||
77 | 372 |
!LayoutFrame methodsFor:'queries'! |
373 |
||
126 | 374 |
corner |
375 |
^ rightFraction asFloat @ bottomFraction asFloat |
|
376 |
! |
|
377 |
||
416 | 378 |
isLayoutFrame |
379 |
"return true, if this is a layoutFrame" |
|
380 |
||
381 |
^ true |
|
382 |
||
383 |
||
384 |
! |
|
385 |
||
77 | 386 |
rectangleRelativeTo:superRectangle preferred:prefRect |
229 | 387 |
"compute the rectangle represented by the receiver, |
388 |
given the superViews rectangle and the views preferredExtent." |
|
389 |
||
498 | 390 |
|x1 y1 x2 y2 superWidth superHeight| |
77 | 391 |
|
392 |
leftOffset isNil ifTrue:[ |
|
229 | 393 |
x1 := 0 |
77 | 394 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
395 |
x1 := leftOffset value |
77 | 396 |
]. |
397 |
topOffset isNil ifTrue:[ |
|
229 | 398 |
y1 := 0 |
77 | 399 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
400 |
y1 := topOffset value |
77 | 401 |
]. |
402 |
rightOffset isNil ifTrue:[ |
|
229 | 403 |
x2 := 0 |
77 | 404 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
405 |
x2 := rightOffset value |
77 | 406 |
]. |
407 |
bottomOffset isNil ifTrue:[ |
|
229 | 408 |
y2 := 0 |
77 | 409 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
410 |
y2 := bottomOffset value |
77 | 411 |
]. |
498 | 412 |
|
77 | 413 |
leftFraction notNil ifTrue:[ |
498 | 414 |
superWidth := superRectangle width. |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
415 |
x1 := x1 + (superWidth * leftFraction value) |
77 | 416 |
]. |
417 |
topFraction notNil ifTrue:[ |
|
498 | 418 |
superHeight := superRectangle height. |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
419 |
y1 := y1 + (superHeight * topFraction value) |
77 | 420 |
]. |
421 |
rightFraction notNil ifTrue:[ |
|
498 | 422 |
superWidth isNil ifTrue:[superWidth := superRectangle width]. |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
423 |
x2 := x2 + (superWidth * rightFraction value) |
77 | 424 |
]. |
425 |
bottomFraction notNil ifTrue:[ |
|
498 | 426 |
superHeight isNil ifTrue:[superHeight := superRectangle height]. |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
427 |
y2 := y2 + (superHeight * bottomFraction value) |
77 | 428 |
]. |
242 | 429 |
^ Rectangle left:x1 top:y1 right:x2 bottom:y2 |
83 | 430 |
|
431 |
" |
|
432 |
|superRect lF| |
|
433 |
||
498 | 434 |
superRect := 0@0 corner:99@99. |
83 | 435 |
lF := (LayoutFrame new). |
436 |
lF leftFraction:0.25; |
|
229 | 437 |
topFraction:0.25; |
438 |
rightFraction:0.75; |
|
439 |
bottomFraction:0.75. |
|
83 | 440 |
lF rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
441 |
" |
|
229 | 442 |
|
498 | 443 |
"Created: 6.3.1997 / 21:07:51 / cg" |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
444 |
"Modified: 13.9.1997 / 10:40:24 / cg" |
77 | 445 |
! ! |
100 | 446 |
|
126 | 447 |
!LayoutFrame class methodsFor:'documentation'! |
100 | 448 |
|
126 | 449 |
version |
700 | 450 |
^ '$Header: /cvs/stx/stx/libview2/Attic/LayoutFrm.st,v 1.23 1997-09-20 22:19:44 cg Exp $' |
100 | 451 |
! ! |