diff --git a/Cargo.toml b/Cargo.toml index 79d7b483e550b..e17c737f90f93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -157,7 +157,7 @@ bevy_ui_picking_backend = [ ] # Provides a debug overlay for bevy UI -bevy_ui_debug = [] +bevy_ui_debug = ["bevy_internal/bevy_ui_debug"] # Force dynamic linking, which improves iterative compile times dynamic_linking = ["dep:bevy_dylib", "bevy_internal/dynamic_linking"] diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index c6f3fed2d9eed..3acc57d16cbf0 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -235,6 +235,9 @@ bevy_sprite_picking_backend = [ # Provides a UI picking backend bevy_ui_picking_backend = ["bevy_picking", "bevy_ui/bevy_ui_picking_backend"] +# Provides a UI debug overlay +bevy_ui_debug = ["bevy_ui?/bevy_ui_debug"] + # Enable support for the ios_simulator by downgrading some rendering capabilities ios_simulator = ["bevy_pbr?/ios_simulator", "bevy_render?/ios_simulator"] diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 35bd8677c4a15..4039930b7654c 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -37,16 +37,19 @@ pub use focus::*; pub use geometry::*; pub use layout::*; pub use measurement::*; -use render::debug_overlay::UiDebugOptions; pub use render::*; pub use ui_material::*; pub use ui_node::*; + use widget::{ImageNode, ImageNodeSize}; /// The UI prelude. /// /// This includes the most common types in this crate, re-exported for your convenience. pub mod prelude { + #[doc(hidden)] + #[cfg(feature = "bevy_ui_debug")] + pub use crate::render::UiDebugOptions; #[allow(deprecated)] #[doc(hidden)] pub use crate::widget::TextBundle; @@ -231,6 +234,7 @@ impl Plugin for UiPlugin { return; } + #[cfg(feature = "bevy_ui_debug")] app.init_resource::(); build_ui_render(app); diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 540cc618322e4..b7801584feb05 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -1,10 +1,12 @@ pub mod box_shadow; -pub mod debug_overlay; mod pipeline; mod render_pass; mod ui_material_pipeline; pub mod ui_texture_slice_pipeline; +#[cfg(feature = "bevy_ui_debug")] +mod debug_overlay; + use crate::widget::ImageNode; use crate::{ experimental::UiChildren, BackgroundColor, BorderColor, BoxShadowSamples, CalculatedClip, @@ -42,7 +44,8 @@ use bevy_render::{ }; use bevy_sprite::TextureAtlasLayout; use bevy_sprite::{BorderRect, SpriteAssetEvents}; -use debug_overlay::extract_debug_overlay; +#[cfg(feature = "bevy_ui_debug")] +pub use debug_overlay::UiDebugOptions; use crate::{Display, Node}; use bevy_text::{ComputedTextBlock, PositionedGlyph, TextColor, TextLayoutInfo}; @@ -100,7 +103,7 @@ pub enum RenderUiSystem { ExtractTextureSlice, ExtractBorders, ExtractText, - ExtractDebugOverlay, + ExtractDebug, } pub fn build_ui_render(app: &mut App) { @@ -128,7 +131,7 @@ pub fn build_ui_render(app: &mut App) { RenderUiSystem::ExtractTextureSlice, RenderUiSystem::ExtractBorders, RenderUiSystem::ExtractText, - RenderUiSystem::ExtractDebugOverlay, + RenderUiSystem::ExtractDebug, ) .chain(), ) @@ -140,7 +143,8 @@ pub fn build_ui_render(app: &mut App) { extract_uinode_images.in_set(RenderUiSystem::ExtractImages), extract_uinode_borders.in_set(RenderUiSystem::ExtractBorders), extract_text_sections.in_set(RenderUiSystem::ExtractText), - extract_debug_overlay.in_set(RenderUiSystem::ExtractDebugOverlay), + #[cfg(feature = "bevy_ui_debug")] + debug_overlay::extract_debug_overlay.in_set(RenderUiSystem::ExtractDebug), ), ) .add_systems( diff --git a/examples/testbed/ui.rs b/examples/testbed/ui.rs index b30dab0e5c703..677576cf12bf2 100644 --- a/examples/testbed/ui.rs +++ b/examples/testbed/ui.rs @@ -18,7 +18,7 @@ fn main() { .add_systems(Startup, setup) .add_systems(Update, update_scroll_position); - #[cfg(feature = "bevy_ui_debug_overlay")] + #[cfg(feature = "bevy_ui_debug")] app.add_systems(Update, toggle_debug_overlay); app.run(); @@ -344,12 +344,9 @@ fn setup(mut commands: Commands, asset_server: Res) { }); } -#[cfg(feature = "bevy_ui_debug_overlay")] +#[cfg(feature = "bevy_ui_debug")] // The system that will enable/disable the debug outlines around the nodes -fn toggle_debug_overlay( - input: Res>, - mut options: ResMut, -) { +fn toggle_debug_overlay(input: Res>, mut options: ResMut) { info_once!("The debug outlines are enabled, press Space to turn them on/off"); if input.just_pressed(KeyCode::Space) { // The toggle method will enable the debug_overlay if disabled and disable if enabled