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]`.
This commit is contained in:
Sludge 2024-07-22 23:39:59 +02:00 committed by GitHub
parent abaea01e30
commit f0ff7fb544
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1007,12 +1007,12 @@ impl Default for GridAutoFlow {
} }
} }
#[derive(Copy, Clone, PartialEq, Debug, Reflect)] #[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
#[reflect_value(PartialEq)] #[reflect(Default, PartialEq)]
#[cfg_attr( #[cfg_attr(
feature = "serialize", feature = "serialize",
derive(serde::Serialize, serde::Deserialize), derive(serde::Serialize, serde::Deserialize),
reflect_value(Serialize, Deserialize) reflect(Serialize, Deserialize)
)] )]
pub enum MinTrackSizingFunction { pub enum MinTrackSizingFunction {
/// Track minimum size should be a fixed pixel value /// Track minimum size should be a fixed pixel value
@ -1024,6 +1024,7 @@ pub enum MinTrackSizingFunction {
/// Track minimum size should be content sized under a max-content constraint /// Track minimum size should be content sized under a max-content constraint
MaxContent, MaxContent,
/// Track minimum size should be automatically sized /// Track minimum size should be automatically sized
#[default]
Auto, Auto,
/// Track minimum size should be a percent of the viewport's smaller dimension. /// Track minimum size should be a percent of the viewport's smaller dimension.
VMin(f32), VMin(f32),
@ -1035,12 +1036,12 @@ pub enum MinTrackSizingFunction {
Vw(f32), Vw(f32),
} }
#[derive(Copy, Clone, PartialEq, Debug, Reflect)] #[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
#[reflect_value(PartialEq)] #[reflect(Default, PartialEq)]
#[cfg_attr( #[cfg_attr(
feature = "serialize", feature = "serialize",
derive(serde::Serialize, serde::Deserialize), derive(serde::Serialize, serde::Deserialize),
reflect_value(Serialize, Deserialize) reflect(Serialize, Deserialize)
)] )]
pub enum MaxTrackSizingFunction { pub enum MaxTrackSizingFunction {
/// Track maximum size should be a fixed pixel value /// Track maximum size should be a fixed pixel value
@ -1056,6 +1057,7 @@ pub enum MaxTrackSizingFunction {
/// Track maximum size should be sized according to the fit-content formula with a percentage limit /// Track maximum size should be sized according to the fit-content formula with a percentage limit
FitContentPercent(f32), FitContentPercent(f32),
/// Track maximum size should be automatically sized /// Track maximum size should be automatically sized
#[default]
Auto, Auto,
/// The dimension as a fraction of the total available grid space (`fr` units in CSS) /// The dimension as a fraction of the total available grid space (`fr` units in CSS)
/// Specified value is the numerator of the fraction. Denominator is the sum of all fractions specified in that grid dimension. /// 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 {
} }
#[derive(Copy, Clone, PartialEq, Debug, Reflect)] #[derive(Copy, Clone, PartialEq, Debug, Reflect)]
#[reflect(PartialEq)] #[reflect(Default, PartialEq)]
#[cfg_attr( #[cfg_attr(
feature = "serialize", feature = "serialize",
derive(serde::Serialize, serde::Deserialize), derive(serde::Serialize, serde::Deserialize),
@ -1257,6 +1259,12 @@ pub enum GridTrackRepetition {
AutoFit, AutoFit,
} }
impl Default for GridTrackRepetition {
fn default() -> Self {
Self::Count(1)
}
}
impl From<u16> for GridTrackRepetition { impl From<u16> for GridTrackRepetition {
fn from(count: u16) -> Self { fn from(count: u16) -> Self {
Self::Count(count) Self::Count(count)
@ -1289,7 +1297,7 @@ impl From<usize> for GridTrackRepetition {
/// then all tracks (in and outside of the repetition) must be fixed size (px or percent). Integer repetitions are just shorthand for writing out /// then all tracks (in and outside of the repetition) must be fixed size (px or percent). Integer repetitions are just shorthand for writing out
/// N tracks longhand and are not subject to the same limitations. /// N tracks longhand and are not subject to the same limitations.
#[derive(Clone, PartialEq, Debug, Reflect)] #[derive(Clone, PartialEq, Debug, Reflect)]
#[reflect(PartialEq)] #[reflect(Default, PartialEq)]
#[cfg_attr( #[cfg_attr(
feature = "serialize", feature = "serialize",
derive(serde::Serialize, serde::Deserialize), derive(serde::Serialize, serde::Deserialize),
@ -1446,6 +1454,15 @@ impl RepeatedGridTrack {
} }
} }
impl Default for RepeatedGridTrack {
fn default() -> Self {
Self {
repetition: Default::default(),
tracks: SmallVec::from_buf([GridTrack::default()]),
}
}
}
impl From<GridTrack> for RepeatedGridTrack { impl From<GridTrack> for RepeatedGridTrack {
fn from(track: GridTrack) -> Self { fn from(track: GridTrack) -> Self {
Self { Self {
@ -1457,10 +1474,7 @@ impl From<GridTrack> for RepeatedGridTrack {
impl From<GridTrack> for Vec<GridTrack> { impl From<GridTrack> for Vec<GridTrack> {
fn from(track: GridTrack) -> Self { fn from(track: GridTrack) -> Self {
vec![GridTrack { vec![track]
min_sizing_function: track.min_sizing_function,
max_sizing_function: track.max_sizing_function,
}]
} }
} }