Skip to content

Commit eb19a9e

Browse files
VitalyAnkhcart
andauthored
Migrate UI bundles to required components (#15898)
# Objective - Migrate UI bundles to required components, fixes #15889 ## Solution - deprecate `NodeBundle` in favor of `Node` - deprecate `ImageBundle` in favor of `UiImage` - deprecate `ButtonBundle` in favor of `Button` ## Testing CI. ## Migration Guide - Replace all uses of `NodeBundle` with `Node`. e.g. ```diff commands - .spawn(NodeBundle { - style: Style { + .spawn(( + Node::default(), + Style { width: Val::Percent(100.), align_items: AlignItems::Center, justify_content: JustifyContent::Center, ..default() }, - ..default() - }) + )) ``` - Replace all uses of `ButtonBundle` with `Button`. e.g. ```diff .spawn(( - ButtonBundle { - style: Style { - width: Val::Px(w), - height: Val::Px(h), - // horizontally center child text - justify_content: JustifyContent::Center, - // vertically center child text - align_items: AlignItems::Center, - margin: UiRect::all(Val::Px(20.0)), - ..default() - }, - image: image.clone().into(), + Button, + Style { + width: Val::Px(w), + height: Val::Px(h), + // horizontally center child text + justify_content: JustifyContent::Center, + // vertically center child text + align_items: AlignItems::Center, + margin: UiRect::all(Val::Px(20.0)), ..default() }, + UiImage::from(image.clone()), ImageScaleMode::Sliced(slicer.clone()), )) ``` - Replace all uses of `ImageBundle` with `UiImage`. e.g. ```diff - commands.spawn(ImageBundle { - image: UiImage { + commands.spawn(( + UiImage { texture: metering_mask, ..default() }, - style: Style { + Style { width: Val::Percent(100.0), height: Val::Percent(100.0), ..default() }, - ..default() - }); + )); ``` --------- Co-authored-by: Carter Anderson <[email protected]>
1 parent 683d6c9 commit eb19a9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1578
-1731
lines changed

crates/bevy_dev_tools/src/fps_overlay.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use bevy_ecs::{
1515
use bevy_hierarchy::{BuildChildren, ChildBuild};
1616
use bevy_render::view::Visibility;
1717
use bevy_text::{Font, TextColor, TextFont, TextSpan};
18+
use bevy_ui::Node;
1819
use bevy_ui::{
19-
node_bundles::NodeBundle,
2020
widget::{Text, TextUiWriter},
2121
GlobalZIndex, PositionType, Style,
2222
};
@@ -89,15 +89,13 @@ struct FpsText;
8989
fn setup(mut commands: Commands, overlay_config: Res<FpsOverlayConfig>) {
9090
commands
9191
.spawn((
92-
NodeBundle {
93-
style: Style {
94-
// We need to make sure the overlay doesn't affect the position of other UI nodes
95-
position_type: PositionType::Absolute,
96-
..default()
97-
},
98-
// Render overlay on top of everything
92+
Node::default(),
93+
Style {
94+
// We need to make sure the overlay doesn't affect the position of other UI nodes
95+
position_type: PositionType::Absolute,
9996
..default()
10097
},
98+
// Render overlay on top of everything
10199
GlobalZIndex(FPS_OVERLAY_ZINDEX),
102100
))
103101
.with_children(|p| {

crates/bevy_ui/src/experimental/ghost_hierarchy.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ mod tests {
170170
};
171171
use bevy_hierarchy::{BuildChildren, ChildBuild};
172172

173-
use super::{GhostNode, UiChildren, UiRootNodes};
174-
use crate::prelude::NodeBundle;
173+
use super::{GhostNode, Node, UiChildren, UiRootNodes};
175174

176175
#[derive(Component, PartialEq, Debug)]
177176
struct A(usize);
@@ -182,22 +181,22 @@ mod tests {
182181

183182
// Normal root
184183
world
185-
.spawn((A(1), NodeBundle::default()))
184+
.spawn((A(1), Node::default()))
186185
.with_children(|parent| {
187-
parent.spawn((A(2), NodeBundle::default()));
186+
parent.spawn((A(2), Node::default()));
188187
parent
189188
.spawn((A(3), GhostNode::new()))
190-
.with_child((A(4), NodeBundle::default()));
189+
.with_child((A(4), Node::default()));
191190
});
192191

193192
// Ghost root
194193
world
195194
.spawn((A(5), GhostNode::new()))
196195
.with_children(|parent| {
197-
parent.spawn((A(6), NodeBundle::default()));
196+
parent.spawn((A(6), Node::default()));
198197
parent
199198
.spawn((A(7), GhostNode::new()))
200-
.with_child((A(8), NodeBundle::default()))
199+
.with_child((A(8), Node::default()))
201200
.with_child(A(9));
202201
});
203202

@@ -213,17 +212,17 @@ mod tests {
213212
fn iterate_ui_children() {
214213
let world = &mut World::new();
215214

216-
let n1 = world.spawn((A(1), NodeBundle::default())).id();
215+
let n1 = world.spawn((A(1), Node::default())).id();
217216
let n2 = world.spawn((A(2), GhostNode::new())).id();
218217
let n3 = world.spawn((A(3), GhostNode::new())).id();
219-
let n4 = world.spawn((A(4), NodeBundle::default())).id();
220-
let n5 = world.spawn((A(5), NodeBundle::default())).id();
218+
let n4 = world.spawn((A(4), Node::default())).id();
219+
let n5 = world.spawn((A(5), Node::default())).id();
221220

222221
let n6 = world.spawn((A(6), GhostNode::new())).id();
223222
let n7 = world.spawn((A(7), GhostNode::new())).id();
224-
let n8 = world.spawn((A(8), NodeBundle::default())).id();
223+
let n8 = world.spawn((A(8), Node::default())).id();
225224
let n9 = world.spawn((A(9), GhostNode::new())).id();
226-
let n10 = world.spawn((A(10), NodeBundle::default())).id();
225+
let n10 = world.spawn((A(10), Node::default())).id();
227226

228227
let no_ui = world.spawn_empty().id();
229228

crates/bevy_ui/src/focus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
3939
///
4040
/// # See also
4141
///
42-
/// - [`ButtonBundle`](crate::node_bundles::ButtonBundle) which includes this component
42+
/// - [`Button`](crate::widget::Button) which requires this component
4343
/// - [`RelativeCursorPosition`] to obtain the position of the cursor relative to current node
4444
#[derive(Component, Copy, Clone, Eq, PartialEq, Debug, Reflect)]
4545
#[reflect(Component, Default, PartialEq, Debug)]

crates/bevy_ui/src/layout/mod.rs

Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -581,25 +581,25 @@ mod tests {
581581

582582
// spawn a root entity with width and height set to fill 100% of its parent
583583
let ui_root = world
584-
.spawn(NodeBundle {
585-
style: Style {
584+
.spawn((
585+
Node::default(),
586+
Style {
586587
width: Val::Percent(100.),
587588
height: Val::Percent(100.),
588589
..default()
589590
},
590-
..default()
591-
})
591+
))
592592
.id();
593593

594594
let ui_child = world
595-
.spawn(NodeBundle {
596-
style: Style {
595+
.spawn((
596+
Node::default(),
597+
Style {
597598
width: Val::Percent(100.),
598599
height: Val::Percent(100.),
599600
..default()
600601
},
601-
..default()
602-
})
602+
))
603603
.id();
604604

605605
world.entity_mut(ui_root).add_child(ui_child);
@@ -624,7 +624,7 @@ mod tests {
624624
let ui_surface = world.resource::<UiSurface>();
625625
assert!(ui_surface.entity_to_taffy.is_empty());
626626

627-
let ui_entity = world.spawn(NodeBundle::default()).id();
627+
let ui_entity = world.spawn(Node::default()).id();
628628

629629
// `ui_layout_system` should map `ui_entity` to a ui node in `UiSurface::entity_to_taffy`
630630
ui_schedule.run(&mut world);
@@ -666,7 +666,7 @@ mod tests {
666666
let camera_entity = world.spawn(Camera2d).id();
667667

668668
let ui_entity = world
669-
.spawn((NodeBundle::default(), TargetCamera(camera_entity)))
669+
.spawn((Node::default(), TargetCamera(camera_entity)))
670670
.id();
671671

672672
// `ui_layout_system` should map `camera_entity` to a ui node in `UiSurface::camera_entity_to_taffy`
@@ -696,7 +696,7 @@ mod tests {
696696
fn despawning_a_ui_entity_should_remove_its_corresponding_ui_node() {
697697
let (mut world, mut ui_schedule) = setup_ui_test_world();
698698

699-
let ui_entity = world.spawn(NodeBundle::default()).id();
699+
let ui_entity = world.spawn(Node::default()).id();
700700

701701
// `ui_layout_system` will insert a ui node into the internal layout tree corresponding to `ui_entity`
702702
ui_schedule.run(&mut world);
@@ -721,7 +721,7 @@ mod tests {
721721
fn changes_to_children_of_a_ui_entity_change_its_corresponding_ui_nodes_children() {
722722
let (mut world, mut ui_schedule) = setup_ui_test_world();
723723

724-
let ui_parent_entity = world.spawn(NodeBundle::default()).id();
724+
let ui_parent_entity = world.spawn(Node::default()).id();
725725

726726
// `ui_layout_system` will insert a ui node into the internal layout tree corresponding to `ui_entity`
727727
ui_schedule.run(&mut world);
@@ -734,7 +734,7 @@ mod tests {
734734

735735
let mut ui_child_entities = (0..10)
736736
.map(|_| {
737-
let child = world.spawn(NodeBundle::default()).id();
737+
let child = world.spawn(Node::default()).id();
738738
world.entity_mut(ui_parent_entity).add_child(child);
739739
child
740740
})
@@ -828,40 +828,40 @@ mod tests {
828828

829829
let mut size = 150.;
830830

831-
world.spawn(NodeBundle {
832-
style: Style {
831+
world.spawn((
832+
Node::default(),
833+
Style {
833834
// test should pass without explicitly requiring position_type to be set to Absolute
834835
// position_type: PositionType::Absolute,
835836
width: Val::Px(size),
836837
height: Val::Px(size),
837838
..default()
838839
},
839-
..default()
840-
});
840+
));
841841

842842
size -= 50.;
843843

844-
world.spawn(NodeBundle {
845-
style: Style {
844+
world.spawn((
845+
Node::default(),
846+
Style {
846847
// position_type: PositionType::Absolute,
847848
width: Val::Px(size),
848849
height: Val::Px(size),
849850
..default()
850851
},
851-
..default()
852-
});
852+
));
853853

854854
size -= 50.;
855855

856-
world.spawn(NodeBundle {
857-
style: Style {
856+
world.spawn((
857+
Node::default(),
858+
Style {
858859
// position_type: PositionType::Absolute,
859860
width: Val::Px(size),
860861
height: Val::Px(size),
861862
..default()
862863
},
863-
..default()
864-
});
864+
));
865865

866866
ui_schedule.run(&mut world);
867867

@@ -996,13 +996,11 @@ mod tests {
996996
));
997997

998998
world.spawn((
999-
NodeBundle {
1000-
style: Style {
1001-
position_type: PositionType::Absolute,
1002-
top: Val::Px(0.),
1003-
left: Val::Px(0.),
1004-
..default()
1005-
},
999+
Node::default(),
1000+
Style {
1001+
position_type: PositionType::Absolute,
1002+
top: Val::Px(0.),
1003+
left: Val::Px(0.),
10061004
..default()
10071005
},
10081006
MovingUiNode,
@@ -1052,12 +1050,10 @@ mod tests {
10521050

10531051
let ui_entity = world
10541052
.spawn((
1055-
NodeBundle {
1056-
style: Style {
1057-
align_self: AlignSelf::Start,
1058-
..Default::default()
1059-
},
1060-
..Default::default()
1053+
Node::default(),
1054+
Style {
1055+
align_self: AlignSelf::Start,
1056+
..default()
10611057
},
10621058
ContentSize::fixed_size(content_size),
10631059
))
@@ -1080,11 +1076,9 @@ mod tests {
10801076
let content_size = Vec2::new(50., 25.);
10811077
let ui_entity = world
10821078
.spawn((
1083-
NodeBundle {
1084-
style: Style {
1085-
align_self: AlignSelf::Start,
1086-
..Default::default()
1087-
},
1079+
Node::default(),
1080+
Style {
1081+
align_self: AlignSelf::Start,
10881082
..Default::default()
10891083
},
10901084
ContentSize::fixed_size(content_size),
@@ -1121,26 +1115,26 @@ mod tests {
11211115
let (mut world, mut ui_schedule) = setup_ui_test_world();
11221116

11231117
let parent = world
1124-
.spawn(NodeBundle {
1125-
style: Style {
1118+
.spawn((
1119+
Node::default(),
1120+
Style {
11261121
display: Display::Grid,
11271122
grid_template_columns: RepeatedGridTrack::min_content(2),
11281123
margin: UiRect::all(Val::Px(4.0)),
1129-
..Default::default()
1124+
..default()
11301125
},
1131-
..Default::default()
1132-
})
1126+
))
11331127
.with_children(|commands| {
11341128
for _ in 0..2 {
1135-
commands.spawn(NodeBundle {
1136-
style: Style {
1129+
commands.spawn((
1130+
Node::default(),
1131+
Style {
11371132
display: Display::Grid,
11381133
width: Val::Px(160.),
11391134
height: Val::Px(160.),
1140-
..Default::default()
1135+
..default()
11411136
},
1142-
..Default::default()
1143-
});
1137+
));
11441138
}
11451139
})
11461140
.id();
@@ -1211,25 +1205,25 @@ mod tests {
12111205
);
12121206

12131207
let ui_root = world
1214-
.spawn(NodeBundle {
1215-
style: Style {
1208+
.spawn((
1209+
Node::default(),
1210+
Style {
12161211
width: Val::Percent(100.),
12171212
height: Val::Percent(100.),
12181213
..default()
12191214
},
1220-
..default()
1221-
})
1215+
))
12221216
.id();
12231217

12241218
let ui_child = world
1225-
.spawn(NodeBundle {
1226-
style: Style {
1219+
.spawn((
1220+
Node::default(),
1221+
Style {
12271222
width: Val::Percent(100.),
12281223
height: Val::Percent(100.),
12291224
..default()
12301225
},
1231-
..default()
1232-
})
1226+
))
12331227
.id();
12341228

12351229
world.entity_mut(ui_root).add_child(ui_child);

crates/bevy_ui/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
//! This crate contains Bevy's UI system, which can be used to create UI for both 2D and 3D games
1010
//! # Basic usage
11-
//! Spawn UI elements with [`node_bundles::ButtonBundle`], [`node_bundles::ImageBundle`], [`Text`](prelude::Text) and [`node_bundles::NodeBundle`]
11+
//! Spawn UI elements with [`widget::Button`], [`UiImage`], [`Text`](prelude::Text) and [`Node`]
1212
//! This UI is laid out with the Flexbox and CSS Grid layout models (see <https://cssreference.io/flexbox/>)
1313
1414
pub mod measurement;
@@ -59,7 +59,7 @@ pub mod prelude {
5959
ui_material::*,
6060
ui_node::*,
6161
widget::{Button, Label},
62-
Interaction, UiMaterialHandle, UiMaterialPlugin, UiScale,
62+
Interaction, MaterialNode, UiMaterialPlugin, UiScale,
6363
},
6464
// `bevy_sprite` re-exports for texture slicing
6565
bevy_sprite::{BorderRect, ImageScaleMode, SliceScaleMode, TextureSlicer},

0 commit comments

Comments
 (0)