render method

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

Renders the underlying widget to the provided buffer within the area.

Implementation

@override
void render(Buffer buffer, Rect area) {
  final borderWidget = widget as LeftBorder;
  final padding = borderWidget.padding;
  final requiredWidth = 1 + padding.left + padding.right;
  final requiredHeight = padding.top + padding.bottom;
  if (area.width <= requiredWidth || area.height <= requiredHeight) return;

  final limit = borderWidget.borderHeight ?? area.height;
  // 1. Draw the vertical line on the left
  for (var y = 0; y < area.height; y++) {
    final cellChar = y < limit ? borderWidget.char : ' ';
    final cell = buffer.getCell(area.x, area.y + y);
    if (cell != null) {
      cell.char = cellChar;
      cell.style = borderWidget.style;
    }
  }

  // 2. Render the child in the remaining area
  final childX = area.x + 1 + padding.left;
  final childWidth = area.width - 1 - padding.left - padding.right;
  final childY = area.y + padding.top;
  final childHeight = area.height - padding.top - padding.bottom;
  final childArea = Rect(childX, childY, childWidth, childHeight);

  if (childElement != null &&
      childElement!.widget.runtimeType == borderWidget.child.runtimeType) {
    childElement!.update(borderWidget.child);
  } else {
    childElement = borderWidget.child.createElement();
    childElement!.mount(this);
  }

  final childViewport = Viewport(buffer, childArea);
  childElement!.render(childViewport, Rect(0, 0, childWidth, childHeight));
}