paintGrid method
void
paintGrid(
- Canvas canvas,
- NodeFlowTheme theme,
- ({double bottom, double left, double right, double top}) gridArea
override
Renders the style-specific grid pattern.
Each grid style implements this method to draw its specific pattern
(lines, dots, crosses, etc.) using the pre-calculated gridArea.
Parameters:
canvas: The canvas to paint ontheme: Theme containing grid configurationgridArea: Pre-calculated grid-aligned area covering the visible region
Implementation
@override
void paintGrid(
Canvas canvas,
NodeFlowTheme theme,
({double left, double top, double right, double bottom}) gridArea,
) {
final gridTheme = theme.gridTheme;
final gridSize = gridTheme.size;
// Create paint for the crosses
final paint = createGridPaint(theme)
..strokeWidth = gridTheme.thickness.clamp(0.5, 1.5);
// Calculate arm length
final armLength = crossSize ?? (gridTheme.thickness * 3).clamp(2.0, 6.0);
// Calculate grid-aligned start positions
final startX = (gridArea.left / gridSize).floor() * gridSize;
final startY = (gridArea.top / gridSize).floor() * gridSize;
// Draw crosses at each grid intersection
for (double x = startX; x <= gridArea.right; x += gridSize) {
for (double y = startY; y <= gridArea.bottom; y += gridSize) {
// Draw horizontal arm
canvas.drawLine(
Offset(x - armLength, y),
Offset(x + armLength, y),
paint,
);
// Draw vertical arm
canvas.drawLine(
Offset(x, y - armLength),
Offset(x, y + armLength),
paint,
);
}
}
}