tailPath function
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;
final path = Path();
switch (side) {
case TailSide.bottom:
final cx =
_clampCenter(hole.center.dx - tooltip.left, tooltipSize.width, half);
path
..moveTo(cx - half, tooltipSize.height - 0.5)
..lineTo(cx + half, tooltipSize.height - 0.5)
..lineTo(cx, tooltipSize.height + length)
..close();
case TailSide.top:
final cx =
_clampCenter(hole.center.dx - tooltip.left, tooltipSize.width, half);
path
..moveTo(cx - half, 0.5)
..lineTo(cx + half, 0.5)
..lineTo(cx, -length)
..close();
case TailSide.left:
final cy =
_clampCenter(hole.center.dy - tooltip.top, tooltipSize.height, half);
path
..moveTo(0.5, cy - half)
..lineTo(0.5, cy + half)
..lineTo(-length, cy)
..close();
case TailSide.right:
final cy =
_clampCenter(hole.center.dy - tooltip.top, tooltipSize.height, half);
path
..moveTo(tooltipSize.width - 0.5, cy - half)
..lineTo(tooltipSize.width - 0.5, cy + half)
..lineTo(tooltipSize.width + length, cy)
..close();
}
return path;
}