text method

TextDrawer<App> text(
  1. String content, [
  2. ColorD? color
])

Draws content at the current cursor and advances horizontally.

Implementation

TextDrawer text(String content, [ColorD? color]) {
  final width = backend.render.measureText(content, _fontSize);

  final drawX = switch (_halign) {
    .left => _x,
    .center => _x - width / 2,
    .right => _x - width,
  };

  final drawY = switch (_valign) {
    .top => _y,
    .middle => _y - _fontSize / 2,
    .bottom => _y - _fontSize,
  };

  backend.render.drawText(content, drawX, drawY, _fontSize, color ?? .WHITE);

  if (_halign == .left) {
    _x += width + _wordSpacing;
  }

  return this;
}