shift property

Offset get shift

Where the box is drawn from where it was laid out.

Implementation

Offset get shift {
  if (!hasSize || !attached) return Offset.zero;
  RenderBox? port;
  HoldsSticky? block;
  for (var p = parent; p != null; p = p.parent) {
    if (block == null && p is HoldsSticky) block = p;
    if (p is RenderBox) port = p;
    if (p is RenderScrollPort) continue;
    if (p is RenderAbstractViewport || p is RenderStickyPort) break;
  }
  if (port == null || !port.hasSize) return Offset.zero;
  final at = MatrixUtils.transformPoint(getTransformTo(port), Offset.zero);
  final room = port.size;
  double toward(double d, double room) => d > 0 ? math.min(d, math.max(0.0, room)) : math.max(d, math.min(0.0, room));
  final top = _inset(_top, _topShare, room.height), bottom = _inset(_bottom, _bottomShare, room.height);
  final left = _inset(_left, _leftShare, room.width), right = _inset(_right, _rightShare, room.width);
  var dy = 0.0, dx = 0.0;
  if (top case final t?) dy = math.max(0.0, t - at.dy);
  if (dy == 0.0 && bottom != null) dy = math.min(0.0, (room.height - bottom) - (at.dy + size.height));
  if (left case final l?) dx = math.max(0.0, l - at.dx);
  if (dx == 0.0 && right != null) dx = math.min(0.0, (room.width - right) - (at.dx + size.width));
  if (block != null && block.hasSize) {
    final b = MatrixUtils.transformPoint(block.getTransformTo(port), Offset.zero);
    final e = block.inset;
    dy = toward(
      dy,
      dy > 0
          ? (b.dy + block.size.height - e.bottom - _margin.bottom) - (at.dy + size.height)
          : (b.dy + e.top + _margin.top) - at.dy,
    );
    dx = toward(
      dx,
      dx > 0
          ? (b.dx + block.size.width - e.right - _margin.right) - (at.dx + size.width)
          : (b.dx + e.left + _margin.left) - at.dx,
    );
  }
  return Offset(dx, dy);
}