author | Claus Gittinger <cg@exept.de> |
Mon, 15 Sep 1997 22:16:05 +0200 | |
changeset 695 | b27d39658fd2 |
parent 544 | b5e8b405844f |
child 736 | d9f874e6b1e4 |
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 |
||
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
13 |
'From Smalltalk/X, Version:3.1.10 on 13-sep-1997 at 10:54:44 pm' ! |
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
14 |
|
83 | 15 |
LayoutOrigin subclass:#AlignmentOrigin |
191 | 16 |
instanceVariableNames:'leftAlignmentFraction topAlignmentFraction' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Graphics-Geometry' |
|
83 | 20 |
! |
21 |
||
88 | 22 |
!AlignmentOrigin 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 components origin |
|
43 |
via a relative part plus offset. However, in contrast to LayoutOrigin |
|
44 |
(in which the top-left corner is specified by fraction+offset, here any |
|
45 |
reference point within the component is positioned. |
|
46 |
The reference point itself is specified as fraction of the components size. |
|
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. |
|
216 | 54 |
|
219 | 55 |
[author:] |
56 |
Claus Gittinger |
|
57 |
||
216 | 58 |
[See also:] |
59 |
LayoutOrigin LayoutFrame Layout |
|
60 |
View |
|
94 | 61 |
" |
93 | 62 |
! |
63 |
||
64 |
examples |
|
65 |
" |
|
229 | 66 |
Although the examples below use a button as component, |
67 |
they work of course with any type of subview .... |
|
68 |
||
93 | 69 |
using a LayoutOrigin, to control the top-left origins position of |
70 |
a component (i.e. origin at:0.5@0.5): |
|
229 | 71 |
[exBegin] |
72 |
|top button| |
|
93 | 73 |
|
229 | 74 |
top := StandardSystemView new. |
75 |
top extent:300@300. |
|
93 | 76 |
|
229 | 77 |
button := Button label:'component'. |
78 |
top add:button in:(LayoutOrigin new |
|
79 |
leftFraction:0.5; |
|
80 |
topFraction:0.5). |
|
93 | 81 |
|
229 | 82 |
top open |
83 |
[exEnd] |
|
93 | 84 |
|
85 |
||
86 |
using an AlignmentOrigin, to control the centers position of |
|
87 |
a component (i.e. center of component at:0.5@0.5): |
|
229 | 88 |
[exBegin] |
89 |
|top button| |
|
93 | 90 |
|
229 | 91 |
top := StandardSystemView new. |
92 |
top extent:300@300. |
|
93 | 93 |
|
229 | 94 |
button := Button label:'component'. |
95 |
top add:button in:(AlignmentOrigin new |
|
96 |
leftFraction:0.5; |
|
97 |
topFraction:0.5; |
|
98 |
leftAlignmentFraction:0.5; |
|
99 |
topAlignmentFraction:0.5). |
|
93 | 100 |
|
229 | 101 |
top open |
102 |
[exEnd] |
|
93 | 103 |
|
104 |
||
105 |
using an AlignmentOrigin, to control the bottom-right position of |
|
106 |
a component (i.e. bottom-right of component at:0.5@0.5): |
|
229 | 107 |
[exBegin] |
108 |
|top button| |
|
93 | 109 |
|
229 | 110 |
top := StandardSystemView new. |
111 |
top extent:300@300. |
|
93 | 112 |
|
229 | 113 |
button := Button label:'component'. |
114 |
top add:button in:(AlignmentOrigin new |
|
115 |
leftFraction:0.5; |
|
116 |
topFraction:0.5; |
|
117 |
leftAlignmentFraction:1.0; |
|
118 |
topAlignmentFraction:1.0). |
|
93 | 119 |
|
229 | 120 |
top open |
121 |
[exEnd] |
|
243 | 122 |
|
123 |
||
124 |
four buttons around relative 0.75@0.75: |
|
125 |
[exBegin] |
|
126 |
|top button| |
|
127 |
||
128 |
top := StandardSystemView new. |
|
129 |
top extent:300@300. |
|
130 |
||
131 |
button := Button label:'button1'. |
|
132 |
top add:button in:(AlignmentOrigin new |
|
133 |
leftFraction:0.75; |
|
134 |
topFraction:0.75; |
|
135 |
leftAlignmentFraction:1.0; |
|
136 |
topAlignmentFraction:1.0). |
|
137 |
||
138 |
button := Button label:'button2'. |
|
139 |
top add:button in:(AlignmentOrigin new |
|
140 |
leftFraction:0.75; |
|
141 |
topFraction:0.75; |
|
142 |
leftAlignmentFraction:0.0; |
|
143 |
topAlignmentFraction:1.0). |
|
144 |
||
145 |
button := Button label:'button3'. |
|
146 |
top add:button in:(AlignmentOrigin new |
|
147 |
leftFraction:0.75; |
|
148 |
topFraction:0.75; |
|
244 | 149 |
leftAlignmentFraction:1.0; |
243 | 150 |
topAlignmentFraction:0.0). |
151 |
||
152 |
button := Button label:'button4'. |
|
153 |
top add:button in:(AlignmentOrigin new |
|
154 |
leftFraction:0.75; |
|
155 |
topFraction:0.75; |
|
244 | 156 |
leftAlignmentFraction:0.0; |
243 | 157 |
topAlignmentFraction:0.0). |
158 |
top open |
|
159 |
[exEnd] |
|
93 | 160 |
" |
88 | 161 |
! ! |
162 |
||
83 | 163 |
!AlignmentOrigin methodsFor:'accessing'! |
164 |
||
126 | 165 |
leftAlignmentFraction |
166 |
"return leftAlignmentFraction" |
|
167 |
||
168 |
^ leftAlignmentFraction |
|
169 |
! |
|
170 |
||
83 | 171 |
leftAlignmentFraction:something |
172 |
"set leftAlignmentFraction" |
|
173 |
||
174 |
leftAlignmentFraction := something. |
|
175 |
! |
|
176 |
||
544 | 177 |
leftAlignmentFraction:lF topAlignmentFraction:tF |
178 |
"set both leftAlignmentFraction and topAlignmentFraction" |
|
179 |
||
180 |
leftAlignmentFraction := lF. |
|
181 |
topAlignmentFraction := tF |
|
182 |
||
183 |
"Created: 18.4.1997 / 20:06:02 / cg" |
|
184 |
! |
|
185 |
||
126 | 186 |
topAlignmentFraction |
187 |
"return topAlignmentFraction" |
|
83 | 188 |
|
419 | 189 |
^ topAlignmentFraction |
83 | 190 |
! |
191 |
||
192 |
topAlignmentFraction:something |
|
193 |
"set topAlignmentFraction" |
|
194 |
||
195 |
topAlignmentFraction := something. |
|
126 | 196 |
! ! |
197 |
||
198 |
!AlignmentOrigin methodsFor:'converting'! |
|
199 |
||
200 |
fromLiteralArrayEncoding:encoding |
|
201 |
"read my values from an encoding. |
|
202 |
The encoding is supposed to be of the form: |
|
203 |
(AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
|
204 |
||
205 |
leftOffset := encoding at:2. |
|
206 |
leftFraction := encoding at:3. |
|
207 |
topOffset := encoding at:4. |
|
208 |
topFraction := encoding at:5. |
|
209 |
leftAlignmentFraction := encoding at:6. |
|
210 |
topAlignmentFraction := encoding at:7. |
|
211 |
||
212 |
||
213 |
" |
|
214 |
AlignmentOrigin new fromLiteralArrayEncoding:#(#AlignmentOrigin 70 0 2 0 0.5 0.25) |
|
215 |
" |
|
216 |
||
217 |
"Modified: 1.9.1995 / 02:23:53 / claus" |
|
83 | 218 |
! |
219 |
||
126 | 220 |
literalArrayEncoding |
191 | 221 |
"encode myself as an array, from which a copy of the receiver |
222 |
can be reconstructed with #decodeAsLiteralArray. |
|
126 | 223 |
The encoding is: |
191 | 224 |
(#AlignmentOrigin orgOffsX relOrgX orgOffsY relOrgY leftAlignFract topAlignFract)" |
83 | 225 |
|
126 | 226 |
^ super literalArrayEncoding |
227 |
, (Array |
|
191 | 228 |
with:leftAlignmentFraction |
229 |
with:topAlignmentFraction) |
|
126 | 230 |
|
231 |
"Modified: 1.9.1995 / 02:43:35 / claus" |
|
191 | 232 |
"Modified: 22.4.1996 / 12:59:56 / cg" |
126 | 233 |
! ! |
234 |
||
235 |
!AlignmentOrigin methodsFor:'initialization'! |
|
236 |
||
237 |
initialize |
|
238 |
super initialize. |
|
239 |
leftAlignmentFraction := topAlignmentFraction := 0. |
|
83 | 240 |
! ! |
241 |
||
242 |
!AlignmentOrigin methodsFor:'printing & storing'! |
|
243 |
||
244 |
displayString |
|
379 | 245 |
"return a printed representation of the receiver for displaying" |
246 |
||
413 | 247 |
^ self class name , '(' |
379 | 248 |
, 'l: ' , leftFraction displayString |
249 |
, '+' , leftOffset displayString |
|
250 |
, ' t: ' , topFraction displayString |
|
251 |
, '+' , topOffset displayString |
|
252 |
, ' a: ' , leftAlignmentFraction displayString |
|
253 |
, '@' , topAlignmentFraction displayString |
|
254 |
, ')' |
|
255 |
||
256 |
"Modified: 22.1.1997 / 11:58:38 / cg" |
|
83 | 257 |
! ! |
258 |
||
259 |
!AlignmentOrigin methodsFor:'queries'! |
|
260 |
||
414 | 261 |
isAlignmentOrigin |
262 |
"return true, if this is an alignmentOrigin" |
|
263 |
||
264 |
^ true |
|
265 |
||
266 |
||
267 |
! |
|
268 |
||
83 | 269 |
rectangleRelativeTo:superRectangle preferred:prefRect |
229 | 270 |
"compute the rectangle represented by the receiver, |
271 |
given the superViews rectangle and the views preferredExtent." |
|
272 |
||
83 | 273 |
|x y| |
274 |
||
275 |
leftOffset isNil ifTrue:[ |
|
229 | 276 |
x := 0 |
83 | 277 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
278 |
x := leftOffset value |
83 | 279 |
]. |
280 |
topOffset isNil ifTrue:[ |
|
229 | 281 |
y := 0 |
83 | 282 |
] ifFalse:[ |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
283 |
y := topOffset value |
83 | 284 |
]. |
285 |
leftFraction notNil ifTrue:[ |
|
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
286 |
x := x + (superRectangle width * leftFraction value) |
83 | 287 |
]. |
288 |
topFraction notNil ifTrue:[ |
|
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
289 |
y := y + (superRectangle height * topFraction value) |
83 | 290 |
]. |
291 |
leftAlignmentFraction ~~ 0 ifTrue:[ |
|
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
292 |
x := x - (prefRect width * leftAlignmentFraction value) |
83 | 293 |
]. |
294 |
topAlignmentFraction ~~ 0 ifTrue:[ |
|
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
295 |
y := y - (prefRect height * topAlignmentFraction value) |
83 | 296 |
]. |
242 | 297 |
^ Rectangle left:x top:y extent:prefRect extent |
83 | 298 |
|
299 |
" |
|
300 |
|superRect aO| |
|
301 |
||
302 |
superRect := 0@0 corner:100@100. |
|
303 |
aO := (AlignmentOrigin new). |
|
304 |
aO leftFraction:0.5; |
|
229 | 305 |
topFraction:0.5; |
306 |
leftAlignmentFraction:0.5; |
|
307 |
topAlignmentFraction:0.5. |
|
83 | 308 |
aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
309 |
" |
|
229 | 310 |
|
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
311 |
"Modified: 13.9.1997 / 10:39:50 / cg" |
83 | 312 |
! ! |
313 |
||
126 | 314 |
!AlignmentOrigin class methodsFor:'documentation'! |
100 | 315 |
|
126 | 316 |
version |
695
b27d39658fd2
allow valueHolders for the layout components.
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
317 |
^ '$Header: /cvs/stx/stx/libview2/AlignmentOrigin.st,v 1.21 1997-09-15 20:16:04 cg Exp $' |
100 | 318 |
! ! |