Implement serialize and deserialize for some UI types (#10044)

# Objective

- Add serde Deserialize and Serialize for structs that doesn't implement
it, even if they could benefit from it

## Solution

- Derive these traits for the structs Style, BackgroundColor,
BorderColor and Outline.

---
This commit is contained in:
pablo-lua 2023-10-10 15:52:48 -03:00 committed by GitHub
parent a52ca170ac
commit ca873e767f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,8 +117,8 @@ impl Default for Node {
/// - [A Complete Guide To CSS Grid](https://css-tricks.com/snippets/css/complete-guide-grid/) by CSS Tricks. This is detailed guide with illustrations and comprehensive written explanation of the different CSS Grid properties and how they work. /// - [A Complete Guide To CSS Grid](https://css-tricks.com/snippets/css/complete-guide-grid/) by CSS Tricks. This is detailed guide with illustrations and comprehensive written explanation of the different CSS Grid properties and how they work.
/// - [CSS Grid Garden](https://cssgridgarden.com/). An interactive tutorial/game that teaches the essential parts of CSS Grid in a fun engaging way. /// - [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)] #[derive(Component, Clone, PartialEq, Debug, Deserialize, Serialize, Reflect)]
#[reflect(Component, Default, PartialEq)] #[reflect(Component, Default, PartialEq, Deserialize, Serialize)]
pub struct Style { pub struct Style {
/// Which layout algorithm to use when laying out this node's contents: /// Which layout algorithm to use when laying out this node's contents:
/// - [`Display::Flex`]: Use the Flexbox layout algorithm /// - [`Display::Flex`]: Use the Flexbox layout algorithm
@ -1420,8 +1420,8 @@ pub enum GridPlacementError {
/// ///
/// This serves as the "fill" color. /// This serves as the "fill" color.
/// When combined with [`UiImage`], tints the provided texture. /// When combined with [`UiImage`], tints the provided texture.
#[derive(Component, Copy, Clone, Debug, Reflect)] #[derive(Component, Copy, Clone, Debug, Deserialize, Serialize, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Deserialize, Serialize)]
pub struct BackgroundColor(pub Color); pub struct BackgroundColor(pub Color);
impl BackgroundColor { impl BackgroundColor {
@ -1453,8 +1453,8 @@ pub struct UiTextureAtlasImage {
} }
/// The border color of the UI node. /// The border color of the UI node.
#[derive(Component, Copy, Clone, Debug, Reflect)] #[derive(Component, Copy, Clone, Debug, Deserialize, Serialize, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Deserialize, Serialize)]
pub struct BorderColor(pub Color); pub struct BorderColor(pub Color);
impl From<Color> for BorderColor { impl From<Color> for BorderColor {
@ -1473,8 +1473,8 @@ impl Default for BorderColor {
} }
} }
#[derive(Component, Copy, Clone, Default, Debug, Reflect)] #[derive(Component, Copy, Clone, Default, Debug, Deserialize, Serialize, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Deserialize, Serialize)]
/// The [`Outline`] component adds an outline outside the edge of a UI node. /// The [`Outline`] component adds an outline outside the edge of a UI node.
/// Outlines do not take up space in the layout /// Outlines do not take up space in the layout
/// ///