Skip to content

Commit 7bc8892

Browse files
authored
Update some UI examples (#22701)
# Objective Some UI examples use the Val and UiRect constructor methods inconsistantly or not at all. ## Solution Update some UI examples to use the val and uirect helper functions. ## Testing The output of the examples should be unchanged
1 parent be608a2 commit 7bc8892

File tree

7 files changed

+29
-39
lines changed

7 files changed

+29
-39
lines changed

examples/picking/dragdrop_picking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ fn setup(
3636
commands
3737
.spawn((
3838
Node {
39-
width: Val::Percent(100.0),
40-
height: Val::Percent(100.0),
39+
width: percent(100),
40+
height: percent(100),
4141
align_items: AlignItems::Center,
4242
justify_content: JustifyContent::Start,
4343
..default()

examples/ui/flex_layout.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
2929
height: percent(100),
3030
flex_direction: FlexDirection::Column,
3131
align_items: AlignItems::Center,
32-
padding: UiRect::all(MARGIN),
32+
padding: MARGIN.all(),
3333
row_gap: MARGIN,
3434
..Default::default()
3535
},
@@ -47,7 +47,7 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
4747
builder,
4848
font.clone(),
4949
ALIGN_ITEMS_COLOR,
50-
UiRect::right(MARGIN),
50+
MARGIN.right(),
5151
"AlignItems",
5252
);
5353
spawn_nested_text_bundle(
@@ -133,13 +133,7 @@ fn spawn_child_node(
133133
];
134134
for (text, color, top_margin) in labels {
135135
// We nest the text within a parent node because margins and padding can't be directly applied to text nodes currently.
136-
spawn_nested_text_bundle(
137-
builder,
138-
font.clone(),
139-
color,
140-
UiRect::top(px(top_margin)),
141-
&text,
142-
);
136+
spawn_nested_text_bundle(builder, font.clone(), color, px(top_margin).top(), &text);
143137
}
144138
});
145139
}

examples/ui/image_node_resizing.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
9292
TextColor::BLACK,
9393
Node {
9494
grid_row: GridPlacement::span(1),
95-
padding: UiRect::all(px(6)),
95+
padding: px(6).all(),
9696
..default()
9797
},
9898
UiDebugOptions {
@@ -110,7 +110,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
110110
grid_row: GridPlacement::span(1),
111111
flex_direction: FlexDirection::Column,
112112
justify_content: JustifyContent::SpaceAround,
113-
padding: UiRect::all(Val::Px(10.)),
113+
padding: px(10.).all(),
114114
..default()
115115
},
116116
BackgroundColor(Color::BLACK),
@@ -124,8 +124,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
124124
Node {
125125
display: Display::Flex,
126126
justify_content: JustifyContent::Start,
127-
width: Val::Percent(IMAGE_GROUP_BOX_INIT_WIDTH),
128-
height: Val::Percent(IMAGE_GROUP_BOX_INIT_HEIGHT),
127+
width: percent(IMAGE_GROUP_BOX_INIT_WIDTH),
128+
height: percent(IMAGE_GROUP_BOX_INIT_HEIGHT),
129129
..default()
130130
},
131131
BackgroundColor(Color::from(tailwind::BLUE_100)),
@@ -150,8 +150,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
150150
Node {
151151
display: Display::Flex,
152152
justify_content: JustifyContent::Start,
153-
width: Val::Percent(IMAGE_GROUP_BOX_INIT_WIDTH),
154-
height: Val::Percent(IMAGE_GROUP_BOX_INIT_HEIGHT),
153+
width: percent(IMAGE_GROUP_BOX_INIT_WIDTH),
154+
height: percent(IMAGE_GROUP_BOX_INIT_HEIGHT),
155155
..default()
156156
},
157157
BackgroundColor(Color::from(tailwind::BLUE_100)),
@@ -160,8 +160,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
160160
for width in [10., 20., 30., 40.] {
161161
parent.spawn((
162162
Node {
163-
height: Val::Percent(100.),
164-
width: Val::Percent(width),
163+
height: percent(100),
164+
width: percent(width),
165165
..default()
166166
},
167167
ImageNode {
@@ -247,27 +247,23 @@ fn on_trigger_image_group(event: On<ImageGroupResize>, query: Query<&mut Node, W
247247
for mut node in query {
248248
match event.event() {
249249
ImageGroupResize::HeightGrow => {
250-
if let Val::Percent(val) = node.height {
251-
let new_val = (val + MIN_RESIZE_VAL).min(IMAGE_GROUP_BOX_MAX_HEIGHT);
252-
node.height = Val::Percent(new_val);
250+
if let Val::Percent(val) = &mut node.height {
251+
*val = (*val + MIN_RESIZE_VAL).min(IMAGE_GROUP_BOX_MAX_HEIGHT);
253252
}
254253
}
255254
ImageGroupResize::HeightShrink => {
256-
if let Val::Percent(val) = node.height {
257-
let new_val = (val - MIN_RESIZE_VAL).max(IMAGE_GROUP_BOX_MIN_HEIGHT);
258-
node.height = Val::Percent(new_val);
255+
if let Val::Percent(val) = &mut node.height {
256+
*val = (*val - MIN_RESIZE_VAL).max(IMAGE_GROUP_BOX_MIN_HEIGHT);
259257
}
260258
}
261259
ImageGroupResize::WidthGrow => {
262-
if let Val::Percent(val) = node.width {
263-
let new_val = (val + MIN_RESIZE_VAL).min(IMAGE_GROUP_BOX_MAX_WIDTH);
264-
node.width = Val::Percent(new_val);
260+
if let Val::Percent(val) = &mut node.width {
261+
*val = (*val + MIN_RESIZE_VAL).min(IMAGE_GROUP_BOX_MAX_WIDTH);
265262
}
266263
}
267264
ImageGroupResize::WidthShrink => {
268-
if let Val::Percent(val) = node.width {
269-
let new_val = (val - MIN_RESIZE_VAL).max(IMAGE_GROUP_BOX_MIN_WIDTH);
270-
node.width = Val::Percent(new_val);
265+
if let Val::Percent(val) = &mut node.width {
266+
*val = (*val - MIN_RESIZE_VAL).max(IMAGE_GROUP_BOX_MIN_WIDTH);
271267
}
272268
}
273269
}

examples/ui/standard_widgets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ fn spawn_menu(anchor: Entity, assets: Res<AssetServer>, mut commands: Commands)
831831
display: Display::Flex,
832832
flex_direction: FlexDirection::Column,
833833
min_height: px(10.),
834-
min_width: Val::Percent(100.),
834+
min_width: percent(100),
835835
border: UiRect::all(px(1)),
836836
position_type: PositionType::Absolute,
837837
..default()

examples/ui/strikethrough_and_underline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
3636
commands.spawn((
3737
Node {
3838
flex_direction: FlexDirection::Column,
39-
width: Val::Percent(100.),
40-
height: Val::Percent(100.),
39+
width: percent(100),
40+
height: percent(100),
4141
justify_content: JustifyContent::Center,
4242
align_items: AlignItems::Center,
4343
..Default::default()

examples/ui/ui_drag_and_drop.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ fn setup(mut commands: Commands) {
3535
parent
3636
.spawn((
3737
Node {
38-
width: Val::Px(TILE_SIZE),
39-
height: Val::Px(TILE_SIZE),
40-
border: UiRect::all(Val::Px(4.)),
38+
width: px(TILE_SIZE),
39+
height: px(TILE_SIZE),
40+
border: px(4.).all(),
4141
grid_row: GridPlacement::start(row + 1),
4242
grid_column: GridPlacement::start(column + 1),
4343
align_items: AlignItems::Center,
@@ -47,7 +47,7 @@ fn setup(mut commands: Commands) {
4747
BorderColor::all(tile_border_color),
4848
BackgroundColor(tile_color),
4949
Outline {
50-
width: Val::Px(2.),
50+
width: px(2.),
5151
offset: Val::ZERO,
5252
color: Color::NONE,
5353
},

examples/ui/ui_texture_atlas_slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn setup(
9494
justify_content: JustifyContent::Center,
9595
// vertically center child text
9696
align_items: AlignItems::Center,
97-
margin: UiRect::all(px(20)),
97+
margin: px(20).all(),
9898
..default()
9999
},
100100
))

0 commit comments

Comments
 (0)