isPositionOnTitle method

  1. @override
bool isPositionOnTitle(
  1. int localX,
  2. int localY
)
override

Returns true if the local coordinates localX and localY lie on the title text.

Implementation

@override
bool isPositionOnTitle(int localX, int localY) {
  if (localY != dialogBounds.y || title.isEmpty) return false;
  final w = dialogBounds.width;
  if (w < 2) return false;

  final titleChars = title.characters;
  final maxTitleLen = w - 4;
  String displayedTitle;
  if (titleChars.length > maxTitleLen) {
    final cutLen = w - 7;
    if (cutLen > 0) {
      displayedTitle = ' ${titleChars.take(cutLen).toString()}... ';
    } else {
      displayedTitle = '';
    }
  } else {
    displayedTitle = ' $title ';
  }

  if (displayedTitle.isEmpty) return false;
  final dispChars = displayedTitle.characters;
  final titleX =
      dialogBounds.x +
      max(1, min(w - 2, ((w - dispChars.length) / 2).floor()));
  return localX >= titleX && localX < titleX + dispChars.length;
}