mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-11 18:11:12 +08:00
Generic way of handling tap events
This commit is contained in:
committed by
renancaraujo
parent
add2a4fdc8
commit
ddaa8b296e
@@ -50,17 +50,14 @@ mixin Tapable on BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mixin HasTapableComponents on BaseGame {
|
mixin HasTapableComponents on BaseGame {
|
||||||
@mustCallSuper
|
void _handleTapEvent(bool Function(Tapable child) tapEventHandler) {
|
||||||
void onTapCancel(int pointerId) {
|
|
||||||
for (Component c in components.toList().reversed) {
|
for (Component c in components.toList().reversed) {
|
||||||
bool shouldContinue = true;
|
bool shouldContinue = true;
|
||||||
if (c is BaseComponent) {
|
if (c is BaseComponent) {
|
||||||
shouldContinue = c.propagateToChildren<Tapable>(
|
shouldContinue = c.propagateToChildren<Tapable>(tapEventHandler);
|
||||||
(child) => child.handleTapCancel(pointerId),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (c is Tapable && shouldContinue) {
|
if (c is Tapable && shouldContinue) {
|
||||||
shouldContinue = c.handleTapCancel(pointerId);
|
shouldContinue = tapEventHandler(c);
|
||||||
}
|
}
|
||||||
if (!shouldContinue) {
|
if (!shouldContinue) {
|
||||||
break;
|
break;
|
||||||
@@ -68,39 +65,18 @@ mixin HasTapableComponents on BaseGame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@mustCallSuper
|
||||||
|
void onTapCancel(int pointerId) {
|
||||||
|
_handleTapEvent((Tapable child) => child.handleTapCancel(pointerId));
|
||||||
|
}
|
||||||
|
|
||||||
@mustCallSuper
|
@mustCallSuper
|
||||||
void onTapDown(int pointerId, TapDownDetails details) {
|
void onTapDown(int pointerId, TapDownDetails details) {
|
||||||
for (Component c in components.toList().reversed) {
|
_handleTapEvent((Tapable child) => child.handleTapDown(pointerId, details));
|
||||||
bool shouldContinue = true;
|
|
||||||
if (c is BaseComponent) {
|
|
||||||
shouldContinue = c.propagateToChildren<Tapable>(
|
|
||||||
(child) => child.handleTapDown(pointerId, details),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (c is Tapable && shouldContinue) {
|
|
||||||
shouldContinue = c.handleTapDown(pointerId, details);
|
|
||||||
}
|
|
||||||
if (!shouldContinue) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@mustCallSuper
|
@mustCallSuper
|
||||||
void onTapUp(int pointerId, TapUpDetails details) {
|
void onTapUp(int pointerId, TapUpDetails details) {
|
||||||
for (Component c in components.toList().reversed) {
|
_handleTapEvent((Tapable child) => child.handleTapUp(pointerId, details));
|
||||||
bool shouldContinue = true;
|
|
||||||
if (c is BaseComponent) {
|
|
||||||
shouldContinue = c.propagateToChildren<Tapable>(
|
|
||||||
(child) => child.handleTapUp(pointerId, details),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (c is Tapable && shouldContinue) {
|
|
||||||
shouldContinue = c.handleTapUp(pointerId, details);
|
|
||||||
}
|
|
||||||
if (!shouldContinue) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user