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
|
126
|
14 |
instanceVariableNames:'rightFraction bottomFraction rightOffset bottomOffset'
|
77
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
83
|
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:
|
|
46 |
LayoutOrigin AlignmentOrigin Layout
|
|
47 |
|
|
48 |
Notice: this class was implemented using protocol information
|
|
49 |
from alpha testers - it may not be complete or compatible to
|
|
50 |
the corresponding ST-80 class. If you encounter any incompatibilities,
|
|
51 |
please forward a note to the ST/X team.
|
94
|
52 |
"
|
93
|
53 |
!
|
|
54 |
|
|
55 |
examples
|
|
56 |
"
|
|
57 |
|top button|
|
|
58 |
|
|
59 |
top := StandardSystemView new.
|
|
60 |
top extent:300@300.
|
|
61 |
|
|
62 |
button := Button label:'component'.
|
|
63 |
top add:button in:(LayoutFrame new
|
|
64 |
leftFraction:0.25;
|
|
65 |
topFraction:0.25;
|
|
66 |
rightFraction:0.75;
|
|
67 |
bottomFraction:0.75).
|
|
68 |
|
|
69 |
top open
|
|
70 |
|
|
71 |
|
|
72 |
like above, but adds additional offset to the origin:
|
|
73 |
|
|
74 |
|top button|
|
|
75 |
|
|
76 |
top := StandardSystemView new.
|
|
77 |
top extent:300@300.
|
|
78 |
|
|
79 |
button := Button label:'component'.
|
|
80 |
top add:button in:(LayoutFrame new
|
|
81 |
leftFraction:0.25; leftOffset:10;
|
|
82 |
topFraction:0.25; topOffset:-20;
|
|
83 |
rightFraction:0.75;
|
|
84 |
bottomFraction:0.75).
|
|
85 |
|
|
86 |
top open
|
|
87 |
|
|
88 |
|
|
89 |
like above, with offsets on all edges, actually simulating
|
|
90 |
a constant inset on all four edges:
|
|
91 |
|
|
92 |
|top button|
|
|
93 |
|
|
94 |
top := StandardSystemView new.
|
|
95 |
top extent:300@300.
|
|
96 |
|
|
97 |
button := Button label:'component'.
|
|
98 |
top add:button in:(LayoutFrame new
|
|
99 |
leftFraction:0.0; leftOffset:10;
|
|
100 |
topFraction:0.0; topOffset:10;
|
|
101 |
rightFraction:1.0; rightOffset:-10;
|
|
102 |
bottomFraction:1.0; bottomOffset:-10).
|
|
103 |
|
|
104 |
top open
|
|
105 |
"
|
88
|
106 |
! !
|
|
107 |
|
77
|
108 |
!LayoutFrame methodsFor:'accessing'!
|
|
109 |
|
126
|
110 |
bottomFraction
|
|
111 |
"return bottomFraction"
|
|
112 |
|
|
113 |
^ bottomFraction
|
|
114 |
!
|
|
115 |
|
|
116 |
bottomFraction:something
|
|
117 |
"set bottomFraction"
|
|
118 |
|
|
119 |
bottomFraction := something.
|
|
120 |
!
|
|
121 |
|
|
122 |
bottomFraction:something offset:o
|
|
123 |
"set bottomFraction and offset"
|
77
|
124 |
|
126
|
125 |
bottomFraction := something.
|
|
126 |
bottomOffset := o
|
|
127 |
!
|
|
128 |
|
|
129 |
bottomOffset
|
|
130 |
"return bottomOffset"
|
|
131 |
|
|
132 |
^ bottomOffset
|
|
133 |
!
|
|
134 |
|
|
135 |
bottomOffset:something
|
|
136 |
"set bottomOffset"
|
|
137 |
|
|
138 |
bottomOffset := something.
|
77
|
139 |
!
|
|
140 |
|
|
141 |
rightFraction
|
|
142 |
"return rightFraction"
|
|
143 |
|
|
144 |
^ rightFraction
|
|
145 |
!
|
|
146 |
|
126
|
147 |
rightFraction:something
|
|
148 |
"set rightFraction"
|
77
|
149 |
|
126
|
150 |
rightFraction := something.
|
77
|
151 |
!
|
|
152 |
|
|
153 |
rightFraction:something offset:o
|
|
154 |
"set rightFraction and offset"
|
|
155 |
|
|
156 |
rightFraction := something.
|
|
157 |
rightOffset := o
|
|
158 |
!
|
|
159 |
|
126
|
160 |
rightOffset
|
|
161 |
"return rightOffset"
|
77
|
162 |
|
126
|
163 |
^ rightOffset
|
77
|
164 |
!
|
|
165 |
|
126
|
166 |
rightOffset:something
|
|
167 |
"set rightOffset"
|
|
168 |
|
|
169 |
rightOffset := something.
|
|
170 |
! !
|
|
171 |
|
|
172 |
!LayoutFrame methodsFor:'converting'!
|
|
173 |
|
|
174 |
fromLiteralArrayEncoding:encoding
|
|
175 |
"read my values from an encoding.
|
|
176 |
The encoding is supposed to be of the form:
|
|
177 |
(LayoutFrame orgOffsX relOrgX orgOffsY relOrgY cornOffsX relCornX cornOffsY relCornY)
|
|
178 |
This is the reverse to literalArrayEncoding."
|
77
|
179 |
|
126
|
180 |
leftOffset := encoding at:2.
|
|
181 |
leftFraction := encoding at:3.
|
|
182 |
topOffset := encoding at:4.
|
|
183 |
topFraction := encoding at:5.
|
|
184 |
rightOffset := encoding at:6.
|
|
185 |
rightFraction := encoding at:7.
|
|
186 |
bottomOffset := encoding at:8.
|
|
187 |
bottomFraction := encoding at:9.
|
|
188 |
|
|
189 |
"
|
|
190 |
LayoutFrame new fromLiteralArrayEncoding:#(#LayoutFrame 70 0 2 0 0 1 25 0 )
|
|
191 |
#(#LayoutFrame 70 0 2 0 0 1 25 0 ) decodeAsLiteralArray
|
|
192 |
"
|
77
|
193 |
!
|
|
194 |
|
126
|
195 |
literalArrayEncoding
|
|
196 |
"encode myself as an array.
|
|
197 |
The encoding is:
|
|
198 |
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY cornOffsX relCornX cornOffsY relCornY)"
|
77
|
199 |
|
126
|
200 |
^ super literalArrayEncoding
|
|
201 |
, (Array
|
|
202 |
with:rightOffset
|
|
203 |
with:rightFraction
|
|
204 |
with:bottomOffset
|
|
205 |
with:bottomFraction)
|
77
|
206 |
|
126
|
207 |
"Modified: 1.9.1995 / 02:43:35 / claus"
|
77
|
208 |
! !
|
|
209 |
|
126
|
210 |
!LayoutFrame methodsFor:'initialization'!
|
|
211 |
|
|
212 |
initialize
|
|
213 |
leftOffset := rightOffset := bottomOffset := topOffset := 0.
|
|
214 |
leftFraction := topFraction := 0.
|
|
215 |
bottomFraction := rightFraction := 1.
|
|
216 |
! !
|
77
|
217 |
|
83
|
218 |
!LayoutFrame methodsFor:'printing & storing'!
|
|
219 |
|
|
220 |
displayString
|
|
221 |
^ (self class name) , '('
|
|
222 |
, 'l: ' , leftFraction displayString
|
|
223 |
, '+' , leftOffset displayString
|
|
224 |
, ' t: ' , topFraction displayString
|
|
225 |
, '+' , topOffset displayString
|
|
226 |
, ' r: ' , rightFraction displayString
|
|
227 |
, '+' , rightOffset displayString
|
|
228 |
, ' b: ' , bottomFraction displayString
|
|
229 |
, '+' , bottomOffset displayString
|
|
230 |
, ')'
|
|
231 |
! !
|
|
232 |
|
77
|
233 |
!LayoutFrame methodsFor:'queries'!
|
|
234 |
|
126
|
235 |
corner
|
|
236 |
^ rightFraction asFloat @ bottomFraction asFloat
|
|
237 |
!
|
|
238 |
|
77
|
239 |
rectangleRelativeTo:superRectangle preferred:prefRect
|
|
240 |
|x1 y1 x2 y2|
|
|
241 |
|
|
242 |
leftOffset isNil ifTrue:[
|
|
243 |
x1 := 0
|
|
244 |
] ifFalse:[
|
|
245 |
x1 := leftOffset
|
|
246 |
].
|
|
247 |
topOffset isNil ifTrue:[
|
|
248 |
y1 := 0
|
|
249 |
] ifFalse:[
|
|
250 |
y1 := topOffset
|
|
251 |
].
|
|
252 |
rightOffset isNil ifTrue:[
|
|
253 |
x2 := 0
|
|
254 |
] ifFalse:[
|
|
255 |
x2 := rightOffset
|
|
256 |
].
|
|
257 |
bottomOffset isNil ifTrue:[
|
|
258 |
y2 := 0
|
|
259 |
] ifFalse:[
|
|
260 |
y2 := bottomOffset
|
|
261 |
].
|
|
262 |
leftFraction notNil ifTrue:[
|
83
|
263 |
x1 := x1 + (superRectangle width * leftFraction)
|
77
|
264 |
].
|
|
265 |
topFraction notNil ifTrue:[
|
83
|
266 |
y1 := y1 + (superRectangle height * topFraction)
|
77
|
267 |
].
|
|
268 |
rightFraction notNil ifTrue:[
|
83
|
269 |
x2 := x2 + (superRectangle width * rightFraction)
|
77
|
270 |
].
|
|
271 |
bottomFraction notNil ifTrue:[
|
83
|
272 |
y2 := y2 + (superRectangle height * bottomFraction)
|
77
|
273 |
].
|
|
274 |
^ Rectangle origin:x1@y1 corner:x2@y2
|
83
|
275 |
|
|
276 |
"
|
|
277 |
|superRect lF|
|
|
278 |
|
|
279 |
superRect := 0@0 corner:100@100.
|
|
280 |
lF := (LayoutFrame new).
|
|
281 |
lF leftFraction:0.25;
|
|
282 |
topFraction:0.25;
|
|
283 |
rightFraction:0.75;
|
|
284 |
bottomFraction:0.75.
|
|
285 |
lF rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
|
|
286 |
"
|
77
|
287 |
! !
|
100
|
288 |
|
126
|
289 |
!LayoutFrame class methodsFor:'documentation'!
|
100
|
290 |
|
126
|
291 |
version
|
|
292 |
^ '$Header: /cvs/stx/stx/libview2/Attic/LayoutFrm.st,v 1.10 1995-11-23 17:42:08 cg Exp $'
|
100
|
293 |
! !
|