40 its superview. It provides the same functionality as a relative origin |
40 its superview. It provides the same functionality as a relative origin |
41 combined with insets. |
41 combined with insets. |
42 A layoutOrigin controls the origin of a subcomponent, given a fractional |
42 A layoutOrigin controls the origin of a subcomponent, given a fractional |
43 component and an offset component. |
43 component and an offset component. |
44 |
44 |
45 See also: |
45 Notice: |
46 LayoutFrame AlignmentOrigin Layout |
46 this class was implemented using protocol information |
47 |
47 from alpha testers - it may not be complete or compatible to |
48 Notice: this class was implemented using protocol information |
48 the corresponding ST-80 class. |
49 from alpha testers - it may not be complete or compatible to |
49 If you encounter any incompatibilities, please forward a note |
50 the corresponding ST-80 class. If you encounter any incompatibilities, |
50 describing the incompatibility verbal (i.e. no code) to the ST/X team. |
51 please forward a note to the ST/X team. |
|
52 |
51 |
53 [author:] |
52 [author:] |
54 Claus Gittinger |
53 Claus Gittinger |
|
54 |
|
55 [see also:] |
|
56 View |
|
57 LayoutFrame AlignmentOrigin Layout |
|
58 Rectangle Point |
55 " |
59 " |
56 ! |
60 ! |
57 |
61 |
58 examples |
62 examples |
59 " |
63 " |
60 using a LayoutOrigin, to control the top-left origins position of |
64 Although the examples below use a button as component, |
61 a component (i.e. origin at:0.5@0.5): |
65 they work of course with any type of subview .... |
62 |
66 |
63 |top button| |
67 using a LayoutOrigin, to arrange for |
64 |
68 the TOPLEFT of a component be positions |
65 top := StandardSystemView new. |
69 at the center (i.e. buttons origin at:0.5 @ 0.5): |
66 top extent:300@300. |
70 [exBegin] |
67 |
71 |top button| |
68 button := Button label:'component'. |
72 |
69 top add:button in:(LayoutOrigin new |
73 top := StandardSystemView new. |
70 leftFraction:0.5; |
74 top extent:300@300. |
71 topFraction:0.5). |
75 |
72 |
76 button := Button label:'component'. |
73 top open |
77 top add:button in:(LayoutOrigin new |
|
78 leftFraction:0.5; |
|
79 topFraction:0.5). |
|
80 |
|
81 top open |
|
82 [exEnd] |
74 |
83 |
75 |
84 |
76 like above, but adds an additional offset: |
85 like above, but adds an additional offset: |
77 (i.e. center of component at:0.5@0.5 OFFSET by 10@20): |
86 (i.e. center of button at:0.5 @ 0.5 OFFSET by 10 @ 20): |
78 |
87 [exBegin] |
79 |top button| |
88 |top button| |
80 |
89 |
81 top := StandardSystemView new. |
90 top := StandardSystemView new. |
82 top extent:300@300. |
91 top extent:300@300. |
83 |
92 |
84 button := Button label:'component'. |
93 button := Button label:'component'. |
85 top add:button in:(LayoutOrigin new |
94 top add:button in:(LayoutOrigin new |
86 leftFraction:0.5; |
95 leftFraction:0.5; |
87 topFraction:0.5; |
96 topFraction:0.5; |
88 leftOffset:10; |
97 leftOffset:10; |
89 topOffset:20). |
98 topOffset:20). |
90 |
99 |
91 top open |
100 top open |
|
101 [exEnd] |
92 " |
102 " |
93 ! ! |
103 ! ! |
94 |
104 |
95 !LayoutOrigin class methodsFor:'instance creation'! |
105 !LayoutOrigin class methodsFor:'instance creation'! |
96 |
106 |
286 origin |
296 origin |
287 ^ leftFraction asFloat @ topFraction asFloat |
297 ^ leftFraction asFloat @ topFraction asFloat |
288 ! |
298 ! |
289 |
299 |
290 rectangleRelativeTo:superRectangle preferred:prefRect |
300 rectangleRelativeTo:superRectangle preferred:prefRect |
|
301 "compute the rectangle represented by the receiver, |
|
302 given the superViews rectangle and the views preferredExtent." |
|
303 |
291 |x y| |
304 |x y| |
292 |
305 |
293 leftOffset isNil ifTrue:[ |
306 leftOffset isNil ifTrue:[ |
294 x := 0 |
307 x := 0 |
295 ] ifFalse:[ |
308 ] ifFalse:[ |
296 x := leftOffset |
309 x := leftOffset |
297 ]. |
310 ]. |
298 topOffset isNil ifTrue:[ |
311 topOffset isNil ifTrue:[ |
299 y := 0 |
312 y := 0 |
300 ] ifFalse:[ |
313 ] ifFalse:[ |
301 y := topOffset |
314 y := topOffset |
302 ]. |
315 ]. |
303 leftFraction notNil ifTrue:[ |
316 leftFraction notNil ifTrue:[ |
304 x := x + (superRectangle width * leftFraction) |
317 x := x + (superRectangle width * leftFraction) |
305 ]. |
318 ]. |
306 topFraction notNil ifTrue:[ |
319 topFraction notNil ifTrue:[ |
307 y := y + (superRectangle height * topFraction) |
320 y := y + (superRectangle height * topFraction) |
308 ]. |
321 ]. |
309 ^ Rectangle origin:x@y extent:prefRect extent |
322 ^ Rectangle origin:x@y extent:prefRect extent |
310 |
323 |
311 " |
324 " |
312 |superRect lO| |
325 |superRect lO| |
313 |
326 |
314 superRect := 0@0 corner:100@100. |
327 superRect := 0@0 corner:100@100. |
315 lO := (LayoutOrigin new). |
328 lO := (LayoutOrigin new). |
316 lO leftFraction:0.5; |
329 lO leftFraction:0.5; |
317 topFraction:0.5. |
330 topFraction:0.5. |
318 lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
331 lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) |
319 " |
332 " |
|
333 |
|
334 "Modified: 27.4.1996 / 14:54:06 / cg" |
320 ! ! |
335 ! ! |
321 |
336 |
322 !LayoutOrigin class methodsFor:'documentation'! |
337 !LayoutOrigin class methodsFor:'documentation'! |
323 |
338 |
324 version |
339 version |
325 ^ '$Header: /cvs/stx/stx/libview2/LayoutOrigin.st,v 1.11 1996-04-25 16:20:55 cg Exp $' |
340 ^ '$Header: /cvs/stx/stx/libview2/LayoutOrigin.st,v 1.12 1996-04-27 17:51:14 cg Exp $' |
326 ! ! |
341 ! ! |