bufferDrawBox method

void bufferDrawBox(
  1. Pointer<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 width×height box at (x,y) into buffer using the border glyphs, packed flags, and optional title from options, with borderColor and backgroundColor. Defaults to single-line border chars when options does not supply all 11. Throws FFIException on failure.

Implementation

void bufferDrawBox(
  Pointer<OptimizedBufferHandle> buffer,
  int x,
  int y,
  int width,
  int height,
  BoxOptions options,
  Color borderColor,
  Color backgroundColor,
) {
  _guardAlloc('Failed to draw box', (alloc) {
    // OpenTUI expects 11 code points in this order:
    // [topLeft, topRight, bottomLeft, bottomRight, horizontal, vertical, topT, bottomT, leftT, rightT, cross]
    const defaultBorderChars = <int>[
      0x250C, // ┌ top-left
      0x2510, // ┐ top-right
      0x2514, // └ bottom-left
      0x2518, // ┘ bottom-right
      0x2500, // ─ horizontal
      0x2502, // │ vertical
      0x252C, // ┬ top T
      0x2534, // ┴ bottom T
      0x251C, // ├ left T
      0x2524, // ┤ right T
      0x253C, // ┼ cross
    ];

    final provided = options.borderChars;
    final borderChars = (provided != null && provided.length == 11)
        ? provided
        : defaultBorderChars;

    final borderPtr = alloc<Uint32>(borderChars.length);
    for (var i = 0; i < borderChars.length; i++) {
      borderPtr[i] = borderChars[i];
    }

    final (titlePtr, titleLen) = _utf8(alloc, options.title ?? '');

    _generated.bufferDrawBox(
      buffer.cast(),
      x,
      y,
      width,
      height,
      borderPtr,
      options.packedOptions,
      borderColor.toNative(alloc),
      backgroundColor.toNative(alloc),
      titlePtr,
      titleLen,
    );
  });
}