Skip to content

Commit d6dc7f6

Browse files
Weibyejames7132
authored andcommitted
Add AUTO and UNDEFINED const constructors for Size (bevyengine#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 :)
1 parent d9a2be6 commit d6dc7f6

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

crates/bevy_ui/src/geometry.rs

+12
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ impl Size {
214214
pub fn new(width: Val, height: Val) -> Self {
215215
Size { width, height }
216216
}
217+
218+
/// Creates a Size where both values are [`Val::Auto`].
219+
pub const AUTO: Size = Size {
220+
width: Val::Auto,
221+
height: Val::Auto,
222+
};
223+
224+
/// Creates a Size where both values are [`Val::Undefined`].
225+
pub const UNDEFINED: Size = Size {
226+
width: Val::Undefined,
227+
height: Val::Undefined,
228+
};
217229
}
218230

219231
impl Add<Vec2> for Size {

crates/bevy_ui/src/ui_node.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ impl Default for Style {
197197
flex_grow: 0.0,
198198
flex_shrink: 1.0,
199199
flex_basis: Val::Auto,
200-
size: Size::new(Val::Auto, Val::Auto),
201-
min_size: Size::new(Val::Auto, Val::Auto),
202-
max_size: Size::new(Val::Auto, Val::Auto),
200+
size: Size::AUTO,
201+
min_size: Size::AUTO,
202+
max_size: Size::AUTO,
203203
aspect_ratio: Default::default(),
204204
overflow: Default::default(),
205205
}

examples/ui/ui.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
126126
style: Style {
127127
flex_direction: FlexDirection::ColumnReverse,
128128
flex_grow: 1.0,
129-
max_size: Size::new(Val::Undefined, Val::Undefined),
129+
max_size: Size::UNDEFINED,
130130
..default()
131131
},
132132
color: Color::NONE.into(),

0 commit comments

Comments
 (0)