Skip to content

Commit

Permalink
feat(2d): universal getter for cardinal points (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarthificial committed Mar 11, 2024
1 parent 491080d commit f7e53ec
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/2d/src/lib/components/Layout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BBox,
boolLerp,
Direction,
InterpolationFunction,
modify,
Origin,
Expand Down Expand Up @@ -627,6 +628,38 @@ export class Layout extends Node {
@originSignal(Origin.BottomRight)
public declare readonly bottomRight: SimpleVector2Signal<this>;

/**
* Get the cardinal point corresponding to the given origin.
*
* @param origin - The origin or direction of the point.
*/
public cardinalPoint(origin: Origin | Direction): SimpleVector2Signal<this> {
switch (origin) {
case Origin.TopLeft:
return this.topLeft;
case Origin.TopRight:
return this.topRight;
case Origin.BottomLeft:
return this.bottomLeft;
case Origin.BottomRight:
return this.bottomRight;
case Origin.Top:
case Direction.Top:
return this.top;
case Origin.Bottom:
case Direction.Bottom:
return this.bottom;
case Origin.Left:
case Direction.Left:
return this.left;
case Origin.Right:
case Direction.Right:
return this.right;
default:
return this.middle;
}
}

@initial(false)
@signal()
public declare readonly clip: SimpleSignal<boolean, this>;
Expand Down

0 comments on commit f7e53ec

Please sign in to comment.