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

feat: Callbacks in HudButtonComponent constructor and ViewportMargin mixin to avoid code duplication #1685

Merged
merged 7 commits into from
Jun 4, 2022

Conversation

spydon
Copy link
Member

@spydon spydon commented May 30, 2022

Description

Created a mixin to handle the margin to the viewport, mostly to remove the code duplication in ButtonComponent and HudButtonComponent, but it can also be useful in other cases when you don't want to wrap your component in HudMarginComponent.

Once the new camera system is in place this will of course have to be replaced.

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • 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.

Breaking Change

  • No, this is not a breaking change.

Related Issues

position: position,
onPressed: onPressed,
onReleased: onReleased,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldnt this be part of a separate PR? For the sake of clear commits

Copy link
Member Author

Choose a reason for hiding this comment

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

It was the other way around really, I wanted the button components to be the same and to do that I introduced the mixin, I can change the title to reflect on that.

@spydon spydon changed the title refactor: ViewportMargin mixin to avoid code duplication feat: Callbacks in HudButtonComponent constructor and ViewportMargin mixin to avoid code duplication May 31, 2022
Copy link
Member

@erickzanardo erickzanardo left a comment

Choose a reason for hiding this comment

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

LGTM, just one small, optional comment.

/// If you set the position of the component instead of a margin when
/// initializing the component, the margin to the edge of the screen from that
/// position will be used.
mixin ComponentViewportMargin on PositionComponent, HasGameRef {
Copy link
Member

Choose a reason for hiding this comment

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

Idk if hud button or button component have tests, but if they don't this would be a good opportunity to introduce a test suite that would end up testing both things.

@spydon spydon merged commit f55b2e0 into main Jun 4, 2022
@spydon spydon deleted the spydon.viewport-margin branch June 4, 2022 15:00
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