docs: Fix naming of drag- and tap-callbacks examples (#2873)

Fix naming of drag- and tap-callbacks examples
This commit is contained in:
Lukas Klingsbo
2023-11-26 18:55:35 +01:00
committed by GitHub
parent 685e1d9529
commit f42d0e73be
3 changed files with 27 additions and 29 deletions

View File

@ -3,14 +3,14 @@ import 'package:flame/events.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart' show Colors;
class DraggablesExample extends FlameGame {
class DragCallbacksExample extends FlameGame {
static const String description = '''
In this example we show you can use the `DragCallbacks` mixin on
`PositionComponent`s. Drag around the Embers and see their position
changing.
''';
DraggablesExample({required this.zoom});
DragCallbacksExample({required this.zoom});
final double zoom;
late final DraggableEmber square;
@ -34,19 +34,12 @@ class DraggableEmber extends Ember with DragCallbacks {
@override
void update(double dt) {
super.update(dt);
debugColor = isDragged && findGame() is DraggablesExample
? Colors.greenAccent
: Colors.purple;
debugColor = isDragged ? Colors.greenAccent : Colors.purple;
}
@override
void onDragUpdate(DragUpdateEvent event) {
if (findGame() is! DraggablesExample) {
event.continuePropagation = true;
return;
}
position.add(event.delta);
event.continuePropagation = false;
}
}

View File

@ -2,7 +2,7 @@ import 'package:dashbook/dashbook.dart';
import 'package:examples/commons/commons.dart';
import 'package:examples/stories/input/advanced_button_example.dart';
import 'package:examples/stories/input/double_tap_callbacks_example.dart';
import 'package:examples/stories/input/draggables_example.dart';
import 'package:examples/stories/input/drag_callbacks_example.dart';
import 'package:examples/stories/input/gesture_hitboxes_example.dart';
import 'package:examples/stories/input/hardware_keyboard_example.dart';
import 'package:examples/stories/input/hover_callbacks_example.dart';
@ -14,7 +14,7 @@ import 'package:examples/stories/input/mouse_cursor_example.dart';
import 'package:examples/stories/input/mouse_movement_example.dart';
import 'package:examples/stories/input/multitap_advanced_example.dart';
import 'package:examples/stories/input/multitap_example.dart';
import 'package:examples/stories/input/overlapping_tappables_example.dart';
import 'package:examples/stories/input/overlapping_tap_callbacks_example.dart';
import 'package:examples/stories/input/scroll_example.dart';
import 'package:examples/stories/input/tap_callbacks_example.dart';
import 'package:flame/game.dart';
@ -29,16 +29,16 @@ void addInputStories(Dashbook dashbook) {
info: TapCallbacksExample.description,
)
..add(
'Draggables',
'DragCallbacks',
(context) {
return GameWidget(
game: DraggablesExample(
game: DragCallbacksExample(
zoom: context.listProperty('zoom', 1, [0.5, 1, 1.5]),
),
);
},
codeLink: baseLink('input/draggables_example.dart'),
info: DraggablesExample.description,
codeLink: baseLink('input/drag_callbacks_example.dart'),
info: DragCallbacksExample.description,
)
..add(
'Double Tap (Component)',
@ -47,7 +47,7 @@ void addInputStories(Dashbook dashbook) {
game: DoubleTapCallbacksExample(),
);
},
codeLink: baseLink('input/draggables_example.dart'),
codeLink: baseLink('input/double_tap_callbacks_example.dart'),
info: DoubleTapCallbacksExample.description,
)
..add(
@ -108,10 +108,10 @@ void addInputStories(Dashbook dashbook) {
info: MultitapAdvancedExample.description,
)
..add(
'Overlapping Tappables',
(_) => GameWidget(game: OverlappingTappablesExample()),
codeLink: baseLink('input/overlapping_tappables_example.dart'),
info: OverlappingTappablesExample.description,
'Overlapping TapCallbacks',
(_) => GameWidget(game: OverlappingTapCallbacksExample()),
codeLink: baseLink('input/overlapping_tap_callbacks_example.dart'),
info: OverlappingTapCallbacksExample.description,
)
..add(
'Gesture Hitboxes',

View File

@ -4,7 +4,7 @@ import 'package:flame/extensions.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
class OverlappingTappablesExample extends FlameGame {
class OverlappingTapCallbacksExample extends FlameGame {
static const String description = '''
In this example we show you that events can choose to continue propagating
to underlying components. The middle green square continue to propagate the
@ -13,14 +13,19 @@ class OverlappingTappablesExample extends FlameGame {
@override
Future<void> onLoad() async {
add(TappableSquare(position: Vector2(100, 100)));
add(TappableSquare(position: Vector2(150, 150), continuePropagation: true));
add(TappableSquare(position: Vector2(100, 200)));
add(TapCallbacksSquare(position: Vector2(100, 100)));
add(
TapCallbacksSquare(
position: Vector2(150, 150),
continuePropagation: true,
),
);
add(TapCallbacksSquare(position: Vector2(100, 200)));
}
}
class TappableSquare extends RectangleComponent with TapCallbacks {
TappableSquare({Vector2? position, this.continuePropagation = false})
class TapCallbacksSquare extends RectangleComponent with TapCallbacks {
TapCallbacksSquare({Vector2? position, this.continuePropagation = false})
: super(
position: position ?? Vector2.all(100),
size: Vector2.all(100),