inBounds method

bool inBounds(
  1. MouseMsg msg
)

Returns true if the mouse event was in the bounds of this zone's coordinates.

If the zone is not known (isZero), returns false. It calculates this using a box between the start and end coordinates. If you're looking to check for abnormal shapes (e.g. something that might wrap a line, but can't be determined using a box), you'll need to implement this yourself.

Example

case MouseMsg(:final action, :final button) when action == MouseAction.press:
  if (zone.get('my-button')?.inBounds(msg) ?? false) {
    // Button was clicked!
  }

Implementation

bool inBounds(MouseMsg msg) {
  if (isZero) return false;
  if (startX > endX || startY > endY) return false;
  if (msg.x < startX || msg.y < startY) return false;
  if (msg.x > endX || msg.y > endY) return false;
  return true;
}