Added vmin and vmax to the gridtrack impls, repeatedgridtrack impls (#13096)
# Objective - Fixes #13094 ## Solution - Added vmin() and vmax() to the `GridTrack` & `RepeatedGridTrack` impls, repeatedgridtrack impls, and both to the variants of Min & Max TrackSizingFunction ## Sidenote This would be my first PR to bevy. Feel free to say anything. Thanks to the Bevy Team for everything you've done! --------- Co-authored-by: Franklin <franklinblanco@tutanota.com>
This commit is contained in:
parent
9ee02e87d3
commit
9c38844fc8
@ -310,6 +310,18 @@ impl MinTrackSizingFunction {
|
||||
MinTrackSizingFunction::Auto => taffy::style::MinTrackSizingFunction::Auto,
|
||||
MinTrackSizingFunction::MinContent => taffy::style::MinTrackSizingFunction::MinContent,
|
||||
MinTrackSizingFunction::MaxContent => taffy::style::MinTrackSizingFunction::MaxContent,
|
||||
MinTrackSizingFunction::VMin(val) => taffy::style::MinTrackSizingFunction::Fixed(
|
||||
Val::VMin(val).into_length_percentage(context),
|
||||
),
|
||||
MinTrackSizingFunction::VMax(val) => taffy::style::MinTrackSizingFunction::Fixed(
|
||||
Val::VMax(val).into_length_percentage(context),
|
||||
),
|
||||
MinTrackSizingFunction::Vh(val) => taffy::style::MinTrackSizingFunction::Fixed(
|
||||
Val::Vh(val).into_length_percentage(context),
|
||||
),
|
||||
MinTrackSizingFunction::Vw(val) => taffy::style::MinTrackSizingFunction::Fixed(
|
||||
Val::Vw(val).into_length_percentage(context),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -339,6 +351,18 @@ impl MaxTrackSizingFunction {
|
||||
MaxTrackSizingFunction::Fraction(fraction) => {
|
||||
taffy::style::MaxTrackSizingFunction::Fraction(fraction)
|
||||
}
|
||||
MaxTrackSizingFunction::VMin(val) => taffy::style::MaxTrackSizingFunction::Fixed(
|
||||
Val::VMin(val).into_length_percentage(context),
|
||||
),
|
||||
MaxTrackSizingFunction::VMax(val) => taffy::style::MaxTrackSizingFunction::Fixed(
|
||||
Val::VMax(val).into_length_percentage(context),
|
||||
),
|
||||
MaxTrackSizingFunction::Vh(val) => taffy::style::MaxTrackSizingFunction::Fixed(
|
||||
Val::Vh(val).into_length_percentage(context),
|
||||
),
|
||||
MaxTrackSizingFunction::Vw(val) => taffy::style::MaxTrackSizingFunction::Fixed(
|
||||
Val::Vw(val).into_length_percentage(context),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1021,6 +1021,14 @@ pub enum MinTrackSizingFunction {
|
||||
MaxContent,
|
||||
/// Track minimum size should be automatically sized
|
||||
Auto,
|
||||
/// Track minimum size should be a percent of the viewport's smaller dimension.
|
||||
VMin(f32),
|
||||
/// Track minimum size should be a percent of the viewport's larger dimension.
|
||||
VMax(f32),
|
||||
/// Track minimum size should be a percent of the viewport's height dimension.
|
||||
Vh(f32),
|
||||
/// Track minimum size should be a percent of the viewport's width dimension.
|
||||
Vw(f32),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
|
||||
@ -1050,6 +1058,14 @@ pub enum MaxTrackSizingFunction {
|
||||
///
|
||||
/// Spec: <https://www.w3.org/TR/css3-grid-layout/#fr-unit>
|
||||
Fraction(f32),
|
||||
/// Track maximum size should be a percent of the viewport's smaller dimension.
|
||||
VMin(f32),
|
||||
/// Track maximum size should be a percent of the viewport's smaller dimension.
|
||||
VMax(f32),
|
||||
/// Track maximum size should be a percent of the viewport's height dimension.
|
||||
Vh(f32),
|
||||
/// Track maximum size should be a percent of the viewport's width dimension.
|
||||
Vw(f32),
|
||||
}
|
||||
|
||||
/// A [`GridTrack`] is a Row or Column of a CSS Grid. This struct specifies what size the track should be.
|
||||
@ -1169,6 +1185,42 @@ impl GridTrack {
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a grid track with a percentage of the viewport's smaller dimension
|
||||
pub fn vmin<T: From<Self>>(value: f32) -> T {
|
||||
Self {
|
||||
min_sizing_function: MinTrackSizingFunction::VMin(value),
|
||||
max_sizing_function: MaxTrackSizingFunction::VMin(value),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a grid track with a percentage of the viewport's larger dimension
|
||||
pub fn vmax<T: From<Self>>(value: f32) -> T {
|
||||
Self {
|
||||
min_sizing_function: MinTrackSizingFunction::VMax(value),
|
||||
max_sizing_function: MaxTrackSizingFunction::VMax(value),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a grid track with a percentage of the viewport's height dimension
|
||||
pub fn vh<T: From<Self>>(value: f32) -> T {
|
||||
Self {
|
||||
min_sizing_function: MinTrackSizingFunction::Vh(value),
|
||||
max_sizing_function: MaxTrackSizingFunction::Vh(value),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a grid track with a percentage of the viewport's width dimension
|
||||
pub fn vw<T: From<Self>>(value: f32) -> T {
|
||||
Self {
|
||||
min_sizing_function: MinTrackSizingFunction::Vw(value),
|
||||
max_sizing_function: MaxTrackSizingFunction::Vw(value),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GridTrack {
|
||||
@ -1341,6 +1393,42 @@ impl RepeatedGridTrack {
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a repeating set of grid tracks with the percentage size of the viewport's smaller dimension
|
||||
pub fn vmin<T: From<Self>>(repetition: impl Into<GridTrackRepetition>, value: f32) -> T {
|
||||
Self {
|
||||
repetition: repetition.into(),
|
||||
tracks: SmallVec::from_buf([GridTrack::vmin(value)]),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a repeating set of grid tracks with the percentage size of the viewport's larger dimension
|
||||
pub fn vmax<T: From<Self>>(repetition: impl Into<GridTrackRepetition>, value: f32) -> T {
|
||||
Self {
|
||||
repetition: repetition.into(),
|
||||
tracks: SmallVec::from_buf([GridTrack::vmax(value)]),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a repeating set of grid tracks with the percentage size of the viewport's height dimension
|
||||
pub fn vh<T: From<Self>>(repetition: impl Into<GridTrackRepetition>, value: f32) -> T {
|
||||
Self {
|
||||
repetition: repetition.into(),
|
||||
tracks: SmallVec::from_buf([GridTrack::vh(value)]),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a repeating set of grid tracks with the percentage size of the viewport's width dimension
|
||||
pub fn vw<T: From<Self>>(repetition: impl Into<GridTrackRepetition>, value: f32) -> T {
|
||||
Self {
|
||||
repetition: repetition.into(),
|
||||
tracks: SmallVec::from_buf([GridTrack::vw(value)]),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Create a repetition of a set of tracks
|
||||
pub fn repeat_many<T: From<Self>>(
|
||||
repetition: impl Into<GridTrackRepetition>,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user