Skip to main content

Function: resolveRect()

resolveRect(parentRect, rectTransform, pixelsPerUnit?): Rect

Defined in: ui/utilities/resolve-rect.ts:64

Resolves a RectTransformEcsComponent's rect against its parent's already-resolved rect. Pure - takes no EcsWorld/entity, reads no other state - so the entire anchor/pivot/stretch surface is unit-testable in isolation.

x and y are resolved independently by resolveAxis, since each is its own UiPointAxis (literal size, moves with the anchor) or UiStretchAxis (resizes with the parent, margin added to the anchored span) - a mixed anchor (e.g. UiAnchor.stretchTop, stretched horizontally but point-anchored vertically) simply resolves each axis under its own rule.

Parameters​

parentRect​

Rect

The parent's already-resolved rect, in UI world space.

rectTransform​

RectTransformDefaultedOptions

The rect transform to resolve.

pixelsPerUnit?​

number = 1

The owning canvas's live reference-pixel-to-screen-pixel ratio (see calculatePixelsPerUnit), used to convert a 'screenPixels'-unit size/margin (see UiAxisSizeUnit) into reference pixels. Defaults to 1 - a neutral value under which 'screenPixels' behaves exactly like 'referencePixels' - for callers that don't track a live ratio.

Returns​

Rect

The resolved rect, in the same UI world space as parentRect.