Add Anchor.Opposite() func
This commit is contained in:
parent
2342984744
commit
c9681cec8a
17
geometry.go
17
geometry.go
|
@ -579,6 +579,23 @@ func (anchor Anchor) String() string {
|
|||
return anchorStrings[anchor]
|
||||
}
|
||||
|
||||
var oppositeAnchors map[Anchor]Anchor = map[Anchor]Anchor{
|
||||
Center: Center,
|
||||
Top: Bottom,
|
||||
Bottom: Top,
|
||||
Right: Left,
|
||||
Left: Right,
|
||||
TopRight: BottomLeft,
|
||||
BottomLeft: TopRight,
|
||||
BottomRight: TopLeft,
|
||||
TopLeft: BottomRight,
|
||||
}
|
||||
|
||||
// Opposite returns the opposite position of the anchor (ie. Top -> Bottom; BottomLeft -> TopRight, etc.).
|
||||
func (anchor Anchor) Opposite() Anchor {
|
||||
return oppositeAnchors[anchor]
|
||||
}
|
||||
|
||||
// AnchorPos returns the relative position of the given anchor.
|
||||
func (r Rect) AnchorPos(anchor Anchor) Vec {
|
||||
return r.Size().ScaledXY(V(0, 0).Sub(Vec(anchor)))
|
||||
|
|
Loading…
Reference in New Issue