Skip to content

fix: Position layout children that do not use a top left anchor - #4283

Merged
spydon merged 3 commits into
flame-engine:mainfrom
Yasser-Ameur:fix/layout-child-anchor
Dec 1, 2026
Merged

spydon merged 3 commits into
flame-engine:mainfrom
Yasser-Ameur:fix/layout-child-anchor

Conversation

@Yasser-Ameur

Copy link
Copy Markdown
Contributor

Description

RowComponent, ColumnComponent and PaddingComponent do not position a child whose anchor is not top left. Three centred icons in a row all stay where they were created:

final icons = [
  for (var i = 0; i < 3; i++)
    PositionComponent(size: Vector2.all(32), anchor: Anchor.center),
];
final row = RowComponent(gap: 8, children: icons);
// top left of each icon after layout
// main:   [-16, -16], [-16, -16], [-16, -16]
// branch: [0, 0], [40, 0], [80, 0]

The layout code moved a child with child.topLeftPosition.setFrom(...). For a top left anchor that getter returns the position vector itself, so writing into it works. For any other anchor it returns a new vector, and the write is lost. The three places now assign through the topLeftPosition setter, which moves the component for every anchor. Children with a top left anchor end up where they did before.

New tests in linear_layout_component_test.dart and padding_component_test.dart lay out centred children in a row, a column and a padding component; they fail on main because the children do not move.

Locally on Windows, from packages/flame: dart format --output=none --set-exit-if-changed on the four changed files reports 0 changed, flutter analyze reports no issues, and test/experimental test/layout gives 124 passed. The melos gates, cspell and the markdown check were not run.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • [-] I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [-] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

RowComponent, ColumnComponent and PaddingComponent placed each child by
calling setFrom on its topLeftPosition. That getter returns the position
vector itself only for a top left anchor; for any other anchor it returns
a fresh copy, so the child was never moved and stayed at its original
position. Assign through the topLeftPosition setter instead.
@Yasser-Ameur
Yasser-Ameur marked this pull request as ready for review December 1, 2026 08:21
@spydon
spydon enabled auto-merge December 1, 2026 13:44
@spydon
spydon added this pull request to the merge queue Dec 1, 2026
Merged via the queue into flame-engine:main with commit 265f495 Dec 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants