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

          Line data    Source code
       1             : import 'package:flutter/rendering.dart' show EdgeInsets, VoidCallback;
       2             : import 'package:meta/meta.dart';
       3             : 
       4             : import '../../../components.dart';
       5             : import '../../../extensions.dart';
       6             : import '../../../input.dart';
       7             : import '../../gestures/events.dart';
       8             : 
       9             : class HudButtonComponent extends HudMarginComponent with Tappable {
      10             :   late final PositionComponent button;
      11             :   late final PositionComponent? buttonDown;
      12             : 
      13             :   /// Callback for what should happen when the button is pressed.
      14             :   /// If you want to interact with [onTapUp] or [onTapCancel] it is recommended
      15             :   /// to extend [HudButtonComponent].
      16             :   VoidCallback? onPressed;
      17             : 
      18           0 :   HudButtonComponent({
      19             :     required this.button,
      20             :     this.buttonDown,
      21             :     EdgeInsets? margin,
      22             :     Vector2? position,
      23             :     Vector2? size,
      24             :     Anchor anchor = Anchor.center,
      25             :     this.onPressed,
      26           0 :   }) : super(
      27             :           margin: margin,
      28             :           position: position,
      29           0 :           size: size ?? button.size,
      30             :           anchor: anchor,
      31             :         );
      32             : 
      33             :   @override
      34           0 :   Future<void> onLoad() async {
      35           0 :     await super.onLoad();
      36           0 :     addChild(button);
      37             :   }
      38             : 
      39           0 :   @override
      40             :   @mustCallSuper
      41             :   bool onTapDown(TapDownInfo info) {
      42           0 :     if (buttonDown != null) {
      43           0 :       children.remove(button);
      44           0 :       addChild(buttonDown!);
      45             :     }
      46           0 :     onPressed?.call();
      47             :     return false;
      48             :   }
      49             : 
      50           0 :   @override
      51             :   @mustCallSuper
      52             :   bool onTapUp(TapUpInfo info) {
      53           0 :     onTapCancel();
      54             :     return true;
      55             :   }
      56             : 
      57           0 :   @override
      58             :   @mustCallSuper
      59             :   bool onTapCancel() {
      60           0 :     if (buttonDown != null) {
      61           0 :       children.remove(buttonDown!);
      62           0 :       addChild(button);
      63             :     }
      64             :     return false;
      65             :   }
      66             : }

Generated by: LCOV version 1.15