LayoutFrame.st
author Claus Gittinger <cg@exept.de>
Tue, 23 Apr 1996 13:06:56 +0200
changeset 210 5405de794686
parent 191 cb2815b77100
child 219 106b86ca81da
permissions -rw-r--r--
checkin from browser

"
 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 to the ST/X team.
"
!

examples
"
	|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


    like above, but adds additional offset to the origin:

	|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


    like above, with offsets on all edges, actually simulating
    a constant inset on all four edges:

	|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
"
! !

!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
!

bottomOffset
    "return bottomOffset"

    ^ bottomOffset
!

bottomOffset:something
    "set bottomOffset"

    bottomOffset := something.
!

rightFraction
    "return rightFraction"

    ^ rightFraction
!

rightFraction:something
    "set rightFraction"

    rightFraction := something.
!

rightFraction:something offset:o
    "set rightFraction and offset"

    rightFraction := something.
    rightOffset := o
!

rightOffset
    "return rightOffset"

    ^ rightOffset
!

rightOffset:something
    "set rightOffset"

    rightOffset := something.
! !

!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.
! !

!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
!

rectangleRelativeTo:superRectangle preferred:prefRect
    |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 origin:x1@y1 corner:x2@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) 
    "
! !

!LayoutFrame class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/LayoutFrame.st,v 1.11 1996-04-22 11:02:14 cg Exp $'
! !