render method

  1. @override
void render(
  1. CanvasBuffer buffer,
  2. Rect bounds
)
override

Renders the component into the provided CanvasBuffer using the given bounds as the drawing area.

Implementation

@override
void render(CanvasBuffer buffer, Rect bounds) {
  Logger.trace("Checkbox", "Checkbox is being called and drawn");

  // Determine checkbox symbol based on state
  String checkbox = (checked) ? '[X]' : '[ ]';
  if ((isFocused || isHovered) && checked) {
    checkbox = '[-]';
  } else if ((isFocused || isHovered) && !checked) {
    checkbox = '[.]';
  }

  // Full string to render
  final renderedComponent = '$checkbox ${component.label}';

  // Add fixed width padding if configured
  final padded = '$renderedComponent${' ' * component.width}';

  // Determine style based on state
  TextComponentStyle style = TextComponentStyle(
    color: component.textColor ?? Colors.white,
  );
  if (checked) {
    style = TextComponentStyle(
      color: component.textColor ?? Colors.white,
      bgColor: component.selectionColor ?? Colors.black,
      padding: EdgeInsets.symmetric(horizontal: component.width),
    );
  } else if (isHovered || isFocused) {
    style = TextComponentStyle(
      color: component.textColor ?? Colors.white,
      bgColor: component.hoverColor ?? Colors.black,
      padding: EdgeInsets.symmetric(horizontal: component.width),
    );
  }

  // Draw checkbox at position
  buffer.drawAt(bounds.x, bounds.y, padded, style);
}