tailPath function

Path tailPath({
  1. required TailSide side,
  2. required Size tooltipSize,
  3. required Rect hole,
  4. required Rect tooltip,
  5. double length = _kTailLength,
  6. double width = _kTailWidth,
})

Triangle of the tail in tooltip-local coordinates.

tooltip — the tooltip's rect in the same (global) space as hole, to derive the hole's center in local coordinates; tooltipSize — the painter's canvas size (== the tooltip's size). The base sits on the tooltip's edge (half a pixel inside, so the opaque tooltip surface covers the seam); the apex extends length beyond it, toward the hole.

Implementation

Path tailPath({
  required TailSide side,
  required Size tooltipSize,
  required Rect hole,
  required Rect tooltip,
  double length = _kTailLength,
  double width = _kTailWidth,
}) {
  final half = width / 2;
  // Center along the parallel axis (shared by the two sides on each axis).
  final along = side == TailSide.top || side == TailSide.bottom
      ? _clampCenter(hole.center.dx - tooltip.left, tooltipSize.width, half)
      : _clampCenter(hole.center.dy - tooltip.top, tooltipSize.height, half);
  final path = Path();
  switch (side) {
    case TailSide.bottom:
      path
        ..moveTo(along - half, tooltipSize.height - 0.5)
        ..lineTo(along + half, tooltipSize.height - 0.5)
        ..lineTo(along, tooltipSize.height + length)
        ..close();
    case TailSide.top:
      path
        ..moveTo(along - half, 0.5)
        ..lineTo(along + half, 0.5)
        ..lineTo(along, -length)
        ..close();
    case TailSide.left:
      path
        ..moveTo(0.5, along - half)
        ..lineTo(0.5, along + half)
        ..lineTo(-length, along)
        ..close();
    case TailSide.right:
      path
        ..moveTo(tooltipSize.width - 0.5, along - half)
        ..lineTo(tooltipSize.width - 0.5, along + half)
        ..lineTo(tooltipSize.width + length, along)
        ..close();
  }
  return path;
}