Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a ButtonComponent #1146

Merged
merged 7 commits into from
Nov 29, 2021
Merged

Added a ButtonComponent #1146

merged 7 commits into from
Nov 29, 2021

Conversation

spydon
Copy link
Member

@spydon spydon commented Nov 26, 2021

Description

Since we have a HudButtonComponent I'm adding this one for consistency.
If you haven't used the HudButtonComponent it is simply two PositionComponents, one that shows when the button is pressed and one that shows otherwise.

recording.mp4

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors and are passing (See Contributor Guide).
  • My PR does not decrease the code coverage, or I have a very special case and explained on the PR description why this PR decreases the coverage.
  • I updated/added relevant documentation (doc comments with ///) and updated/added examples in doc/examples.
  • I have formatted my code with flutter format and the flutter analyze does not report any problems.
  • I read and followed the Flame Style Guide.
  • I have added a description of the change under [next] in CHANGELOG.md.
  • I removed the Draft status, by clicking on the Ready for review button in this PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flame users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md).
  • No, this is not a breaking change.

Related Issues

Replace this paragraph with a list of issues related to this PR from the issue database. Indicate, which of these issues are resolved or fixed by this PR.

/// Note: You have to set the [button] in [onLoad] if you are not passing it in
/// through the constructor.
class ButtonComponent extends PositionComponent with Tappable {
late final PositionComponent? button;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be non-nullable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because then we can't do an assertion on onMount.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need an assertion though? If a variable is declared late final and you use it before it is initialized, Dart will through an assertion error for you automatically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those runtime errors are hard for the user to understand though, but maybe they are enough.
If we decide those are enough, then we need to change on all other PositionComponents that can be initialized like this too, so it is outside of the scope of this PR since it only follows the current structure.

Copy link
Member

@luanpotter luanpotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused on whats the difference then between ButtonComp and HudButtonComp? maybe something to explain on their docs in case people find the wrong one

@spydon
Copy link
Member Author

spydon commented Nov 28, 2021

I'm a bit confused on whats the difference then between ButtonComp and HudButtonComp? maybe something to explain on their docs in case people find the wrong one

HudButtonComponent is a hud and its position will be static to the margin that you have set, or if you set a position it will be calculate the margin and use that if the screen resizes. Which is how all HudMarginComponents work.
Meanwhile ButtonComponent is just a normal PositionComponent, and same with SpriteButtonComponent.

@spydon spydon merged commit ca8f8d3 into main Nov 29, 2021
@spydon spydon deleted the spydon.button-component branch November 29, 2021 20:01
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.

3 participants