Reflect derived traits on all components and resources: bevy_ui (#15231)

Solves https://github.com/bevyengine/bevy/issues/15187 for bevy_ui
This commit is contained in:
Blazepaws 2024-09-15 19:52:38 +02:00 committed by GitHub
parent 4d65757b3e
commit cb6ab16c97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 21 additions and 18 deletions

View file

@ -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),

View file

@ -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),

View file

@ -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 {

View file

@ -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<T: Into<Color>> From<T> 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<Handle<Image>> 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 {
///
/// <https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius>
#[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 {

View file

@ -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;

View file

@ -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
///

View file

@ -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;

View file

@ -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,