From 5f0674f6c3015d0e495cb74d473efdd392e71cbb Mon Sep 17 00:00:00 2001 From: Jakob Wolf Date: Wed, 8 Jan 2025 20:04:32 +0100 Subject: [PATCH] Allow tuple structs in animated_field! macro (#17234) # 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. --- crates/bevy_animation/src/animation_curves.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/bevy_animation/src/animation_curves.rs b/crates/bevy_animation/src/animation_curves.rs index 40256485ebc6b..f31f54f8da778 100644 --- a/crates/bevy_animation/src/animation_curves.rs +++ b/crates/bevy_animation/src/animation_curves.rs @@ -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; @@ -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 })