From 3f535d54eb125130a79cbd5d7e5cd76fe13e18df Mon Sep 17 00:00:00 2001 From: Atomei Alexandru <118962363+Ato2207@users.noreply.github.com> Date: Wed, 3 Jan 2024 20:57:05 +0200 Subject: [PATCH] =?UTF-8?q?Made=20the=20remaining=20types=20from=20bevy=5F?= =?UTF-8?q?ui=20to=20reflect=20the=20Default=20trait=20if=E2=80=A6=20(#111?= =?UTF-8?q?99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - Fixes https://github.com/bevyengine/bevy/issues/11197 ## Solution - Made the remaining types from bevy_ui that do not reflect the Default trait to do it if possible. --- crates/bevy_ui/src/focus.rs | 8 ++++---- crates/bevy_ui/src/geometry.rs | 7 +++++-- crates/bevy_ui/src/ui_node.rs | 36 +++++++++++++++++----------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 36ebfc18022ad..b2f195c92fbbc 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -9,7 +9,7 @@ use bevy_ecs::{ }; use bevy_input::{mouse::MouseButton, touch::Touches, ButtonInput}; use bevy_math::{Rect, Vec2}; -use bevy_reflect::Reflect; +use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::{camera::NormalizedRenderTarget, prelude::Camera, view::ViewVisibility}; use bevy_transform::components::GlobalTransform; @@ -34,7 +34,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; /// Note that you can also control the visibility of a node using the [`Display`](crate::ui_node::Display) property, /// which fully collapses it during layout calculations. #[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect)] -#[reflect(Component, PartialEq)] +#[reflect(Component, Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -67,7 +67,7 @@ impl Default for Interaction { /// /// It can be used alongside interaction to get the position of the press. #[derive(Component, Copy, Clone, Default, PartialEq, Debug, Reflect)] -#[reflect(Component, PartialEq)] +#[reflect(Component, Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -92,7 +92,7 @@ impl RelativeCursorPosition { /// Describes whether the node should block interactions with lower nodes #[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect)] -#[reflect(Component, PartialEq)] +#[reflect(Component, Default, PartialEq)] #[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 bf970f4cceb7c..c4cf096bc687d 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -1,4 +1,5 @@ use bevy_math::Vec2; +use bevy_reflect::std_traits::ReflectDefault; use bevy_reflect::Reflect; use std::ops::Neg; use std::ops::{Div, DivAssign, Mul, MulAssign}; @@ -11,8 +12,9 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; /// /// This enum allows specifying values for various [`Style`](crate::Style) properties in different units, /// such as logical pixels, percentages, or automatically determined values. + #[derive(Copy, Clone, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -245,8 +247,9 @@ impl Val { /// bottom: Val::Px(40.0), /// }; /// ``` + #[derive(Copy, Clone, PartialEq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 773da577a5b2e..83c2de55e4f73 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -469,7 +469,7 @@ impl Default for Style { /// /// #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -512,7 +512,7 @@ impl Default for AlignItems { /// /// #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -549,7 +549,7 @@ impl Default for JustifyItems { /// /// #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -592,7 +592,7 @@ impl Default for AlignSelf { /// /// #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -629,7 +629,7 @@ impl Default for JustifySelf { /// /// #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -676,7 +676,7 @@ impl Default for AlignContent { /// /// #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -721,7 +721,7 @@ impl Default for JustifyContent { /// /// For example, English is written LTR (left-to-right) while Arabic is written RTL (right-to-left). #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -750,7 +750,7 @@ impl Default for Direction { /// /// Part of the [`Style`] component. #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -780,7 +780,7 @@ impl Default for Display { /// Defines how flexbox items are ordered within a flexbox #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -809,7 +809,7 @@ impl Default for FlexDirection { /// Whether to show or hide overflowing items #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -874,7 +874,7 @@ impl Default for Overflow { /// Whether to show or hide overflowing items #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -904,7 +904,7 @@ impl Default for OverflowAxis { /// The strategy used to position this node #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -929,7 +929,7 @@ impl Default for PositionType { /// Defines if flexbox items appear on a single line or on multiple lines #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -963,7 +963,7 @@ impl Default for FlexWrap { /// /// #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -1042,7 +1042,7 @@ pub enum MaxTrackSizingFunction { /// A [`GridTrack`] is a Row or Column of a CSS Grid. This struct specifies what size the track should be. /// See below for the different "track sizing functions" you can specify. #[derive(Copy, Clone, PartialEq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -1375,7 +1375,7 @@ impl From for Vec { } #[derive(Copy, Clone, PartialEq, Eq, Debug, Reflect)] -#[reflect(PartialEq)] +#[reflect(Default, PartialEq)] #[cfg_attr( feature = "serialize", derive(serde::Serialize, serde::Deserialize), @@ -1768,7 +1768,7 @@ impl From> for UiImage { /// The calculated clip of the node #[derive(Component, Default, Copy, Clone, Debug, Reflect)] -#[reflect(Component)] +#[reflect(Component, Default)] pub struct CalculatedClip { /// The rect of the clip pub clip: Rect, @@ -1788,7 +1788,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, Reflect)] -#[reflect(Component)] +#[reflect(Component, Default)] pub enum ZIndex { /// Indicates the order in which this node should be rendered relative to its siblings. Local(i32),