feat: Add copyWith method on the TextBoxConfig (#3099)

Simplifies the creation of the `TextBoxConfig` in the
`ScrollTextBoxComponent` by adding a `copyWith` method to it and making
it `const`.
This commit is contained in:
Lukas Klingsbo
2024-03-26 23:21:26 +01:00
committed by GitHub
parent 8cd9e12319
commit b946ba70cb
5 changed files with 34 additions and 27 deletions

View File

@ -77,9 +77,9 @@ class TextExample extends FlameGame {
size: Vector2(200, 150),
position: Vector2(size.x / 2, size.y / 2 + 100),
anchor: Anchor.topCenter,
boxConfig: TextBoxConfig(
boxConfig: const TextBoxConfig(
timePerChar: 0.005,
margins: const EdgeInsets.fromLTRB(10, 10, 10, 10),
margins: EdgeInsets.fromLTRB(10, 10, 10, 10),
),
),
],
@ -138,6 +138,9 @@ class MyTextBox extends TextBoxComponent {
Future<void> onLoad() {
paint = Paint();
bgRect = Rect.fromLTWH(0, 0, width, height);
size.addListener(() {
bgRect = Rect.fromLTWH(0, 0, width, height);
});
paint.color = Colors.white10;
return super.onLoad();
@ -152,7 +155,7 @@ class MyTextBox extends TextBoxComponent {
class MyScrollTextBox extends ScrollTextBoxComponent {
late Paint paint;
late Rect bgRect;
late Rect backgroundRect;
MyScrollTextBox(
String text, {
@ -165,7 +168,7 @@ class MyScrollTextBox extends ScrollTextBoxComponent {
@override
FutureOr<void> onLoad() {
paint = Paint();
bgRect = Rect.fromLTWH(0, 0, width, height);
backgroundRect = Rect.fromLTWH(0, 0, width, height);
paint.color = Colors.white10;
return super.onLoad();
@ -173,7 +176,7 @@ class MyScrollTextBox extends ScrollTextBoxComponent {
@override
void render(Canvas canvas) {
canvas.drawRect(bgRect, paint);
canvas.drawRect(backgroundRect, paint);
super.render(canvas);
}
}