LCOV - code coverage report
Current view: top level - lib/src/components/mixins - tappable.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 13 28 46.4 %
Date: 2021-08-10 15:50:53 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:meta/meta.dart';
       2             : 
       3             : import '../../../game.dart';
       4             : import '../../game/base_game.dart';
       5             : import '../../gestures/events.dart';
       6             : import '../base_component.dart';
       7             : 
       8             : mixin Tappable on BaseComponent {
       9           0 :   bool onTapCancel() {
      10             :     return true;
      11             :   }
      12             : 
      13           1 :   bool onTapDown(TapDownInfo info) {
      14             :     return true;
      15             :   }
      16             : 
      17           0 :   bool onTapUp(TapUpInfo info) {
      18             :     return true;
      19             :   }
      20             : 
      21             :   int? _currentPointerId;
      22             : 
      23           0 :   bool _checkPointerId(int pointerId) => _currentPointerId == pointerId;
      24             : 
      25           3 :   bool handleTapDown(int pointerId, TapDownInfo info) {
      26           6 :     if (containsPoint(eventPosition(info))) {
      27           3 :       _currentPointerId = pointerId;
      28           3 :       return onTapDown(info);
      29             :     }
      30             :     return true;
      31             :   }
      32             : 
      33           0 :   bool handleTapUp(int pointerId, TapUpInfo info) {
      34           0 :     if (_checkPointerId(pointerId) && containsPoint(eventPosition(info))) {
      35           0 :       _currentPointerId = null;
      36           0 :       return onTapUp(info);
      37             :     }
      38             :     return true;
      39             :   }
      40             : 
      41           0 :   bool handleTapCancel(int pointerId) {
      42           0 :     if (_checkPointerId(pointerId)) {
      43           0 :       _currentPointerId = null;
      44           0 :       return onTapCancel();
      45             :     }
      46             :     return true;
      47             :   }
      48             : }
      49             : 
      50             : mixin HasTappableComponents on BaseGame {
      51           2 :   void _handleTapEvent(bool Function(Tappable child) tapEventHandler) {
      52           6 :     for (final c in components.reversed()) {
      53             :       var shouldContinue = true;
      54           2 :       if (c is BaseComponent) {
      55           2 :         shouldContinue = c.propagateToChildren<Tappable>(tapEventHandler);
      56             :       }
      57           2 :       if (c is Tappable && shouldContinue) {
      58           2 :         shouldContinue = tapEventHandler(c);
      59             :       }
      60             :       if (!shouldContinue) {
      61             :         break;
      62             :       }
      63             :     }
      64             :   }
      65             : 
      66           0 :   @mustCallSuper
      67             :   void onTapCancel(int pointerId) {
      68           0 :     _handleTapEvent((Tappable child) => child.handleTapCancel(pointerId));
      69             :   }
      70             : 
      71           2 :   @mustCallSuper
      72             :   void onTapDown(int pointerId, TapDownInfo info) {
      73           6 :     _handleTapEvent((Tappable child) => child.handleTapDown(pointerId, info));
      74             :   }
      75             : 
      76           0 :   @mustCallSuper
      77             :   void onTapUp(int pointerId, TapUpInfo info) {
      78           0 :     _handleTapEvent((Tappable child) => child.handleTapUp(pointerId, info));
      79             :   }
      80             : }

Generated by: LCOV version 1.15