Add AUTO and UNDEFINED const constructors for Size (#5761)

# Objective

Very small convenience constructors added to `Size`. 

Does not change current examples too much but I'm working on a rather complex UI use-case where this cuts down on some extra typing :)
This commit is contained in:
Andreas Weibye 2022-08-22 23:08:08 +00:00
parent cde5ae8104
commit 675607a7e6
3 changed files with 16 additions and 4 deletions

View File

@ -214,6 +214,18 @@ impl Size {
pub fn new(width: Val, height: Val) -> Self { pub fn new(width: Val, height: Val) -> Self {
Size { width, height } Size { width, height }
} }
/// Creates a Size where both values are [`Val::Auto`].
pub const AUTO: Size = Size {
width: Val::Auto,
height: Val::Auto,
};
/// Creates a Size where both values are [`Val::Undefined`].
pub const UNDEFINED: Size = Size {
width: Val::Undefined,
height: Val::Undefined,
};
} }
impl Add<Vec2> for Size { impl Add<Vec2> for Size {

View File

@ -197,9 +197,9 @@ impl Default for Style {
flex_grow: 0.0, flex_grow: 0.0,
flex_shrink: 1.0, flex_shrink: 1.0,
flex_basis: Val::Auto, flex_basis: Val::Auto,
size: Size::new(Val::Auto, Val::Auto), size: Size::AUTO,
min_size: Size::new(Val::Auto, Val::Auto), min_size: Size::AUTO,
max_size: Size::new(Val::Auto, Val::Auto), max_size: Size::AUTO,
aspect_ratio: Default::default(), aspect_ratio: Default::default(),
overflow: Default::default(), overflow: Default::default(),
} }

View File

@ -126,7 +126,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
style: Style { style: Style {
flex_direction: FlexDirection::ColumnReverse, flex_direction: FlexDirection::ColumnReverse,
flex_grow: 1.0, flex_grow: 1.0,
max_size: Size::new(Val::Undefined, Val::Undefined), max_size: Size::UNDEFINED,
..default() ..default()
}, },
color: Color::NONE.into(), color: Color::NONE.into(),