Skip to content

Commit

Permalink
fix: Fix TextBoxComponent alignment bug (#2781)
Browse files Browse the repository at this point in the history
Fix `TextBoxComponent` alignment bug
The `anchor` is the anchor of the text box component itself.
It has nothing to do with the alignment of the text within the box.
The position computed for rendering the text on the above lines is
assuming `topLeft` anchor for the text.
  • Loading branch information
luanpotter committed Sep 30, 2023
1 parent bdb1c79 commit 0fb53ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/flame/lib/src/components/text_box_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class TextBoxComponent<T extends TextRenderer> extends TextComponent {
(boxHeight - nLines * _lineHeight) * align.y +
i * _lineHeight,
);
textElement.render(canvas, position, anchor: anchor);
textElement.render(canvas, position);

charCount += lines[i].length;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/flame/test/components/text_box_component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ void main() {
_FramedTextBox(
text: 'That shows thee a weak slave; for the weakest goes to the '
'wall.',
position: Vector2(410, 320),
position: Vector2(410, 320) + Vector2(380, 270),
size: Vector2(380, 270),
align: Anchor.centerRight,
anchor: Anchor.bottomRight,
),
]);
},
Expand Down Expand Up @@ -194,6 +195,7 @@ class _FramedTextBox extends TextBoxComponent {
super.align,
super.position,
super.size,
super.anchor,
}) : super(
textRenderer: DebugTextRenderer(fontSize: 22),
);
Expand Down

0 comments on commit 0fb53ef

Please sign in to comment.