Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add background to ValueRoute example that captures events #3145

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/flame/examples/lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class RoundedButton extends PositionComponent with TapCallbacks {
required this.action,
required Color color,
required Color borderColor,
super.position,
super.anchor = Anchor.center,
}) : _textDrawable = TextPaint(
style: const TextStyle(
Expand Down
15 changes: 11 additions & 4 deletions doc/flame/examples/lib/value_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,21 @@ class RateRoute extends ValueRoute<int>
final size = Vector2(250, 130);
const radius = 18.0;
final starGap = (size.x - 5 * 2 * radius) / 6;
return RectangleComponent(
return DialogBackground(
position: game.size / 2,
size: size,
anchor: Anchor.center,
paint: Paint()..color = const Color(0xee858585),
children: [
RoundedButton(
text: 'Ok',
position: position = Vector2(size.x / 2, 100),
action: () {
completeWith(
descendants().where((c) => c is Star && c.active).length,
);
},
color: const Color(0xFFFFFFFF),
borderColor: const Color(0xFF000000),
)..position = Vector2(size.x / 2, 100),
),
for (var i = 0; i < 5; i++)
Star(
value: i + 1,
Expand All @@ -81,6 +80,14 @@ class RateRoute extends ValueRoute<int>
}
}

class DialogBackground extends RectangleComponent with TapCallbacks {
DialogBackground({super.position, super.size, super.children})
: super(
anchor: Anchor.center,
paint: Paint()..color = const Color(0xee858585),
);
}

class Star extends PositionComponent with TapCallbacks {
Star({required this.value, required this.radius, super.position})
: super(size: Vector2.all(2 * radius), anchor: Anchor.center);
Expand Down
4 changes: 3 additions & 1 deletion doc/flame/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Each page in the router can be either transparent or opaque. If a page is opaque
below it in the stack are not rendered and do not receive pointer events (such as taps or drags).
On the contrary, if a page is transparent, then the page below it will be rendered and receive
events normally. Such transparent pages are useful for implementing modal dialogs, inventory or
dialogue UIs, etc.
dialogue UIs, etc. If you want your route to be visually transparent but for the routes below it
to not receive events, make sure to add a background component to your route that captures the
events by using one of the [event capturing mixins](inputs/inputs.md).

Usage example:

Expand Down
Loading