AlignmentOrigin.st
changeset 229 612861ef768a
parent 219 106b86ca81da
child 242 5b7f59450c65
equal deleted inserted replaced
228:8f73cdf66b60 229:612861ef768a
    41     via a relative part plus offset. However, in contrast to LayoutOrigin
    41     via a relative part plus offset. However, in contrast to LayoutOrigin
    42     (in which the top-left corner is specified by fraction+offset, here any
    42     (in which the top-left corner is specified by fraction+offset, here any
    43     reference point within the component is positioned.
    43     reference point within the component is positioned.
    44     The reference point itself is specified as fraction of the components size.
    44     The reference point itself is specified as fraction of the components size.
    45 
    45 
    46     Notice: this class was implemented using protocol information
    46     Notice: 
    47     from alpha testers - it may not be complete or compatible to
    47         this class was implemented using protocol information
    48     the corresponding ST-80 class. If you encounter any incompatibilities,
    48         from alpha testers - it may not be complete or compatible to
    49     please forward a note to the ST/X team.
    49         the corresponding ST-80 class. 
       
    50         If you encounter any incompatibilities, please forward a note 
       
    51         describing the incompatibility verbal (i.e. no code) to the ST/X team.
    50 
    52 
    51     [author:]
    53     [author:]
    52         Claus Gittinger
    54         Claus Gittinger
    53 
    55 
    54     [See also:]
    56     [See also:]
    57 "
    59 "
    58 !
    60 !
    59 
    61 
    60 examples
    62 examples
    61 "
    63 "
       
    64     Although the examples below use a button as component,
       
    65     they work of course with any type of subview ....
       
    66 
    62     using a LayoutOrigin, to control the top-left origins position of
    67     using a LayoutOrigin, to control the top-left origins position of
    63     a component (i.e. origin at:0.5@0.5):
    68     a component (i.e. origin at:0.5@0.5):
    64 
    69                                                                         [exBegin]
    65 	|top button|
    70         |top button|
    66 
    71 
    67 	top := StandardSystemView new.
    72         top := StandardSystemView new.
    68 	top extent:300@300.
    73         top extent:300@300.
    69 
    74 
    70 	button := Button label:'component'.
    75         button := Button label:'component'.
    71 	top add:button in:(LayoutOrigin new
    76         top add:button in:(LayoutOrigin new
    72 				leftFraction:0.5;
    77                                 leftFraction:0.5;
    73 				topFraction:0.5).
    78                                 topFraction:0.5).
    74 
    79 
    75 	top open
    80         top open
       
    81                                                                         [exEnd]
    76 
    82 
    77 
    83 
    78     using an AlignmentOrigin, to control the centers position of
    84     using an AlignmentOrigin, to control the centers position of
    79     a component (i.e. center of component at:0.5@0.5):
    85     a component (i.e. center of component at:0.5@0.5):
    80 
    86                                                                         [exBegin]
    81 	|top button|
    87         |top button|
    82 
    88 
    83 	top := StandardSystemView new.
    89         top := StandardSystemView new.
    84 	top extent:300@300.
    90         top extent:300@300.
    85 
    91 
    86 	button := Button label:'component'.
    92         button := Button label:'component'.
    87 	top add:button in:(AlignmentOrigin new
    93         top add:button in:(AlignmentOrigin new
    88 				leftFraction:0.5;
    94                                 leftFraction:0.5;
    89 				topFraction:0.5;
    95                                 topFraction:0.5;
    90 				leftAlignmentFraction:0.5;
    96                                 leftAlignmentFraction:0.5;
    91 				topAlignmentFraction:0.5).
    97                                 topAlignmentFraction:0.5).
    92 
    98 
    93 	top open
    99         top open
       
   100                                                                         [exEnd]
    94 
   101 
    95 
   102 
    96     using an AlignmentOrigin, to control the bottom-right position of
   103     using an AlignmentOrigin, to control the bottom-right position of
    97     a component (i.e. bottom-right of component at:0.5@0.5):
   104     a component (i.e. bottom-right of component at:0.5@0.5):
    98 
   105                                                                         [exBegin]
    99 	|top button|
   106         |top button|
   100 
   107 
   101 	top := StandardSystemView new.
   108         top := StandardSystemView new.
   102 	top extent:300@300.
   109         top extent:300@300.
   103 
   110 
   104 	button := Button label:'component'.
   111         button := Button label:'component'.
   105 	top add:button in:(AlignmentOrigin new
   112         top add:button in:(AlignmentOrigin new
   106 				leftFraction:0.5;
   113                                 leftFraction:0.5;
   107 				topFraction:0.5;
   114                                 topFraction:0.5;
   108 				leftAlignmentFraction:1.0;
   115                                 leftAlignmentFraction:1.0;
   109 				topAlignmentFraction:1.0).
   116                                 topAlignmentFraction:1.0).
   110 
   117 
   111 	top open
   118         top open
       
   119                                                                         [exEnd]
   112 "
   120 "
   113 ! !
   121 ! !
   114 
   122 
   115 !AlignmentOrigin methodsFor:'accessing'!
   123 !AlignmentOrigin methodsFor:'accessing'!
   116 
   124 
   196 ! !
   204 ! !
   197 
   205 
   198 !AlignmentOrigin methodsFor:'queries'!
   206 !AlignmentOrigin methodsFor:'queries'!
   199 
   207 
   200 rectangleRelativeTo:superRectangle preferred:prefRect
   208 rectangleRelativeTo:superRectangle preferred:prefRect
       
   209     "compute the rectangle represented by the receiver,
       
   210      given the superViews rectangle and the views preferredExtent."
       
   211 
   201     |x y|
   212     |x y|
   202 
   213 
   203     leftOffset isNil ifTrue:[
   214     leftOffset isNil ifTrue:[
   204 	x := 0
   215         x := 0
   205     ] ifFalse:[
   216     ] ifFalse:[
   206 	x := leftOffset
   217         x := leftOffset
   207     ].
   218     ].
   208     topOffset isNil ifTrue:[
   219     topOffset isNil ifTrue:[
   209 	y := 0
   220         y := 0
   210     ] ifFalse:[
   221     ] ifFalse:[
   211 	y := topOffset
   222         y := topOffset
   212     ].
   223     ].
   213     leftFraction notNil ifTrue:[
   224     leftFraction notNil ifTrue:[
   214 	x := x + (superRectangle width * leftFraction)
   225         x := x + (superRectangle width * leftFraction)
   215     ].
   226     ].
   216     topFraction notNil ifTrue:[
   227     topFraction notNil ifTrue:[
   217 	y := y + (superRectangle height * topFraction)
   228         y := y + (superRectangle height * topFraction)
   218     ].
   229     ].
   219     leftAlignmentFraction ~~ 0 ifTrue:[
   230     leftAlignmentFraction ~~ 0 ifTrue:[
   220 	x := x - (prefRect width * leftAlignmentFraction)
   231         x := x - (prefRect width * leftAlignmentFraction)
   221     ].
   232     ].
   222     topAlignmentFraction ~~ 0 ifTrue:[
   233     topAlignmentFraction ~~ 0 ifTrue:[
   223 	y := y - (prefRect height * topAlignmentFraction)
   234         y := y - (prefRect height * topAlignmentFraction)
   224     ].
   235     ].
   225     ^ Rectangle origin:x@y extent:prefRect extent
   236     ^ Rectangle origin:x@y extent:prefRect extent
   226 
   237 
   227     "
   238     "
   228      |superRect aO|
   239      |superRect aO|
   229 
   240 
   230      superRect := 0@0 corner:100@100.
   241      superRect := 0@0 corner:100@100.
   231      aO := (AlignmentOrigin new).
   242      aO := (AlignmentOrigin new).
   232      aO leftFraction:0.5;
   243      aO leftFraction:0.5;
   233 	topFraction:0.5;
   244         topFraction:0.5;
   234 	leftAlignmentFraction:0.5;
   245         leftAlignmentFraction:0.5;
   235 	topAlignmentFraction:0.5.
   246         topAlignmentFraction:0.5.
   236      aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) 
   247      aO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30) 
   237     "
   248     "
       
   249 
       
   250     "Modified: 27.4.1996 / 14:53:56 / cg"
   238 ! !
   251 ! !
   239 
   252 
   240 !AlignmentOrigin class methodsFor:'documentation'!
   253 !AlignmentOrigin class methodsFor:'documentation'!
   241 
   254 
   242 version
   255 version
   243     ^ '$Header: /cvs/stx/stx/libview2/AlignmentOrigin.st,v 1.11 1996-04-25 16:21:00 cg Exp $'
   256     ^ '$Header: /cvs/stx/stx/libview2/AlignmentOrigin.st,v 1.12 1996-04-27 17:51:19 cg Exp $'
   244 ! !
   257 ! !