Skip to content

Support tuple structs in AnimatedField #16747

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

Conversation

yonzebu
Copy link
Contributor

@yonzebu yonzebu commented Dec 10, 2024

Objective

Partially fixes #16736.

Solution

AnimatedField::new_unchecked now supports tuple struct fields. animated_field! is unchanged.

Testing

Added a test to make sure common and simple uses of AnimatedField::new_unchecked with tuple structs don't panic.

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@IQuick143 IQuick143 added A-Animation Make things move and change over time S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 10, 2024
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Dec 11, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Good change: this isn't a full fix, but we might as well make this more generous now to ease making the macro work later.

Copy link
Member

@MrGVSV MrGVSV 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 not very familiar with this part of the code, but the reflection stuff looks good to me!

fn test_animated_field_tuple_struct_simple_uses() {
#[derive(Clone, Debug, Component, Reflect)]
struct A(f32);
let _ = AnimatedField::new_unchecked("0", |a: &mut A| &mut a.0);
Copy link
Member

Choose a reason for hiding this comment

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

Question: What's the point of setting the field name if we have to specify this function?

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'm not super familiar with all the animation machinery, but for structs with named fields, the field name is used as part of the EvaluatorId, which I think identifies what part of the component is being animated? If you're manually constructing an AnimatedField (without the macro) you still have to do something like AnimatedField::new_unchecked("bar", |foo: &mut Foo| &mut foo.bar) for structs with named fields, so I figured it was fine to maintain the field name requirement, especially since I'm not quite sure what the EvaluatorId would be without being given the field name.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yonzebu That is correct; in turn, it's important that the EvaluatorId incorporates the field index so that it can be known when two animatable properties are "the same" (this is used to dispatch the animation evaluators).

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 11, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 11, 2024
github-merge-queue bot pushed a commit that referenced this pull request Dec 11, 2024
# Objective

Partially fixes #16736.

## Solution

`AnimatedField::new_unchecked` now supports tuple struct fields.
`animated_field!` is unchanged.

## Testing

Added a test to make sure common and simple uses of
`AnimatedField::new_unchecked` with tuple structs don't panic.

---------

Co-authored-by: yonzebu <yonzebu@gmail.com>
Merged via the queue into bevyengine:main with commit 2994e53 Dec 11, 2024
34 checks passed
@yonzebu yonzebu deleted the support-tuple-struct-animated-fields branch December 12, 2024 04:00
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
# Objective

Partially fixes bevyengine#16736.

## Solution

`AnimatedField::new_unchecked` now supports tuple struct fields.
`animated_field!` is unchanged.

## Testing

Added a test to make sure common and simple uses of
`AnimatedField::new_unchecked` with tuple structs don't panic.

---------

Co-authored-by: yonzebu <yonzebu@gmail.com>
github-merge-queue bot pushed a commit that referenced this pull request Jan 8, 2025
# Objective

Allow tuple structs in the animated_field macro.
-  for example `animated_field!(MyTupleStruct::0)`.

Fixes #16736 
- This issue was partially fixed in #16747, where support for tuple
structs was added to `AnimatedField::new_unchecked`.

## Solution

Change the designator for `$field` in the macro from `ident` to `tt`.

## Testing

Expanded the doc test on `animated_field!` to include an example with a
tuple struct.
mrchantey pushed a commit to mrchantey/bevy that referenced this pull request Feb 4, 2025
# Objective

Allow tuple structs in the animated_field macro.
-  for example `animated_field!(MyTupleStruct::0)`.

Fixes bevyengine#16736 
- This issue was partially fixed in bevyengine#16747, where support for tuple
structs was added to `AnimatedField::new_unchecked`.

## Solution

Change the designator for `$field` in the macro from `ident` to `tt`.

## Testing

Expanded the doc test on `animated_field!` to include an example with a
tuple struct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Animation Make things move and change over time C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to the animated_field! macro for tuple structs
5 participants