handleMouseEvent method
Handles mouse interactions.
Implementation
void handleMouseEvent(MouseEvent event, int localX, int localY) {
final resolvedWidth = widget.width ?? _lastWidth;
final resolvedHeight = widget.height ?? _lastHeight;
if (resolvedWidth <= 0 || resolvedHeight <= 0) return;
// Body is always at (0, 0) with width W - 1 and height H - 1
final inBounds =
localX >= 0 &&
localX < resolvedWidth - 1 &&
localY >= 0 &&
localY < resolvedHeight - 1;
if (event.type == MouseEventType.press) {
if (inBounds) {
setState(() {
_isPressed = true;
_isHovered = false;
final clickPoint = Point(localX, localY);
triggerEffect(_ripple, clickPoint);
});
}
} else if (event.type == MouseEventType.release) {
if (_isPressed) {
setState(() {
_isPressed = false;
_ripple.reset();
if (inBounds) {
_isHovered = true;
widget.onPressed();
} else {
_isHovered = false;
}
});
}
} else if (event.type == MouseEventType.move ||
event.type == MouseEventType.drag) {
final oldHovered = _isHovered;
_isHovered = inBounds && !_isPressed;
if (_isHovered != oldHovered) {
setState(() {});
}
}
}