render method

  1. @override
void render(
  1. Buffer buffer,
  2. Rect area
)
override

Renders the widget onto the provided buffer within the specified area.

Implementation

@override
void render(Buffer buffer, Rect area) {
  if (area.width <= 0 || area.height <= 0) return;

  final allStyledChars = <StyledChar>[];
  text.buildStyledChars(allStyledChars, Style.empty);

  final lines = wrap
      ? _wrapStyledChars(allStyledChars, area.width)
      : _clipStyledChars(allStyledChars, area.width);

  final limit = maxLines != null ? min(maxLines!, area.height) : area.height;
  for (var y = 0; y < lines.length; y++) {
    if (y >= limit) break;
    final line = lines[y];

    // Compute horizontal alignments
    final lineLen = line.length;
    var startX = 0;
    if (textAlign == TextAlign.right) {
      startX = max(0, area.width - lineLen);
    } else if (textAlign == TextAlign.center) {
      startX = max(0, (area.width - lineLen) ~/ 2);
    }

    for (var x = 0; x < line.length; x++) {
      if (startX + x >= area.width) break;
      final cell = buffer.getCell(startX + x, y);
      if (cell != null) {
        cell.char = line[x].char;
        cell.style = line[x].style;
      }
    }
  }
}