paint method
void
paint({
- required HMOrientation orientation,
- required RenderBox parentBox,
- required Canvas canvas,
- required Offset center,
- required double scale,
- required TextPainter labelPainter,
- required double textScaleFactor,
- required Size sizeWithOverflow,
- required Color backgroundPaintColor,
- Color? strokePaintColor,
Implementation
void paint({
required HMOrientation orientation,
required RenderBox parentBox,
required Canvas canvas,
required Offset center,
required double scale,
required TextPainter labelPainter,
required double textScaleFactor,
required Size sizeWithOverflow,
required Color backgroundPaintColor,
Color? strokePaintColor,
}) {
if (scale == 0.0) {
// Zero scale essentially means "do not draw anything", so it's safe to just return.
return;
}
final double rectangleWidth =
_upperRectangleWidth(labelPainter, scale, textScaleFactor);
final double horizontalShift = getHorizontalShift(
parentBox: parentBox,
center: center,
labelPainter: labelPainter,
textScaleFactor: textScaleFactor,
sizeWithOverflow: sizeWithOverflow,
scale: scale,
);
final double rectHeight = labelPainter.height + _labelPadding;
final Rect upperRect = Rect.fromLTWH(
-rectangleWidth / 2 + horizontalShift,
-_triangleHeight - rectHeight,
rectangleWidth,
rectHeight,
);
final Paint fillPaint = Paint()..color = backgroundPaintColor;
final RRect upperRRect = RRect.fromRectAndRadius(
upperRect, const Radius.circular(_upperRectRadius));
canvas.save();
// Prepare the canvas for the base of the tooltip, which is relative to the
// center of the thumb.
if (orientation == HMOrientation.vertical) {
canvas
..rotate(math.pi / 2)
..translate(-center.dy - labelPainter.height,
-center.dx + (_labelPadding * 1.5));
} else {
canvas.translate(center.dx, center.dy - _bottomTipYOffset);
}
canvas.scale(scale, scale);
canvas.drawRRect(upperRRect, fillPaint);
// The label text is centered within the value indicator.
final double bottomTipToUpperRectTranslateY =
-_preferredHalfHeight / 2 - upperRect.height;
canvas.translate(0, bottomTipToUpperRectTranslateY);
final Offset boxCenter = Offset(horizontalShift, upperRect.height / 2);
final Offset halfLabelPainterOffset =
Offset(labelPainter.width / 2, labelPainter.height / 2);
final Offset labelOffset = boxCenter - halfLabelPainterOffset;
labelPainter.paint(canvas, labelOffset);
canvas.restore();
}