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) {
    if (cell == null) {
      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].resetToEmpty(x);
        }
      }
    } else {
      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, cell);
        }
      }
    }
    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);
    }
  }
}