drawFaceInfoLabel function
void
drawFaceInfoLabel(})
Draws faceInfoLabelText for face as a translucent card anchored just
above faceRect (falling back to inside its top edge when there is no
room), clamped to canvasSize.
Implementation
void drawFaceInfoLabel(
Canvas canvas,
Size canvasSize,
Face face,
Rect faceRect, {
bool showClassification = false,
}) {
final TextPainter tp = TextPainter(
text: TextSpan(
text: faceInfoLabelText(face, showClassification: showClassification),
style: const TextStyle(
color: Colors.white,
fontSize: 11,
height: 1.35,
fontWeight: FontWeight.w600,
),
),
textDirection: TextDirection.ltr,
)..layout();
const double padH = 6;
const double padV = 4;
const double gap = 4;
final double boxW = tp.width + padH * 2;
final double boxH = tp.height + padV * 2;
double left = faceRect.left;
double top = faceRect.top - gap - boxH;
if (top < 0) top = faceRect.top + gap;
if (left + boxW > canvasSize.width) left = canvasSize.width - boxW;
if (left < 0) left = 0;
if (top + boxH > canvasSize.height) {
top = math.max(0, canvasSize.height - boxH);
}
canvas.drawRRect(
RRect.fromRectAndRadius(
Rect.fromLTWH(left, top, boxW, boxH),
const Radius.circular(4),
),
Paint()..color = const Color(0xB3000000),
);
tp.paint(canvas, Offset(left + padH, top + padV));
}