getLineLayout method
Gets the layout parameters (width and x-offset) for a line at a specific Y position. Returns null if the line is outside the displayable area.
Implementation
@override
({int width, int xOffset})? getLineLayout(double lineY, double lineHeight) {
// Calculate the vertical distance from the center of the circle to the middle of the line.
final double distFromCenter = (lineY + lineHeight / 2) - centerY;
if (distFromCenter.abs() > radius) {
return null; // Line is completely outside the circle.
}
// Use the Pythagorean theorem to calculate the half-width of the chord at this y-position.
final double halfWidth = math.sqrt(radius * radius - distFromCenter * distFromCenter);
final int lineWidth = (halfWidth * 2).floor();
final int xOffset = (centerX - halfWidth).floor();
// Avoid rendering text on very narrow lines near the top/bottom of the circle.
if (lineWidth < fontSize) return null;
return (width: lineWidth, xOffset: xOffset);
}