Skip to content

Commit 03f63a6

Browse files
committed
Make UIPlugin work without rendering
Achieved by making loading of some functions conditional: if RenderPlugin is absent, they are not added.
1 parent 6cec29d commit 03f63a6

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

crates/bevy_ui/src/lib.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub use margins::*;
1818
pub use render::*;
1919
pub use ui_node::*;
2020

21+
use bevy_render::RenderPlugin;
22+
2123
#[doc(hidden)]
2224
pub mod prelude {
2325
#[doc(hidden)]
@@ -76,15 +78,7 @@ impl Plugin for UiPlugin {
7678
CoreStage::PreUpdate,
7779
ui_focus_system.label(UiSystem::Focus).after(InputSystem),
7880
)
79-
// add these stages to front because these must run before transform update systems
80-
.add_system_to_stage(
81-
CoreStage::PostUpdate,
82-
widget::text_system.before(UiSystem::Flex),
83-
)
84-
.add_system_to_stage(
85-
CoreStage::PostUpdate,
86-
widget::image_node_system.before(UiSystem::Flex),
87-
)
81+
// Add these stages to front because these must run before transform update systems
8882
.add_system_to_stage(
8983
CoreStage::PostUpdate,
9084
flex_node_system
@@ -102,6 +96,20 @@ impl Plugin for UiPlugin {
10296
update_clipping_system.after(TransformSystem::TransformPropagate),
10397
);
10498

105-
crate::render::build_ui_render(app);
99+
// Allows for UIPlugin to be tested without a renderer
100+
// (text_system and image_node_system depend on textures, which are only
101+
// available with RenderPlugin)
102+
if app.is_plugin_added::<RenderPlugin>() {
103+
app.add_system_to_stage(
104+
CoreStage::PostUpdate,
105+
widget::text_system.before(UiSystem::Flex),
106+
)
107+
.add_system_to_stage(
108+
CoreStage::PostUpdate,
109+
widget::image_node_system.before(UiSystem::Flex),
110+
);
111+
112+
crate::render::build_ui_render(app);
113+
}
106114
}
107115
}

0 commit comments

Comments
 (0)