|
Class: LayoutOrigin
Object
|
+--Layout
|
+--LayoutOrigin
|
+--AlignmentOrigin
|
+--LayoutFrame
- Package:
- stx:libview2
- Category:
- Graphics-Geometry
- Version:
- rev:
1.35
date: 2022/01/12 17:32:51
- user: cg
- file: LayoutOrigin.st directory: libview2
- module: stx stc-classLibrary: libview2
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. It provides the same functionality as a relative origin
combined with insets.
A layoutOrigin controls the origin of a subcomponent, given a fractional
component and an offset component.
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.
copyrightCOPYRIGHT (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.
instance creation
-
fractionalFromPoint: aPoint
-
given a point, create a layoutOrigin representing the same
relative origin.
Usage example(s):
LayoutOrigin fractionalFromPoint:0.5@0.5
|
-
fromPoint: aPoint
-
return a new LayoutOrigin from aPoint.
If the coordinates are between 0 and 1,
take them as fractional parts (relative to superview).
Otherwise, treat them as absolute offsets.
Usage example(s):
LayoutOrigin fromPoint:100@100
LayoutOrigin fromPoint:0.5@0.5
LayoutOrigin fromPoint:0.5@100
|
-
offsetFromPoint: aPoint
-
given a point, create a layoutOrigin representing the same
absolute (pixel) origin.
Usage example(s):
LayoutOrigin offsetFromPoint:100@100
|
accessing
-
leftFraction
-
return leftFraction
-
leftFraction: aFraction
-
set leftFraction (0..1)
-
leftFraction: aFraction offset: o
-
set leftFraction (0..1) and offset in pixels
-
leftFraction: lF offset: lO topFraction: tF offset: tO
-
set leftFraction (0..1), leftOffset, topFraction (0..1) and topOffset
-
leftFraction: newLeft topFraction: newTop
-
set leftFraction (0..1) and topFraction (0..1)
-
leftInset: pixels
-
set leftOffset for an inset at the left
-
leftOffset
-
return leftOffset
-
leftOffset: something
-
set leftOffset
-
leftOffset: newLeft topOffset: newTop
-
set leftOffset and topOffset
-
offset: aPoint
-
set both left and top offsets
-
topFraction
-
return topFraction
-
topFraction: aFraction
-
set topFraction (0..1)
-
topFraction: aFraction offset: o
-
set topFraction (0..1) and offset
-
topInset: pixels
-
set topOffset for an inset at the top
-
topOffset
-
return topOffset
-
topOffset: something
-
set topOffset
comparing
-
= anObject
-
(comment from inherited method)
return true if the receiver and the arg have the same structure.
Notice:
This method is partially open coded (inlined) by the compiler(s)
identical objects are always considered equal.
redefining it may not work as expected.
-
hash
-
(comment from inherited method)
return an Integer useful as a hash key for the receiver.
This hash should return same values for objects with same
contents (i.e. use this to hash on structure)
computing
-
rectangleRelativeTo: superRectangle preferred: prefRectHolder
-
compute the rectangle represented by the receiver,
given the superView's rectangle and the view's preferredExtent.
Usage example(s):
|superRect lO|
superRect := 0@0 corner:100@100.
lO := (LayoutOrigin new).
lO leftFraction:0.5;
topFraction:0.5.
lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
|
converting
-
asAlignmentOrigin
-
return an equivalent alignmentOrigin
-
fromLiteralArrayEncoding: encoding
-
read my values from an encoding.
The encoding is supposed to be of the form:
(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
This is the reverse operation to #literalArrayEncoding.
Usage example(s):
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
|
-
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)
Usage example(s):
LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
(LayoutOrigin new leftOffset:10; leftFraction:0.2;
topOffset:20; topFraction:0.4) literalArrayEncoding
|
initialization
-
initialize
-
(comment from inherited method)
setup the instance - to be redefined by concrete subclasses
printing & storing
-
displayOn: aGCOrStream
-
return a printed representation of the receiver for displaying
queries
-
isLayoutOrigin
-
return true, if this is a layoutOrigin
-
origin
-
Although the examples below use a button as component,
they work of course with any type of subview ....
using a LayoutOrigin, to arrange for
the TOPLEFT of a component be positions
at the center (i.e. buttons origin at:0.5 @ 0.5):
|top button|
top := StandardSystemView new.
top extent:300@300.
button := Button label:'component'.
top add:button in:(LayoutOrigin new
leftFraction:0.5;
topFraction:0.5).
top open
|
like above, but adds an additional offset:
(i.e. center of button at:0.5 @ 0.5 OFFSET by 10 @ 20):
|top button|
top := StandardSystemView new.
top extent:300@300.
button := Button label:'component'.
top add:button in:(LayoutOrigin new
leftFraction:0.5;
topFraction:0.5;
leftOffset:10;
topOffset:20).
top open
|
|