Derive default for enums where possible (#5158)
# Objective Fixes #5153 ## Solution Search for all enums and manually check if they have default impls that can use this new derive. By my reckoning: | enum | num | |-|-| | total | 159 | | has default impl | 29 | | default is unit variant | 23 |
This commit is contained in:
parent
747b0c69b0
commit
5e1756954f
@ -109,18 +109,14 @@ where
|
|||||||
marker: PhantomData<fn() -> T>,
|
marker: PhantomData<fn() -> T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Default is only needed because `Handle`'s field `handle_type` is currently ignored for reflection
|
||||||
|
#[derive(Default)]
|
||||||
enum HandleType {
|
enum HandleType {
|
||||||
|
#[default]
|
||||||
Weak,
|
Weak,
|
||||||
Strong(Sender<RefChange>),
|
Strong(Sender<RefChange>),
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This only is needed because `Handle`'s field `handle_type` is currently ignored for reflection
|
|
||||||
impl Default for HandleType {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Weak
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Debug for HandleType {
|
impl Debug for HandleType {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@ -4,20 +4,15 @@ use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
|
|||||||
use bevy_render::{color::Color, extract_resource::ExtractResource};
|
use bevy_render::{color::Color, extract_resource::ExtractResource};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Reflect, Serialize, Deserialize, Clone, Debug)]
|
#[derive(Reflect, Serialize, Deserialize, Clone, Debug, Default)]
|
||||||
#[reflect_value(Serialize, Deserialize)]
|
#[reflect_value(Serialize, Deserialize)]
|
||||||
pub enum ClearColorConfig {
|
pub enum ClearColorConfig {
|
||||||
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
Custom(Color),
|
Custom(Color),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ClearColorConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
ClearColorConfig::Default
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When used as a resource, sets the color that is used to clear the screen between frames.
|
/// When used as a resource, sets the color that is used to clear the screen between frames.
|
||||||
///
|
///
|
||||||
/// This color appears as the "background" color for simple apps, when
|
/// This color appears as the "background" color for simple apps, when
|
||||||
|
|||||||
@ -145,21 +145,16 @@ mod sealed {
|
|||||||
/// #[component(storage = "SparseSet")]
|
/// #[component(storage = "SparseSet")]
|
||||||
/// struct A;
|
/// struct A;
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
|
||||||
pub enum StorageType {
|
pub enum StorageType {
|
||||||
/// Provides fast and cache-friendly iteration, but slower addition and removal of components.
|
/// Provides fast and cache-friendly iteration, but slower addition and removal of components.
|
||||||
/// This is the default storage type.
|
/// This is the default storage type.
|
||||||
|
#[default]
|
||||||
Table,
|
Table,
|
||||||
/// Provides fast addition and removal of components, but slower iteration.
|
/// Provides fast addition and removal of components, but slower iteration.
|
||||||
SparseSet,
|
SparseSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StorageType {
|
|
||||||
fn default() -> Self {
|
|
||||||
StorageType::Table
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ComponentInfo {
|
pub struct ComponentInfo {
|
||||||
id: ComponentId,
|
id: ComponentId,
|
||||||
|
|||||||
@ -4,9 +4,10 @@ use bevy_reflect::Reflect;
|
|||||||
|
|
||||||
// FIXME: This should probably be part of bevy_render2!
|
// FIXME: This should probably be part of bevy_render2!
|
||||||
/// Alpha mode
|
/// Alpha mode
|
||||||
#[derive(Component, Debug, Reflect, Copy, Clone, PartialEq)]
|
#[derive(Component, Debug, Default, Reflect, Copy, Clone, PartialEq)]
|
||||||
#[reflect(Component, Default)]
|
#[reflect(Component, Default)]
|
||||||
pub enum AlphaMode {
|
pub enum AlphaMode {
|
||||||
|
#[default]
|
||||||
Opaque,
|
Opaque,
|
||||||
/// An alpha cutoff must be supplied where alpha values >= the cutoff
|
/// An alpha cutoff must be supplied where alpha values >= the cutoff
|
||||||
/// will be fully opaque and < will be fully transparent
|
/// will be fully opaque and < will be fully transparent
|
||||||
@ -15,9 +16,3 @@ pub enum AlphaMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for AlphaMode {}
|
impl Eq for AlphaMode {}
|
||||||
|
|
||||||
impl Default for AlphaMode {
|
|
||||||
fn default() -> Self {
|
|
||||||
AlphaMode::Opaque
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -24,9 +24,10 @@ const HASH_ATTR: &str = "Hash";
|
|||||||
pub(crate) const REFLECT_DEFAULT: &str = "ReflectDefault";
|
pub(crate) const REFLECT_DEFAULT: &str = "ReflectDefault";
|
||||||
|
|
||||||
/// A marker for trait implementations registered via the `Reflect` derive macro.
|
/// A marker for trait implementations registered via the `Reflect` derive macro.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub(crate) enum TraitImpl {
|
pub(crate) enum TraitImpl {
|
||||||
/// The trait is not registered as implemented.
|
/// The trait is not registered as implemented.
|
||||||
|
#[default]
|
||||||
NotImplemented,
|
NotImplemented,
|
||||||
/// The trait is registered as implemented.
|
/// The trait is registered as implemented.
|
||||||
Implemented,
|
Implemented,
|
||||||
@ -35,13 +36,6 @@ pub(crate) enum TraitImpl {
|
|||||||
/// The trait is registered with a custom function rather than an actual implementation.
|
/// The trait is registered with a custom function rather than an actual implementation.
|
||||||
Custom(Ident),
|
Custom(Ident),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TraitImpl {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::NotImplemented
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A collection of traits that have been registered for a reflected type.
|
/// A collection of traits that have been registered for a reflected type.
|
||||||
///
|
///
|
||||||
/// This keeps track of a few traits that are utilized internally for reflection
|
/// This keeps track of a few traits that are utilized internally for reflection
|
||||||
|
|||||||
@ -22,8 +22,10 @@ pub(crate) struct ReflectFieldAttr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Controls how the default value is determined for a field.
|
/// Controls how the default value is determined for a field.
|
||||||
|
#[derive(Default)]
|
||||||
pub(crate) enum DefaultBehavior {
|
pub(crate) enum DefaultBehavior {
|
||||||
/// Field is required.
|
/// Field is required.
|
||||||
|
#[default]
|
||||||
Required,
|
Required,
|
||||||
/// Field can be defaulted using `Default::default()`.
|
/// Field can be defaulted using `Default::default()`.
|
||||||
Default,
|
Default,
|
||||||
@ -34,12 +36,6 @@ pub(crate) enum DefaultBehavior {
|
|||||||
Func(syn::ExprPath),
|
Func(syn::ExprPath),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DefaultBehavior {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Required
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse all field attributes marked "reflect" (such as `#[reflect(ignore)]`).
|
/// Parse all field attributes marked "reflect" (such as `#[reflect(ignore)]`).
|
||||||
pub(crate) fn parse_field_attrs(attrs: &[Attribute]) -> Result<ReflectFieldAttr, syn::Error> {
|
pub(crate) fn parse_field_attrs(attrs: &[Attribute]) -> Result<ReflectFieldAttr, syn::Error> {
|
||||||
let mut args = ReflectFieldAttr::default();
|
let mut args = ReflectFieldAttr::default();
|
||||||
|
|||||||
@ -307,21 +307,16 @@ impl RenderTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Reflect, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, Default, Reflect, Serialize, Deserialize)]
|
||||||
#[reflect_value(Serialize, Deserialize)]
|
#[reflect_value(Serialize, Deserialize)]
|
||||||
pub enum DepthCalculation {
|
pub enum DepthCalculation {
|
||||||
/// Pythagorean distance; works everywhere, more expensive to compute.
|
/// Pythagorean distance; works everywhere, more expensive to compute.
|
||||||
|
#[default]
|
||||||
Distance,
|
Distance,
|
||||||
/// Optimization for 2D; assuming the camera points towards -Z.
|
/// Optimization for 2D; assuming the camera points towards -Z.
|
||||||
ZDifference,
|
ZDifference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DepthCalculation {
|
|
||||||
fn default() -> Self {
|
|
||||||
DepthCalculation::Distance
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn camera_system<T: CameraProjection + Component>(
|
pub fn camera_system<T: CameraProjection + Component>(
|
||||||
mut window_resized_events: EventReader<WindowResized>,
|
mut window_resized_events: EventReader<WindowResized>,
|
||||||
mut window_created_events: EventReader<WindowCreated>,
|
mut window_created_events: EventReader<WindowCreated>,
|
||||||
|
|||||||
@ -31,10 +31,11 @@ impl Default for Capsule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
/// Manner in which UV coordinates are distributed vertically.
|
/// Manner in which UV coordinates are distributed vertically.
|
||||||
pub enum CapsuleUvProfile {
|
pub enum CapsuleUvProfile {
|
||||||
/// UV space is distributed by how much of the capsule consists of the hemispheres.
|
/// UV space is distributed by how much of the capsule consists of the hemispheres.
|
||||||
|
#[default]
|
||||||
Aspect,
|
Aspect,
|
||||||
/// Hemispheres get UV space according to the ratio of latitudes to rings.
|
/// Hemispheres get UV space according to the ratio of latitudes to rings.
|
||||||
Uniform,
|
Uniform,
|
||||||
@ -43,12 +44,6 @@ pub enum CapsuleUvProfile {
|
|||||||
Fixed,
|
Fixed,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CapsuleUvProfile {
|
|
||||||
fn default() -> Self {
|
|
||||||
CapsuleUvProfile::Aspect
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Capsule> for Mesh {
|
impl From<Capsule> for Mesh {
|
||||||
#[allow(clippy::needless_range_loop)]
|
#[allow(clippy::needless_range_loop)]
|
||||||
fn from(capsule: Capsule) -> Self {
|
fn from(capsule: Capsule) -> Self {
|
||||||
|
|||||||
@ -39,19 +39,14 @@ pub trait RenderAsset: Asset {
|
|||||||
) -> Result<Self::PreparedAsset, PrepareAssetError<Self::ExtractedAsset>>;
|
) -> Result<Self::PreparedAsset, PrepareAssetError<Self::ExtractedAsset>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Hash, Debug, PartialEq, Eq, SystemLabel)]
|
#[derive(Clone, Hash, Debug, Default, PartialEq, Eq, SystemLabel)]
|
||||||
pub enum PrepareAssetLabel {
|
pub enum PrepareAssetLabel {
|
||||||
PreAssetPrepare,
|
PreAssetPrepare,
|
||||||
|
#[default]
|
||||||
AssetPrepare,
|
AssetPrepare,
|
||||||
PostAssetPrepare,
|
PostAssetPrepare,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PrepareAssetLabel {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::AssetPrepare
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This plugin extracts the changed assets from the "app world" into the "render world"
|
/// This plugin extracts the changed assets from the "app world" into the "render world"
|
||||||
/// and prepares them for the GPU. They can then be accessed from the [`RenderAssets`] resource.
|
/// and prepares them for the GPU. They can then be accessed from the [`RenderAssets`] resource.
|
||||||
///
|
///
|
||||||
|
|||||||
@ -115,18 +115,14 @@ pub struct Image {
|
|||||||
/// Used in [`Image`], this determines what image sampler to use when rendering. The default setting,
|
/// Used in [`Image`], this determines what image sampler to use when rendering. The default setting,
|
||||||
/// [`ImageSampler::Default`], will read the sampler from the [`ImageSettings`] resource at runtime.
|
/// [`ImageSampler::Default`], will read the sampler from the [`ImageSettings`] resource at runtime.
|
||||||
/// Setting this to [`ImageSampler::Descriptor`] will override the global default descriptor for this [`Image`].
|
/// Setting this to [`ImageSampler::Descriptor`] will override the global default descriptor for this [`Image`].
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub enum ImageSampler {
|
pub enum ImageSampler {
|
||||||
/// Default image sampler, derived from the [`ImageSettings`] resource.
|
/// Default image sampler, derived from the [`ImageSettings`] resource.
|
||||||
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
/// Custom sampler for this image which will override global default.
|
/// Custom sampler for this image which will override global default.
|
||||||
Descriptor(wgpu::SamplerDescriptor<'static>),
|
Descriptor(wgpu::SamplerDescriptor<'static>),
|
||||||
}
|
}
|
||||||
impl Default for ImageSampler {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Default
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ImageSampler {
|
impl ImageSampler {
|
||||||
/// Returns a sampler descriptor with `Linear` min and mag filters
|
/// Returns a sampler descriptor with `Linear` min and mag filters
|
||||||
|
|||||||
@ -21,9 +21,10 @@ pub struct Sprite {
|
|||||||
|
|
||||||
/// How a sprite is positioned relative to its [`Transform`](bevy_transform::components::Transform).
|
/// How a sprite is positioned relative to its [`Transform`](bevy_transform::components::Transform).
|
||||||
/// It defaults to `Anchor::Center`.
|
/// It defaults to `Anchor::Center`.
|
||||||
#[derive(Debug, Clone, Reflect)]
|
#[derive(Debug, Clone, Default, Reflect)]
|
||||||
#[doc(alias = "pivot")]
|
#[doc(alias = "pivot")]
|
||||||
pub enum Anchor {
|
pub enum Anchor {
|
||||||
|
#[default]
|
||||||
Center,
|
Center,
|
||||||
BottomLeft,
|
BottomLeft,
|
||||||
BottomCenter,
|
BottomCenter,
|
||||||
@ -38,12 +39,6 @@ pub enum Anchor {
|
|||||||
Custom(Vec2),
|
Custom(Vec2),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Anchor {
|
|
||||||
fn default() -> Self {
|
|
||||||
Anchor::Center
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Anchor {
|
impl Anchor {
|
||||||
pub fn as_vec(&self) -> Vec2 {
|
pub fn as_vec(&self) -> Vec2 {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@ -17,7 +17,9 @@ use smallvec::SmallVec;
|
|||||||
/// Describes what type of input interaction has occurred for a UI node.
|
/// Describes what type of input interaction has occurred for a UI node.
|
||||||
///
|
///
|
||||||
/// This is commonly queried with a `Changed<Interaction>` filter.
|
/// This is commonly queried with a `Changed<Interaction>` filter.
|
||||||
#[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize)]
|
#[derive(
|
||||||
|
Component, Copy, Clone, Default, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize,
|
||||||
|
)]
|
||||||
#[reflect_value(Component, Serialize, Deserialize, PartialEq)]
|
#[reflect_value(Component, Serialize, Deserialize, PartialEq)]
|
||||||
pub enum Interaction {
|
pub enum Interaction {
|
||||||
/// The node has been clicked
|
/// The node has been clicked
|
||||||
@ -25,31 +27,22 @@ pub enum Interaction {
|
|||||||
/// The node has been hovered over
|
/// The node has been hovered over
|
||||||
Hovered,
|
Hovered,
|
||||||
/// Nothing has happened
|
/// Nothing has happened
|
||||||
|
#[default]
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Interaction {
|
|
||||||
fn default() -> Self {
|
|
||||||
Interaction::None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Describes whether the node should block interactions with lower nodes
|
/// Describes whether the node should block interactions with lower nodes
|
||||||
#[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize)]
|
#[derive(
|
||||||
|
Component, Copy, Clone, Default, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize,
|
||||||
|
)]
|
||||||
#[reflect_value(Component, Serialize, Deserialize, PartialEq)]
|
#[reflect_value(Component, Serialize, Deserialize, PartialEq)]
|
||||||
pub enum FocusPolicy {
|
pub enum FocusPolicy {
|
||||||
/// Blocks interaction
|
/// Blocks interaction
|
||||||
|
#[default]
|
||||||
Block,
|
Block,
|
||||||
/// Lets interaction pass through
|
/// Lets interaction pass through
|
||||||
Pass,
|
Pass,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FocusPolicy {
|
|
||||||
fn default() -> Self {
|
|
||||||
FocusPolicy::Block
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Contains entities whose Interaction should be set to None
|
/// Contains entities whose Interaction should be set to None
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
|
|||||||
@ -20,10 +20,11 @@ pub struct Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An enum that describes possible types of value in flexbox layout options
|
/// An enum that describes possible types of value in flexbox layout options
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum Val {
|
pub enum Val {
|
||||||
/// No value defined
|
/// No value defined
|
||||||
|
#[default]
|
||||||
Undefined,
|
Undefined,
|
||||||
/// Automatically determine this value
|
/// Automatically determine this value
|
||||||
Auto,
|
Auto,
|
||||||
@ -33,12 +34,6 @@ pub enum Val {
|
|||||||
Percent(f32),
|
Percent(f32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Val {
|
|
||||||
fn default() -> Self {
|
|
||||||
Val::Undefined
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Add<f32> for Val {
|
impl Add<f32> for Val {
|
||||||
type Output = Val;
|
type Output = Val;
|
||||||
|
|
||||||
@ -144,7 +139,7 @@ impl Default for Style {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// How items are aligned according to the cross axis
|
/// How items are aligned according to the cross axis
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum AlignItems {
|
pub enum AlignItems {
|
||||||
/// Items are aligned at the start
|
/// Items are aligned at the start
|
||||||
@ -156,20 +151,16 @@ pub enum AlignItems {
|
|||||||
/// Items are aligned at the baseline
|
/// Items are aligned at the baseline
|
||||||
Baseline,
|
Baseline,
|
||||||
/// Items are stretched across the whole cross axis
|
/// Items are stretched across the whole cross axis
|
||||||
|
#[default]
|
||||||
Stretch,
|
Stretch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AlignItems {
|
|
||||||
fn default() -> AlignItems {
|
|
||||||
AlignItems::Stretch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Works like [`AlignItems`] but applies only to a single item
|
/// Works like [`AlignItems`] but applies only to a single item
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum AlignSelf {
|
pub enum AlignSelf {
|
||||||
/// Use the value of [`AlignItems`]
|
/// Use the value of [`AlignItems`]
|
||||||
|
#[default]
|
||||||
Auto,
|
Auto,
|
||||||
/// If the parent has [`AlignItems::Center`] only this item will be at the start
|
/// If the parent has [`AlignItems::Center`] only this item will be at the start
|
||||||
FlexStart,
|
FlexStart,
|
||||||
@ -183,16 +174,10 @@ pub enum AlignSelf {
|
|||||||
Stretch,
|
Stretch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AlignSelf {
|
|
||||||
fn default() -> AlignSelf {
|
|
||||||
AlignSelf::Auto
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Defines how each line is aligned within the flexbox.
|
/// Defines how each line is aligned within the flexbox.
|
||||||
///
|
///
|
||||||
/// It only applies if [`FlexWrap::Wrap`] is present and if there are multiple lines of items.
|
/// It only applies if [`FlexWrap::Wrap`] is present and if there are multiple lines of items.
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum AlignContent {
|
pub enum AlignContent {
|
||||||
/// Each line moves towards the start of the cross axis
|
/// Each line moves towards the start of the cross axis
|
||||||
@ -202,6 +187,7 @@ pub enum AlignContent {
|
|||||||
/// Each line moves towards the center of the cross axis
|
/// Each line moves towards the center of the cross axis
|
||||||
Center,
|
Center,
|
||||||
/// Each line will stretch to fill the remaining space
|
/// Each line will stretch to fill the remaining space
|
||||||
|
#[default]
|
||||||
Stretch,
|
Stretch,
|
||||||
/// Each line fills the space it needs, putting the remaining space, if any
|
/// Each line fills the space it needs, putting the remaining space, if any
|
||||||
/// inbetween the lines
|
/// inbetween the lines
|
||||||
@ -211,19 +197,14 @@ pub enum AlignContent {
|
|||||||
SpaceAround,
|
SpaceAround,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AlignContent {
|
|
||||||
fn default() -> AlignContent {
|
|
||||||
AlignContent::Stretch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Defines the text direction
|
/// Defines the text direction
|
||||||
///
|
///
|
||||||
/// For example English is written LTR (left-to-right) while Arabic is written RTL (right-to-left).
|
/// For example English is written LTR (left-to-right) while Arabic is written RTL (right-to-left).
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
/// Inherit from parent node
|
/// Inherit from parent node
|
||||||
|
#[default]
|
||||||
Inherit,
|
Inherit,
|
||||||
/// Text is written left to right
|
/// Text is written left to right
|
||||||
LeftToRight,
|
LeftToRight,
|
||||||
@ -231,33 +212,23 @@ pub enum Direction {
|
|||||||
RightToLeft,
|
RightToLeft,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Direction {
|
|
||||||
fn default() -> Direction {
|
|
||||||
Direction::Inherit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether to use Flexbox layout
|
/// Whether to use Flexbox layout
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum Display {
|
pub enum Display {
|
||||||
/// Use flexbox
|
/// Use flexbox
|
||||||
|
#[default]
|
||||||
Flex,
|
Flex,
|
||||||
/// Use no layout, don't render this node and its children
|
/// Use no layout, don't render this node and its children
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Display {
|
|
||||||
fn default() -> Display {
|
|
||||||
Display::Flex
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Defines how flexbox items are ordered within a flexbox
|
/// Defines how flexbox items are ordered within a flexbox
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum FlexDirection {
|
pub enum FlexDirection {
|
||||||
/// Same way as text direction along the main axis
|
/// Same way as text direction along the main axis
|
||||||
|
#[default]
|
||||||
Row,
|
Row,
|
||||||
/// Flex from bottom to top
|
/// Flex from bottom to top
|
||||||
Column,
|
Column,
|
||||||
@ -267,17 +238,12 @@ pub enum FlexDirection {
|
|||||||
ColumnReverse,
|
ColumnReverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FlexDirection {
|
|
||||||
fn default() -> FlexDirection {
|
|
||||||
FlexDirection::Row
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Defines how items are aligned according to the main axis
|
/// Defines how items are aligned according to the main axis
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum JustifyContent {
|
pub enum JustifyContent {
|
||||||
/// Pushed towards the start
|
/// Pushed towards the start
|
||||||
|
#[default]
|
||||||
FlexStart,
|
FlexStart,
|
||||||
/// Pushed towards the end
|
/// Pushed towards the end
|
||||||
FlexEnd,
|
FlexEnd,
|
||||||
@ -291,33 +257,23 @@ pub enum JustifyContent {
|
|||||||
SpaceEvenly,
|
SpaceEvenly,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for JustifyContent {
|
|
||||||
fn default() -> JustifyContent {
|
|
||||||
JustifyContent::FlexStart
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether to show or hide overflowing items
|
/// Whether to show or hide overflowing items
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Reflect, Serialize, Deserialize)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Reflect, Serialize, Deserialize)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum Overflow {
|
pub enum Overflow {
|
||||||
/// Show overflowing items
|
/// Show overflowing items
|
||||||
|
#[default]
|
||||||
Visible,
|
Visible,
|
||||||
/// Hide overflowing items
|
/// Hide overflowing items
|
||||||
Hidden,
|
Hidden,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Overflow {
|
|
||||||
fn default() -> Overflow {
|
|
||||||
Overflow::Visible
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The strategy used to position this node
|
/// The strategy used to position this node
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum PositionType {
|
pub enum PositionType {
|
||||||
/// Relative to all other nodes with the [`PositionType::Relative`] value
|
/// Relative to all other nodes with the [`PositionType::Relative`] value
|
||||||
|
#[default]
|
||||||
Relative,
|
Relative,
|
||||||
/// Independent of all other nodes
|
/// Independent of all other nodes
|
||||||
///
|
///
|
||||||
@ -325,17 +281,12 @@ pub enum PositionType {
|
|||||||
Absolute,
|
Absolute,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PositionType {
|
|
||||||
fn default() -> PositionType {
|
|
||||||
PositionType::Relative
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Defines if flexbox items appear on a single line or on multiple lines
|
/// Defines if flexbox items appear on a single line or on multiple lines
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)]
|
||||||
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
#[reflect_value(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum FlexWrap {
|
pub enum FlexWrap {
|
||||||
/// Single line, will overflow if needed
|
/// Single line, will overflow if needed
|
||||||
|
#[default]
|
||||||
NoWrap,
|
NoWrap,
|
||||||
/// Multiple lines, if needed
|
/// Multiple lines, if needed
|
||||||
Wrap,
|
Wrap,
|
||||||
@ -343,12 +294,6 @@ pub enum FlexWrap {
|
|||||||
WrapReverse,
|
WrapReverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FlexWrap {
|
|
||||||
fn default() -> FlexWrap {
|
|
||||||
FlexWrap::NoWrap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The calculated size of the node
|
/// The calculated size of the node
|
||||||
#[derive(Component, Default, Copy, Clone, Debug, Reflect)]
|
#[derive(Component, Default, Copy, Clone, Debug, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
|
|||||||
@ -12,19 +12,14 @@ use bevy_render::texture::Image;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Describes how to resize the Image node
|
/// Describes how to resize the Image node
|
||||||
#[derive(Component, Debug, Clone, Reflect, Serialize, Deserialize)]
|
#[derive(Component, Debug, Default, Clone, Reflect, Serialize, Deserialize)]
|
||||||
#[reflect_value(Component, Serialize, Deserialize)]
|
#[reflect_value(Component, Serialize, Deserialize)]
|
||||||
pub enum ImageMode {
|
pub enum ImageMode {
|
||||||
/// Keep the aspect ratio of the image
|
/// Keep the aspect ratio of the image
|
||||||
|
#[default]
|
||||||
KeepAspect,
|
KeepAspect,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ImageMode {
|
|
||||||
fn default() -> Self {
|
|
||||||
ImageMode::KeepAspect
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates calculated size of the node based on the image provided
|
/// Updates calculated size of the node based on the image provided
|
||||||
pub fn image_node_system(
|
pub fn image_node_system(
|
||||||
textures: Res<Assets<Image>>,
|
textures: Res<Assets<Image>>,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user