render method
Renders the widget onto the provided buffer within the specified area.
Implementation
@override
void render(Buffer buffer, Rect area) {
Tracer.record(_traceCanvasRenderId, Phase.begin);
try {
var currentBuffer = buffer;
var startX = 0;
var startY = 0;
while (currentBuffer is Viewport) {
startX += currentBuffer.bounds.x;
startY += currentBuffer.bounds.y;
currentBuffer = currentBuffer.parent;
}
final targetBuffer = currentBuffer;
final targetWidth = targetBuffer.width;
final targetHeight = targetBuffer.height;
final targetCells = targetBuffer.cells;
for (var cy = 0; cy < height; cy++) {
final ty = startY + cy;
if (ty < 0 || ty >= targetHeight) continue;
for (var cx = 0; cx < width; cx++) {
final tx = startX + cx;
if (tx < 0 || tx >= targetWidth) continue;
if (isOccluded != null && isOccluded!(cx, cy)) continue;
final idx = cy * width + cx;
final dots = _grid[idx];
if (dots == 0 && _styles[idx] == null && style == Style.empty) {
continue;
}
final String char;
if (renderMode == CanvasRenderMode.quadrants) {
char = _quadrantCache[dots];
} else if (renderMode == CanvasRenderMode.density ||
_antiAliased[idx] == 1) {
char = _densityCache[dots];
} else {
char = _brailleCache[dots];
}
final targetIdx = ty * targetWidth + tx;
final cell = targetCells[targetIdx];
cell.char = char;
final s = _styles[idx];
if (s != null) {
cell.style = Style(
foreground: s.foreground ?? style.foreground,
background: s.background ?? style.background,
modifiers: s.modifiers | style.modifiers,
);
} else {
cell.style = style;
}
}
}
} finally {
Tracer.record(_traceCanvasRenderId, Phase.end);
}
}