fillArea method

void fillArea(
  1. Cell? cell,
  2. Rectangle area
)

Fills the buffer with cell within area.

Note: we step by cell width to avoid repeatedly overwriting wide-cell placeholders.

Implementation

void fillArea(Cell? cell, Rectangle area) {
  final clipped = area.intersect(bounds());
  if (clipped.isEmpty) return;

  final opaqueSingleWidth =
      (cell == null || !_hasTranslucentOverlay(cell.style)) &&
      (cell == null || cell.width <= 1);
  if (opaqueSingleWidth) {
    final fillCell = cell ?? Cell.emptyCell();
    for (var y = clipped.minY; y < clipped.maxY; y++) {
      touchLine(clipped.minX, y, clipped.width);
      for (var x = clipped.minX; x < clipped.maxX; x++) {
        lines[y].replaceWithClone(x, fillCell);
      }
    }
    return;
  }

  var cellWidth = 1;
  if (cell.width > 1) cellWidth = cell.width;
  for (var y = clipped.minY; y < clipped.maxY; y++) {
    for (var x = clipped.minX; x < clipped.maxX; x += cellWidth) {
      setCell(x, y, cell);
    }
  }
}