fillRect function

void fillRect(
  1. Screen screen,
  2. Rectangle area,
  3. int x,
  4. int y,
  5. int w,
  6. int h,
  7. UvStyle style,
)

Fills a rectangular region on screen with style as the background.

Implementation

void fillRect(
  Screen screen,
  Rectangle area,
  int x,
  int y,
  int w,
  int h,
  UvStyle style,
) {
  final bg = style.bg ?? style.fg;
  if (bg == null) return;
  final fill = UvStyle(fg: bg, bg: bg);
  final startX = math.max(x, area.minX);
  final startY = math.max(y, area.minY);
  final maxX = math.min(x + w, area.maxX);
  final maxY = math.min(y + h, area.maxY);
  for (var py = startY; py < maxY; py++) {
    for (var px = startX; px < maxX; px++) {
      putCell(screen, px, py, ' ', fill);
    }
  }
}