Skip to content

Commit

Permalink
fix: Add missing generic to ComponentViewportMargin (#2983)
Browse files Browse the repository at this point in the history
Improve `ComponentViewportMargin` (see #2982)


Closes #2982
  • Loading branch information
jtmcdole committed Jan 16, 2024
1 parent 2e5e64d commit 1d9fe61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
@@ -1,6 +1,7 @@
import 'package:flame/camera.dart';
import 'package:flame/components.dart';
import 'package:flame/effects.dart';
import 'package:flame/src/game/flame_game.dart';
import 'package:flutter/widgets.dart' show EdgeInsets;
import 'package:meta/meta.dart';

Expand All @@ -19,7 +20,8 @@ import 'package:meta/meta.dart';
/// Do note that this only works with the old style camera and not the
/// [CameraComponent].
// TODO(Lukas): Rename this since it isn't necessarily related to the viewport.
mixin ComponentViewportMargin on PositionComponent, HasGameReference {
mixin ComponentViewportMargin<T extends FlameGame>
on PositionComponent, HasGameReference<T> {
/// Instead of setting a position of the [PositionComponent] that uses
/// [ComponentViewportMargin] a margin from the edges of the parent can be
/// used instead.
Expand Down
@@ -1,12 +1,14 @@
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('ComponentViewportMargin', () {
testWithFlameGame(
testWithGame(
'margin should stay same after GameResize',
_TestGame.new,
(game) async {
final initialGameSize = Vector2.all(100);
final componentSize = Vector2.all(10);
Expand Down Expand Up @@ -40,5 +42,7 @@ void main() {
});
}

class _TestGame extends FlameGame<World> {}

class _ComponentWithViewportMargin extends PositionComponent
with HasGameReference, ComponentViewportMargin {}
with HasGameReference<_TestGame>, ComponentViewportMargin<_TestGame> {}

0 comments on commit 1d9fe61

Please sign in to comment.