Can't center `TextComponent`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 32/100
調査の方向性
まず Flame 1.19.0 で例を再現し、レポートに示されている camera.visibleWorldRect の値を含めて、TextComponent、Anchor.center、TextPaint、CenterTextBody.onLoad を調査します。コンテナのサイズごとにレンダリングされたテキストの位置を比較します。影響を受ける Android セットアップで中央揃えのテキストが一貫してレンダリングされ、その動作が適切な回帰テストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
What happened?
Even add Anchor.center to TextComponent still can't center it to container and no regular pattern, some are above, some are below.
What do you expect?
Text can auto center to container
How can we reproduce this?
import 'dart:async';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_forge2d/flame_forge2d.dart' hide Transform;
import 'package:flutter/material.dart';
import 'package:flame/extensions.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Container(
width: 30, height: 30,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 40, height: 40,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 50, height: 50,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 55, height: 55,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 60, height: 60,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 70, height: 70,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
],
),
Row(
children: [
Container(
width: 25, height: 25,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 35, height: 35,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 65, height: 65,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 75, height: 75,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
Container(
width: 80, height: 80,
margin: const EdgeInsets.all(8),
color: Colors.blue,
child: GameWidget<TextCenterGame>(game: TextCenterGame(),),
),
],
),
],
),
),
),
),
);
}
class TextCenterGame extends Forge2DGame{
TextCenterGame() : super(world: TextCenterWord(),);
@override
Color backgroundColor() {
return Colors.transparent;
}
@override
FutureOr<void> onLoad() {
super.onLoad();
}
}
class TextCenterWord extends Forge2DWorld with HasGameReference<Forge2DGame> {
@override
Future<void> onLoad() async {
super.onLoad();
print('game.size: ${game.size}, ${game.camera.visibleWorldRect}');
// add(CenterTextBody(Size(game.size.x, game.size.y)));
add(CenterTextBody(Size(game.camera.visibleWorldRect.width, game.camera.visibleWorldRect.height)));
}
}
class CenterTextBody extends BodyComponent {// with TapCallbacks
final bgPaint = Paint();
final Size size;
CenterTextBody(this.size);
@override
Future<void> onLoad() async {
await super.onLoad();
bgPaint.style = PaintingStyle.stroke;
bgPaint.strokeWidth = 0.1;
bgPaint.color = Colors.red;
final fontSize = size.width*0.6;
print('game.size: $fontSize, ${game.size}, ${game.camera.visibleWorldRect}');
TextComponent textComponent = TextComponent(
text: '0',//🌟⭐
textRenderer: TextPaint(
style: TextStyle(
fontSize: fontSize,
// height: 1,
),
),
anchor: Anchor.center,
);
add(textComponent);
}
@override
void renderCircle(Canvas canvas, Offset center, double radius) {
canvas.drawCircle(center, radius, bgPaint);
canvas.drawLine(Offset(-radius, center.dy), Offset(radius, center.dy), bgPaint);
canvas.drawLine(Offset(center.dx, -radius), Offset(center.dx, radius), bgPaint);
}
@override
Body createBody() {
print('createBody: $size');
final fixtureDef = FixtureDef(
CircleShape()..radius=size.width/2,
);
final bodyDef = BodyDef(
// position: Vector2(size.width/2, size.height/2),
// position: Vector2(),
type: BodyType.static,
);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
What steps should take to fix this?
No response
Do have an example of where the bug occurs?
No response
Relevant log output
No response
Execute in a terminal and put output into the code block below
[✓] Flutter (Channel stable, 3.24.1, on macOS 14.6.1 23G93 darwin-arm64 (Rosetta), locale en-US)
• Flutter version 3.24.1 on channel stable at /Users/taotao/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 5874a72aa4 (5 weeks ago), 2024-08-20 16:46:00 -0500
• Engine revision c9b9d5780d
• Dart version 3.5.1
• DevTools version 2.37.2
• Pub download mirror https://pub.flutter-io.com
• Flutter download mirror https://storage.flutter-io.com
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/taotao/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/taotao/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
• All Android licenses accepted.
Affected platforms
Android
Other information
flame: ^1.19.0
flame_forge2d: ^0.18.2
flame_svg: ^1.11.0
Are you interested in working on a PR for this?
- I want to work on this
- 主要言語
- Dart
- スター
- 10.8k
- フォーク
- 1.1k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 61
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
flame-engine/flame のほかの issue
-
Timer with tickCount stays finished after start() or reset()対応中かも @matthewalberto が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
flame-engine/flame#4240 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`CameraComponent.follow` follows the local position of a nested target対応中かも @ufrshubham が 1 日前に担当しました。 オープンbug
flame-engine/flame#4238 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`ComponentPool` returns components to the pool while they are still in use, and loses components removed before mounting対応中かも @ufrshubham が 18 日前に担当しました。 オープンbug
flame-engine/flame#4191 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Move the flame_studio debugging features to flame_devtools対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンenhancement
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
flame-engine/flame#4176 ·
メンテナーはふだん 1 日以内に返信
-
discussion enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
flame-engine/flame#4175 ·
メンテナーはふだん 1 日以内に返信
flame-engine/flame の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
spotiflacapp/SpotiFLAC-Mobile#935 ·
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
chriskelly/wish-together#193 ·
メンテナーはふだん 1 日以内に返信
-
area: player feature request
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100