Skip to content

Commit

Permalink
Add AUTO and UNDEFINED const constructors for Size (bevyengine#5761)
Browse files Browse the repository at this point in the history
# 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 :)
  • Loading branch information
Weibye authored and maccesch committed Sep 28, 2022
1 parent 3787205 commit 7bf3778
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions crates/bevy_ui/src/geometry.rs
Expand Up @@ -214,6 +214,18 @@ impl Size {
pub fn new(width: Val, height: Val) -> Self {
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 {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ui/src/ui_node.rs
Expand Up @@ -197,9 +197,9 @@ impl Default for Style {
flex_grow: 0.0,
flex_shrink: 1.0,
flex_basis: Val::Auto,
size: Size::new(Val::Auto, Val::Auto),
min_size: Size::new(Val::Auto, Val::Auto),
max_size: Size::new(Val::Auto, Val::Auto),
size: Size::AUTO,
min_size: Size::AUTO,
max_size: Size::AUTO,
aspect_ratio: Default::default(),
overflow: Default::default(),
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/ui.rs
Expand Up @@ -126,7 +126,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
style: Style {
flex_direction: FlexDirection::ColumnReverse,
flex_grow: 1.0,
max_size: Size::new(Val::Undefined, Val::Undefined),
max_size: Size::UNDEFINED,
..default()
},
color: Color::NONE.into(),
Expand Down

0 comments on commit 7bf3778

Please sign in to comment.