draw method

void draw(
  1. Screen screen,
  2. Rectangle area
)

Draws this buffer onto screen at the specified area.

Upstream: third_party/ultraviolet/buffer.go (Buffer.Draw).

Implementation

void draw(Screen screen, Rectangle area) {
  if (area.isEmpty) return;
  final bounds = screen.bounds();
  if (area.minX < bounds.minX ||
      area.minY < bounds.minY ||
      area.maxX > bounds.maxX ||
      area.maxY > bounds.maxY) {
    return;
  }

  for (var y = area.minY; y < area.maxY; y++) {
    var x = area.minX;
    while (x < area.maxX) {
      final c = cellAt(x - area.minX, y - area.minY);
      if (c == null || c.isZero) {
        x++;
        continue;
      }
      screen.setCell(x, y, c);
      x += c.width > 0 ? c.width : 1;
    }
  }
}