pos method

({int x, int y}) pos(
  1. MouseMsg msg
)

Returns the coordinates of the mouse event relative to this zone.

Returns a record with (x, y) being the position within the zone, with (0, 0) being the top left cell of the zone.

If the zone is not known or the mouse event is not in bounds, returns (-1, -1).

Example

final zoneInfo = zone.get('text-area');
if (zoneInfo != null) {
  final (x, y) = zoneInfo.pos(mouseMsg);
  if (x >= 0 && y >= 0) {
    // x, y are coordinates within the text area
    cursor.moveTo(x, y);
  }
}

Implementation

({int x, int y}) pos(MouseMsg msg) {
  if (isZero || !inBounds(msg)) {
    return (x: -1, y: -1);
  }
  return (x: msg.x - startX, y: msg.y - startY);
}