computeAbsolutePaintOffsetFor method

  1. @protected
Offset computeAbsolutePaintOffsetFor(
  1. RenderBox child,
  2. {required Offset layoutOffset}
)

The offset at which the given child should be painted.

The returned offset is from the top left corner of the inside of the viewport to the top left corner of the paint coordinate system of the child.

This is useful when the one or both of the axes of the viewport are reversed. The normalized layout offset of the child is used to compute the paint offset in relation to the verticalAxisDirection and horizontalAxisDirection.

Implementation

@protected
Offset computeAbsolutePaintOffsetFor(
  RenderBox child, {
  required Offset layoutOffset,
}) {
  // This is only usable once we have sizes.
  assert(hasSize);
  assert(child.hasSize);
  final double xOffset = switch (horizontalAxisDirection) {
    AxisDirection.right => layoutOffset.dx,
    AxisDirection.left => viewportDimension.width - (layoutOffset.dx + child.size.width),
    AxisDirection.up || AxisDirection.down => throw Exception('This should not happen'),
  };
  final double yOffset = switch (verticalAxisDirection) {
    AxisDirection.up => viewportDimension.height - (layoutOffset.dy + child.size.height),
    AxisDirection.down => layoutOffset.dy,
    AxisDirection.right || AxisDirection.left => throw Exception('This should not happen'),
  };
  return Offset(xOffset, yOffset);
}