"
COPYRIGHT (c) 1995 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
LayoutOrigin subclass:#LayoutFrame
instanceVariableNames:'rightFraction bottomFraction rightOffset bottomOffset'
classVariableNames:''
poolDictionaries:''
category:'Graphics-Geometry'
!
!LayoutFrame class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1995 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
!
documentation
"
This class is provided to make porting of existing ST-80 applications
easier. Instances can be used to control the geometry of a subview, within
its superview. Like a layoutOrigin, it controls the origin of a component
by given fraction and offset dimensions; in addition, the bottom-right
corner is also controlled by corresponding values. Therefore, the components
preferredExtent is ignored.
See also:
LayoutOrigin AlignmentOrigin Layout
Notice:
this class was implemented using protocol information
from alpha testers - it may not be complete or compatible to
the corresponding ST-80 class.
If you encounter any incompatibilities, please forward a note
describing the incompatibility verbal (i.e. no code) to the ST/X team.
[author:]
Claus Gittinger
[see also:]
View
LayoutOrigin AlignmentOrigin Layout
Rectangle Point
"
!
examples
"
Although the examples below use a button as component,
they work of course with any type of subview ....
arrange for the button to be in 0.25 @ 0.25 -> 0.75 @ 0.75.
This is the same as with relative origin/corner.
[exBegin]
|top button|
top := StandardSystemView new.
top extent:300@300.
button := Button label:'component'.
top add:button in:(LayoutFrame new
leftFraction:0.25;
topFraction:0.25;
rightFraction:0.75;
bottomFraction:0.75).
top open
[exEnd]
like above, but adds additional offset to the origin:
This is the same as with relative origin/corner
and setting left & right insets.
[exBegin]
|top button|
top := StandardSystemView new.
top extent:300@300.
button := Button label:'component'.
top add:button in:(LayoutFrame new
leftFraction:0.25; leftOffset:10;
topFraction:0.25; topOffset:-20;
rightFraction:0.75;
bottomFraction:0.75).
top open
[exEnd]
like above, with offsets on all edges,
actually simulating a constant inset on all four edges:
[exBegin]
|top button|
top := StandardSystemView new.
top extent:300@300.
button := Button label:'component'.
top add:button in:(LayoutFrame new
leftFraction:0.0; leftOffset:10;
topFraction:0.0; topOffset:10;
rightFraction:1.0; rightOffset:-10;
bottomFraction:1.0; bottomOffset:-10).
top open
[exEnd]
"
! !
!LayoutFrame class methodsFor:'instance creation'!
leftFraction:lF offset:lO rightFraction:rF offset:rO topFraction:tF offset:tO bottomFraction:bF offset:bO
"create a new layoutFrame"
^ self new
leftFraction:lF offset:lO
rightFraction:rF offset:rO
topFraction:tF offset:tO
bottomFraction:bF offset:bO
! !
!LayoutFrame methodsFor:'accessing'!
bottomFraction
"return bottomFraction"
^ bottomFraction
!
bottomFraction:something
"set bottomFraction"
bottomFraction := something.
!
bottomFraction:something offset:o
"set bottomFraction and offset"
bottomFraction := something.
bottomOffset := o
!
bottomInset:pixels
"set bottomOffset for an inset at the bottom"
bottomOffset := pixels negated.
"Created: 26.5.1996 / 17:38:30 / cg"
!
bottomOffset
"return bottomOffset"
^ bottomOffset
!
bottomOffset:something
"set bottomOffset"
bottomOffset := something.
!
horizontalInset:aNumber
"setup the offsets for insetting horizontally the frame aNumber pixels
at all sides"
leftOffset := aNumber.
rightOffset := aNumber negated.
"Created: 26.5.1996 / 17:39:35 / cg"
!
inset:aNumber
"setup the offsets for insetting the frame aNumber pixels
at all sides"
topOffset := leftOffset := aNumber.
rightOffset := bottomOffset := aNumber negated.
"Created: 26.5.1996 / 17:36:49 / cg"
!
leftFraction:lF offset:lO rightFraction:rF offset:rO topFraction:tF offset:tO bottomFraction:bF offset:bO
"set all fields"
leftFraction := lF.
rightFraction := rF.
topFraction := tF.
bottomFraction := bF.
leftOffset := lO.
rightOffset := rO.
topOffset := tO.
bottomOffset := bO.
!
rightFraction
"return rightFraction"
^ rightFraction
!
rightFraction:something
"set rightFraction"
rightFraction := something.
!
rightFraction:something offset:o
"set rightFraction and offset"
rightFraction := something.
rightOffset := o
!
rightInset:pixels
"set rightOffset for an inset at the right"
rightOffset := pixels negated.
"Created: 26.5.1996 / 17:38:38 / cg"
!
rightOffset
"return rightOffset"
^ rightOffset
!
rightOffset:something
"set rightOffset"
rightOffset := something.
!
verticalInset:aNumber
"setup the offsets for insetting vertically the frame aNumber pixels
at all sides"
topOffset := aNumber.
bottomOffset := aNumber negated.
"Created: 26.5.1996 / 17:39:50 / cg"
! !
!LayoutFrame methodsFor:'converting'!
fromLiteralArrayEncoding:encoding
"read my values from an encoding.
The encoding is supposed to be of the form:
(LayoutFrame orgOffsX relOrgX orgOffsY relOrgY cornOffsX relCornX cornOffsY relCornY)
This is the reverse to literalArrayEncoding."
leftOffset := encoding at:2.
leftFraction := encoding at:3.
topOffset := encoding at:4.
topFraction := encoding at:5.
rightOffset := encoding at:6.
rightFraction := encoding at:7.
bottomOffset := encoding at:8.
bottomFraction := encoding at:9.
"
LayoutFrame new fromLiteralArrayEncoding:#(#LayoutFrame 70 0 2 0 0 1 25 0 )
#(#LayoutFrame 70 0 2 0 0 1 25 0 ) decodeAsLiteralArray
"
!
literalArrayEncoding
"encode myself as an array, from which a copy of the receiver
can be reconstructed with #decodeAsLiteralArray.
The encoding is:
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY cornOffsX relCornX cornOffsY relCornY)"
^ super literalArrayEncoding
, (Array
with:rightOffset
with:rightFraction
with:bottomOffset
with:bottomFraction)
"Modified: 1.9.1995 / 02:43:35 / claus"
"Modified: 22.4.1996 / 13:00:17 / cg"
! !
!LayoutFrame methodsFor:'initialization'!
initialize
leftOffset := rightOffset := bottomOffset := topOffset := 0.
leftFraction := topFraction := 0.
"/ bottomFraction := rightFraction := 1.
bottomFraction := rightFraction := 0.
"Modified: 1.3.1997 / 16:12:50 / cg"
! !
!LayoutFrame methodsFor:'printing & storing'!
displayString
^ (self class name) , '('
, 'l: ' , leftFraction displayString
, '+' , leftOffset displayString
, ' t: ' , topFraction displayString
, '+' , topOffset displayString
, ' r: ' , rightFraction displayString
, '+' , rightOffset displayString
, ' b: ' , bottomFraction displayString
, '+' , bottomOffset displayString
, ')'
! !
!LayoutFrame methodsFor:'queries'!
corner
^ rightFraction asFloat @ bottomFraction asFloat
!
isLayoutFrame
"return true, if this is a layoutFrame"
^ true
!
rectangleRelativeTo:superRectangle preferred:prefRect
"compute the rectangle represented by the receiver,
given the superViews rectangle and the views preferredExtent."
|x1 y1 x2 y2|
leftOffset isNil ifTrue:[
x1 := 0
] ifFalse:[
x1 := leftOffset
].
topOffset isNil ifTrue:[
y1 := 0
] ifFalse:[
y1 := topOffset
].
rightOffset isNil ifTrue:[
x2 := 0
] ifFalse:[
x2 := rightOffset
].
bottomOffset isNil ifTrue:[
y2 := 0
] ifFalse:[
y2 := bottomOffset
].
leftFraction notNil ifTrue:[
x1 := x1 + (superRectangle width * leftFraction)
].
topFraction notNil ifTrue:[
y1 := y1 + (superRectangle height * topFraction)
].
rightFraction notNil ifTrue:[
x2 := x2 + (superRectangle width * rightFraction)
].
bottomFraction notNil ifTrue:[
y2 := y2 + (superRectangle height * bottomFraction)
].
^ Rectangle left:x1 top:y1 right:x2 bottom:y2
"
|superRect lF|
superRect := 0@0 corner:100@100.
lF := (LayoutFrame new).
lF leftFraction:0.25;
topFraction:0.25;
rightFraction:0.75;
bottomFraction:0.75.
lF rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
"
"Modified: 8.5.1996 / 20:50:45 / cg"
! !
!LayoutFrame class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libview2/LayoutFrame.st,v 1.19 1997-03-01 16:27:29 cg Exp $'
! !