mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
38 lines
937 B
Dart
38 lines
937 B
Dart
import 'dart:ui';
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
mixin Tapable {
|
|
Rect toRect();
|
|
|
|
void onTapCancel() {}
|
|
void onTapDown(TapDownDetails details) {}
|
|
void onTapUp(TapUpDetails details) {}
|
|
|
|
bool checkTapOverlap(Offset o) => toRect().contains(o);
|
|
|
|
void handleTapDown(TapDownDetails details) {
|
|
if (checkTapOverlap(details.globalPosition)) {
|
|
onTapDown(details);
|
|
}
|
|
tapableChildren().forEach((c) => c.handleTapDown(details));
|
|
}
|
|
|
|
void handleTapUp(TapUpDetails details) {
|
|
if (checkTapOverlap(details.globalPosition)) {
|
|
onTapUp(details);
|
|
}
|
|
tapableChildren().forEach((c) => c.handleTapUp(details));
|
|
}
|
|
|
|
void handleTapCancel() {
|
|
onTapCancel();
|
|
tapableChildren().forEach((c) => c.handleTapCancel());
|
|
}
|
|
|
|
/// Overwrite this to add children to this [Tapable].
|
|
///
|
|
/// If a [Tapable] has children, its children be taped as well.
|
|
Iterable<Tapable> tapableChildren() => [];
|
|
}
|