resolve method

Offset resolve(
  1. Size containerSize,
  2. Size lensSize
)

Resolves the position to an absolute Offset based on the container size.

Implementation

Offset resolve(Size containerSize, Size lensSize) {
  if (_offset != null) return _offset;
  if (_alignment != null) {
    // Calculate center of the container
    final centerX = containerSize.width / 2;
    final centerY = containerSize.height / 2;

    // Calculate the alignment offset from the center
    final shiftX = (containerSize.width / 2) * _alignment.x;
    final shiftY = (containerSize.height / 2) * _alignment.y;

    // Top-left of the lens to center it on the alignment point
    return Offset(
      centerX + shiftX - (lensSize.width / 2),
      centerY + shiftY - (lensSize.height / 2),
    );
  }
  return Offset.zero;
}