fillBackgroundStyle method

void fillBackgroundStyle(
  1. Rect bounds,
  2. Style style,
  3. BlendOption blend
)

Fills the background style of all cells in bounds using blend.

Implementation

void fillBackgroundStyle(Rect bounds, Style style, BlendOption blend) {
  final bgVal = style.background?.argb ?? 0;
  final styleMods = style.modifiers;
  for (var y = bounds.y; y < bounds.y + bounds.height; y++) {
    if (y < 0 || y >= height) continue;
    final rowOffset = y * width;
    for (var x = bounds.x; x < bounds.x + bounds.width; x++) {
      if (x < 0 || x >= width) continue;
      final idx = rowOffset + x;
      final attrIdx = idx * 3;
      if (blend == BlendOption.replace) {
        attributes[attrIdx + 0] = style.foreground?.argb ?? 0;
        attributes[attrIdx + 1] = bgVal;
        attributes[attrIdx + 2] = styleMods;
      } else if (blend == BlendOption.colorOnly) {
        if (bgVal != 0) {
          attributes[attrIdx + 1] = bgVal;
        }
      } else if (blend == BlendOption.addModifiers) {
        attributes[attrIdx + 2] |= styleMods;
      }
    }
  }
}