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

[Merged by Bors] - Add builder methods to Transform #2778

Closed
wants to merge 2 commits into from

Conversation

Lythenas
Copy link
Contributor

@Lythenas Lythenas commented Sep 6, 2021

Objective

Make it easier to construct transforms. E.g.

Transform::from_xyz(0.0, 0.0, 10.0).with_scale(Vec3::splat(2.0))

I found myself writing an extension method to do this so I don't have to write:

Transform {
  translation: Vec3::new(0.0, 0.0, 10.0),
  scale: Vec3::splat(2.0),
  ..Default::default()
}

Solution

Add builder style methods to Transform.

Methods:

  • with_translation
  • with_rotation
  • with_scale

I also added these methods to GlobalTransform. But they are probably less useful there.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Sep 6, 2021
Copy link
Contributor

@afonsolage afonsolage left a comment

Choose a reason for hiding this comment

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

I like this change, it is compatible with others APIs.

@@ -105,6 +105,27 @@ impl GlobalTransform {
self
}

#[doc(hidden)]
Copy link
Member

Choose a reason for hiding this comment

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

Why add doc(hidden) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it because the other creation methods (looking_at and from_*) are all doc(hidden).

I think it's a bit strange that they are hidden but users don't usually create GlobalTransforms.

Copy link
Member

Choose a reason for hiding this comment

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

hmm yeah then i guess we can just leave this as-is for now and then circle back if/when we need to with docs.

@NiklasEi NiklasEi added C-Usability A simple quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Sep 7, 2021
@cart
Copy link
Member

cart commented Sep 9, 2021

bors r+

bors bot pushed a commit that referenced this pull request Sep 9, 2021
# Objective

Make it easier to construct transforms. E.g.

```rs
Transform::from_xyz(0.0, 0.0, 10.0).with_scale(Vec3::splat(2.0))
```

I found myself writing an extension method to do this so I don't have to write:

```rs
Transform {
  translation: Vec3::new(0.0, 0.0, 10.0),
  scale: Vec3::splat(2.0),
  ..Default::default()
}
```

## Solution

Add *builder style* methods to `Transform`.

Methods:

- `with_translation`
- `with_rotation`
- `with_scale`

I also added these methods to `GlobalTransform`. But they are probably less useful there.
@bors bors bot changed the title Add builder methods to Transform [Merged by Bors] - Add builder methods to Transform Sep 9, 2021
@bors bors bot closed this Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants