place static method

void place(
  1. LayoutItem item,
  2. Vector2 position
)

Positions item so its content's top-left corner lands at position, honoring item's own anchor and scale.

Implementation

static void place(LayoutItem item, Vector2 position) {
  final size = item.size;
  final scale = item.scale;
  final anchor = item.anchor;

  // The anchor offset is applied in the item's own space, so it arrives here
  // scaled. A flipped axis grows the other way, which puts its anchor on the
  // opposite edge. Without that, the content lands outside its own space.
  final anchorX = scale.x < 0 ? anchor.x - 1 : anchor.x;
  final anchorY = scale.y < 0 ? anchor.y - 1 : anchor.y;

  item.position.setValues(
    anchorX * size.x * scale.x + position.x,
    anchorY * size.y * scale.y + position.y,
  );
}