LayoutFrame.st
author claus
Wed, 30 Aug 1995 01:43:11 +0200
changeset 98 ab8ed9e213d0
parent 96 948318b2fbd4
child 100 0300e64bb883
permissions -rw-r--r--
.

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

'From Smalltalk/X, Version:2.10.5 on 15-apr-1995 at 12:14:46 pm'!

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

version
"
$Header: /cvs/stx/stx/libview2/LayoutFrame.st,v 1.7 1995-08-29 17:44:07 claus Exp $
"
! !

!LayoutFrame methodsFor:'accessing'!

rightFraction:something
    "set rightFraction"

    rightFraction := something.
!

rightFraction
    "return rightFraction"

    ^ rightFraction
!

rightOffset:something
    "set rightOffset"

    rightOffset := something.
!

rightOffset
    "return rightOffset"

    ^ rightOffset
!

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

    rightFraction := something.
    rightOffset := o
!

bottomFraction:something
    "set bottomFraction"

    bottomFraction := something.
!

bottomFraction
    "return bottomFraction"

    ^ bottomFraction
!

bottomOffset:something
    "set bottomOffset"

    bottomOffset := something.
!

bottomOffset
    "return bottomOffset"

    ^ bottomOffset
!

bottomFraction:something offset:o
    "set bottomFraction and offset"

    bottomFraction := something.
    bottomOffset := o
! !


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

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

corner
    ^ rightFraction asFloat @ bottomFraction asFloat
! !

!LayoutFrame methodsFor:'initialization'!

initialize
    leftOffset := rightOffset := bottomOffset := topOffset := 0.
    leftFraction := topFraction := 0.
    bottomFraction := rightFraction := 1.
! !