Skip to content

Commit f0ff7fb

Browse files
authored
Add and reflect Default impls for CSS grid types (#14443)
# Objective - Some types here were not constructible via reflection, and some were missing fairly obvious `Default` values. - Some types used `#[reflect_value]` for some unstated reason, making them opaque to reflection-based code. ## Solution - Add and reflect some `Default` impls, and stop using `#[reflect_value]`.
1 parent abaea01 commit f0ff7fb

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

crates/bevy_ui/src/ui_node.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,12 +1007,12 @@ impl Default for GridAutoFlow {
10071007
}
10081008
}
10091009

1010-
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
1011-
#[reflect_value(PartialEq)]
1010+
#[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
1011+
#[reflect(Default, PartialEq)]
10121012
#[cfg_attr(
10131013
feature = "serialize",
10141014
derive(serde::Serialize, serde::Deserialize),
1015-
reflect_value(Serialize, Deserialize)
1015+
reflect(Serialize, Deserialize)
10161016
)]
10171017
pub enum MinTrackSizingFunction {
10181018
/// Track minimum size should be a fixed pixel value
@@ -1024,6 +1024,7 @@ pub enum MinTrackSizingFunction {
10241024
/// Track minimum size should be content sized under a max-content constraint
10251025
MaxContent,
10261026
/// Track minimum size should be automatically sized
1027+
#[default]
10271028
Auto,
10281029
/// Track minimum size should be a percent of the viewport's smaller dimension.
10291030
VMin(f32),
@@ -1035,12 +1036,12 @@ pub enum MinTrackSizingFunction {
10351036
Vw(f32),
10361037
}
10371038

1038-
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
1039-
#[reflect_value(PartialEq)]
1039+
#[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
1040+
#[reflect(Default, PartialEq)]
10401041
#[cfg_attr(
10411042
feature = "serialize",
10421043
derive(serde::Serialize, serde::Deserialize),
1043-
reflect_value(Serialize, Deserialize)
1044+
reflect(Serialize, Deserialize)
10441045
)]
10451046
pub enum MaxTrackSizingFunction {
10461047
/// Track maximum size should be a fixed pixel value
@@ -1056,6 +1057,7 @@ pub enum MaxTrackSizingFunction {
10561057
/// Track maximum size should be sized according to the fit-content formula with a percentage limit
10571058
FitContentPercent(f32),
10581059
/// Track maximum size should be automatically sized
1060+
#[default]
10591061
Auto,
10601062
/// The dimension as a fraction of the total available grid space (`fr` units in CSS)
10611063
/// Specified value is the numerator of the fraction. Denominator is the sum of all fractions specified in that grid dimension.
@@ -1234,7 +1236,7 @@ impl Default for GridTrack {
12341236
}
12351237

12361238
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
1237-
#[reflect(PartialEq)]
1239+
#[reflect(Default, PartialEq)]
12381240
#[cfg_attr(
12391241
feature = "serialize",
12401242
derive(serde::Serialize, serde::Deserialize),
@@ -1257,6 +1259,12 @@ pub enum GridTrackRepetition {
12571259
AutoFit,
12581260
}
12591261

1262+
impl Default for GridTrackRepetition {
1263+
fn default() -> Self {
1264+
Self::Count(1)
1265+
}
1266+
}
1267+
12601268
impl From<u16> for GridTrackRepetition {
12611269
fn from(count: u16) -> Self {
12621270
Self::Count(count)
@@ -1289,7 +1297,7 @@ impl From<usize> for GridTrackRepetition {
12891297
/// then all tracks (in and outside of the repetition) must be fixed size (px or percent). Integer repetitions are just shorthand for writing out
12901298
/// N tracks longhand and are not subject to the same limitations.
12911299
#[derive(Clone, PartialEq, Debug, Reflect)]
1292-
#[reflect(PartialEq)]
1300+
#[reflect(Default, PartialEq)]
12931301
#[cfg_attr(
12941302
feature = "serialize",
12951303
derive(serde::Serialize, serde::Deserialize),
@@ -1446,6 +1454,15 @@ impl RepeatedGridTrack {
14461454
}
14471455
}
14481456

1457+
impl Default for RepeatedGridTrack {
1458+
fn default() -> Self {
1459+
Self {
1460+
repetition: Default::default(),
1461+
tracks: SmallVec::from_buf([GridTrack::default()]),
1462+
}
1463+
}
1464+
}
1465+
14491466
impl From<GridTrack> for RepeatedGridTrack {
14501467
fn from(track: GridTrack) -> Self {
14511468
Self {
@@ -1457,10 +1474,7 @@ impl From<GridTrack> for RepeatedGridTrack {
14571474

14581475
impl From<GridTrack> for Vec<GridTrack> {
14591476
fn from(track: GridTrack) -> Self {
1460-
vec![GridTrack {
1461-
min_sizing_function: track.min_sizing_function,
1462-
max_sizing_function: track.max_sizing_function,
1463-
}]
1477+
vec![track]
14641478
}
14651479
}
14661480

0 commit comments

Comments
 (0)