Skip to content

Commit

Permalink
Allow tuple structs in animated_field! macro (#17234)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
wolf-in-space authored Jan 8, 2025
1 parent 6462935 commit 5f0674f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/bevy_animation/src/animation_curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ where
///
/// ```
/// # use bevy_animation::{animation_curves::AnimatedField, animated_field};
/// # use bevy_color::Srgba;
/// # use bevy_ecs::component::Component;
/// # use bevy_math::Vec3;
/// # use bevy_reflect::Reflect;
Expand All @@ -993,10 +994,15 @@ where
/// }
///
/// let field = animated_field!(Transform::translation);
///
/// #[derive(Component, Reflect)]
/// struct Color(Srgba);
///
/// let tuple_field = animated_field!(Color::0);
/// ```
#[macro_export]
macro_rules! animated_field {
($component:ident::$field:ident) => {
($component:ident::$field:tt) => {
AnimatedField::new_unchecked(stringify!($field), |component: &mut $component| {
&mut component.$field
})
Expand Down

0 comments on commit 5f0674f

Please sign in to comment.