From cb6ab16c975d822d2ce0c7bcce80bb71cf9cf377 Mon Sep 17 00:00:00 2001 From: Blazepaws <157802762+blazepaws@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:52:38 +0200 Subject: [PATCH] Reflect derived traits on all components and resources: bevy_ui (#15231) Solves https://github.com/bevyengine/bevy/issues/15187 for bevy_ui --- crates/bevy_ui/src/focus.rs | 6 +++--- crates/bevy_ui/src/geometry.rs | 4 ++-- crates/bevy_ui/src/lib.rs | 2 ++ crates/bevy_ui/src/ui_node.rs | 19 ++++++++++--------- crates/bevy_ui/src/widget/button.rs | 2 +- crates/bevy_ui/src/widget/image.rs | 2 +- crates/bevy_ui/src/widget/label.rs | 2 +- crates/bevy_ui/src/widget/text.rs | 2 +- 8 files changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index c7feeca10f..59f75f1b3c 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -42,7 +42,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; /// - [`ButtonBundle`](crate::node_bundles::ButtonBundle) which includes this component /// - [`RelativeCursorPosition`] to obtain the position of the cursor relative to current node #[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect)] -#[reflect(Component, Default, PartialEq)] +#[reflect(Component, Default, PartialEq, Debug)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -76,7 +76,7 @@ impl Default for Interaction { /// /// The component is updated when it is in the same entity with [`Node`]. #[derive(Component, Copy, Clone, Default, PartialEq, Debug, Reflect)] -#[reflect(Component, Default, PartialEq)] +#[reflect(Component, Default, PartialEq, Debug)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -101,7 +101,7 @@ impl RelativeCursorPosition { /// Describes whether the node should block interactions with lower nodes #[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect)] -#[reflect(Component, Default, PartialEq)] +#[reflect(Component, Default, PartialEq, Debug)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 610fc8fb7a..bd0164bbcc 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -14,7 +14,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; /// such as logical pixels, percentages, or automatically determined values. #[derive(Copy, Clone, Debug, Reflect)] -#[reflect(Default, PartialEq)] +#[reflect(Default, PartialEq, Debug)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -249,7 +249,7 @@ impl Val { /// ``` #[derive(Copy, Clone, PartialEq, Debug, Reflect)] -#[reflect(Default, PartialEq)] +#[reflect(Default, PartialEq, Debug)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 948e52ebfa..f55e875de2 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -21,6 +21,7 @@ pub mod widget; pub mod picking_backend; use bevy_derive::{Deref, DerefMut}; +use bevy_reflect::std_traits::ReflectDefault; use bevy_reflect::Reflect; #[cfg(feature = "bevy_text")] mod accessibility; @@ -100,6 +101,7 @@ pub enum UiSystem { /// A multiplier to fixed-sized ui values. /// **Note:** This will only affect fixed ui values like [`Val::Px`] #[derive(Debug, Reflect, Resource, Deref, DerefMut)] +#[reflect(Resource, Debug, Default)] pub struct UiScale(pub f32); impl Default for UiScale { diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index f43c45bf6c..9fbe8c4437 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -24,7 +24,7 @@ use thiserror::Error; /// to obtain the cursor position relative to this node /// - [`Interaction`](crate::Interaction) to obtain the interaction state of this node #[derive(Component, Debug, Copy, Clone, PartialEq, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] pub struct Node { /// The order of the node in the UI layout. /// Nodes with a higher stack index are drawn on top of and receive interactions before nodes with lower stack indices. @@ -169,7 +169,7 @@ impl Default for Node { /// - [CSS Grid Garden](https://cssgridgarden.com/). An interactive tutorial/game that teaches the essential parts of CSS Grid in a fun engaging way. #[derive(Component, Clone, PartialEq, Debug, Reflect)] -#[reflect(Component, Default, PartialEq)] +#[reflect(Component, Default, PartialEq, Debug)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -1684,7 +1684,7 @@ pub enum GridPlacementError { /// /// This serves as the "fill" color. #[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -1711,7 +1711,7 @@ impl> From for BackgroundColor { /// The border color of the UI node. #[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -1737,7 +1737,7 @@ impl Default for BorderColor { } #[derive(Component, Copy, Clone, Default, Debug, PartialEq, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -1822,7 +1822,7 @@ impl Outline { /// The 2D texture displayed for this UI node #[derive(Component, Clone, Debug, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] pub struct UiImage { /// The tint color used to draw the image. /// @@ -1926,7 +1926,7 @@ impl From> for UiImage { /// The calculated clip of the node #[derive(Component, Default, Copy, Clone, Debug, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] pub struct CalculatedClip { /// The rect of the clip pub clip: Rect, @@ -1946,7 +1946,7 @@ pub struct CalculatedClip { /// /// Nodes without this component will be treated as if they had a value of `ZIndex::Local(0)`. #[derive(Component, Copy, Clone, Debug, PartialEq, Eq, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug, PartialEq)] pub enum ZIndex { /// Indicates the order in which this node should be rendered relative to its siblings. Local(i32), @@ -2002,7 +2002,7 @@ impl Default for ZIndex { /// /// #[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)] -#[reflect(Component, PartialEq, Default)] +#[reflect(Component, PartialEq, Default, Debug)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -2306,6 +2306,7 @@ mod tests { /// /// Optional if there is only one camera in the world. Required otherwise. #[derive(Component, Clone, Debug, Reflect, Eq, PartialEq)] +#[reflect(Component, Debug, PartialEq)] pub struct TargetCamera(pub Entity); impl TargetCamera { diff --git a/crates/bevy_ui/src/widget/button.rs b/crates/bevy_ui/src/widget/button.rs index d28c9ce5cd..dbe1405e92 100644 --- a/crates/bevy_ui/src/widget/button.rs +++ b/crates/bevy_ui/src/widget/button.rs @@ -5,5 +5,5 @@ use bevy_reflect::Reflect; /// Marker struct for buttons #[derive(Component, Debug, Default, Clone, Copy, PartialEq, Eq, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug, PartialEq)] pub struct Button; diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index cf04384404..dc846dbe4b 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -12,7 +12,7 @@ use taffy::{MaybeMath, MaybeResolve}; /// /// This component is updated automatically by [`update_image_content_size_system`] #[derive(Component, Debug, Copy, Clone, Default, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] pub struct UiImageSize { /// The size of the image's texture /// diff --git a/crates/bevy_ui/src/widget/label.rs b/crates/bevy_ui/src/widget/label.rs index 5b4561ac34..4aa7f7e36b 100644 --- a/crates/bevy_ui/src/widget/label.rs +++ b/crates/bevy_ui/src/widget/label.rs @@ -5,5 +5,5 @@ use bevy_reflect::Reflect; /// Marker struct for labels #[derive(Component, Debug, Default, Clone, Copy, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] pub struct Label; diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 515dae7f05..66de4f01b5 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -26,7 +26,7 @@ use taffy::style::AvailableSpace; /// /// Used internally by [`measure_text_system`] and [`text_system`] to schedule text for processing. #[derive(Component, Debug, Clone, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] pub struct TextFlags { /// If set a new measure function for the text node will be created needs_new_measure_func: bool,