bufferDrawBox method

void bufferDrawBox(
  1. OptimizedBufferHandle buffer,
  2. int x,
  3. int y,
  4. int width,
  5. int height,
  6. BoxOptions options,
  7. Color borderColor,
  8. Color backgroundColor,
)

Draws a box with optional title.

Implementation

void bufferDrawBox(
  OptimizedBufferHandle buffer,
  int x,
  int y,
  int width,
  int height,
  BoxOptions options,
  Color borderColor,
  Color backgroundColor,
) {
  _checkSigned32Abi(x, 'x');
  _checkSigned32Abi(y, 'y');
  _checkUnsignedAbi(width, 0xFFFFFFFF, 'width');
  _checkUnsignedAbi(height, 0xFFFFFFFF, 'height');
  validateColorChannels(borderColor, name: 'borderColor');
  validateColorChannels(backgroundColor, name: 'backgroundColor');
  const defaults = <int>[
    0x250C,
    0x2510,
    0x2514,
    0x2518,
    0x2500,
    0x2502,
    0x252C,
    0x2534,
    0x251C,
    0x2524,
    0x253C,
  ];
  final borderChars = options.borderChars ?? defaults;
  for (final character in borderChars) {
    _checkUnsignedAbi(character, 0xFFFFFFFF, 'borderChars');
  }
  _guardAlloc('Failed to draw box', (allocator) {
    final nativeBorderChars = allocator<Uint32>(11);
    nativeBorderChars.asTypedList(11).setAll(0, borderChars);
    final (title, titleLength) = _utf8(allocator, options.title ?? '');
    final nativeBorderColor = _colorToNative(borderColor, allocator);
    _native.bufferDrawBox(
      buffer.value,
      x,
      y,
      width,
      height,
      nativeBorderChars,
      _boxOptionsToNative(options),
      nativeBorderColor,
      _colorToNative(backgroundColor, allocator),
      nativeBorderColor,
      title,
      titleLength,
    );
  });
}