Repository navigation
fix: Keep a HUD component at the left or top edge in place on resize - #4284
Open
Yasser-Ameur wants to merge 1 commit into
Open
Yasser-Ameur wants to merge 1 commit into
Yasser-Ameur wants to merge 1 commit into
Conversation
A HudMarginComponent, or a component using ComponentViewportMargin such as HudButtonComponent, created with a position turns that position into a margin, but a zero left or top margin was read as "measure from the right or bottom edge". A component placed at x = 0 or y = 0 therefore moved away from that edge when the game was resized. Margins derived from the position are now always measured from the left and top edges.
Yasser-Ameur
marked this pull request as ready for review
December 1, 2026 09:09
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A HUD component that is placed by
positionat the left or top edge moves when the game is resized, and leaves the screen when the game gets smaller:A component created with a
positionand nomarginturns that position into a margin on load. When the component touches the left or top edge, that margin has a zeroleftortop, and the resize code reads a zero as "not set, measure from the right or bottom edge". A resize is needed to see it, such as a desktop or web window resize or a phone rotation.A margin that was derived from the position is now remembered and always measured from the left and top edges.
HudMarginComponentand theComponentViewportMarginmixin (used byHudButtonComponentandJoystickComponent) had the same code, and both get the same change. A margin that is passed explicitly behaves as before, also when it has a zeroleftortop.New tests in
hud_margin_component_test.dartandhud_button_component_test.dartplace a component at the edge and resize the game; they fail onmain.Locally on Windows, from
packages/flame:dart format --output=none --set-exit-if-changedon the four changed files reports 0 changed,flutter analyzereports no issues, andtest/componentsgives 657 passed. Themelosgates, cspell and the markdown check were not run.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues