Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/bevy_dev_tools/src/diagnostics_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ROW_COLUMN_GAP: Val = Val::Px(4.);
/// Padding for cels of the diagnostics overlay
const DEFAULT_PADDING: UiRect = UiRect::all(Val::Px(4.));
/// Initial Z-index for the [`DiagnosticsOverlayPlane`]
pub const INITIAL_DIAGNOSTICS_OVERLAY_PLANE_Z_INDEX: GlobalZIndex = GlobalZIndex(1_000_000);
pub const INITIAL_DIAGNOSTICS_OVERLAY_PLANE_Z_INDEX: &str = "bevy_dev_tools::diagnostics_overlay";
/// Alias to shorten the name
type StandardMaterialAllocator = MaterialAllocatorDiagnosticPlugin<StandardMaterial>;

Expand Down Expand Up @@ -249,6 +249,13 @@ pub struct DiagnosticsOverlayPlugin;

impl Plugin for DiagnosticsOverlayPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<GlobalZLayers>();
let mut layers = app.world_mut().resource_mut::<GlobalZLayers>();
let index = layers
.get_index(crate::fps_overlay::FPS_OVERLAY_ZINDEX)
.or_else(|_| layers.get_index(crate::picking_debug::DEBUG_PICKING_LAYER))
.map_or(layers.len(), |index| index as usize);
layers.insert(index, INITIAL_DIAGNOSTICS_OVERLAY_PLANE_Z_INDEX.into());
app.init_resource::<DiagnosticsOverlayStyle>();
app.configure_sets(Update, DiagnosticsOverlaySystems::Rebuild);
app.add_systems(PreStartup, build_plane);
Expand Down Expand Up @@ -280,7 +287,7 @@ fn build_plane(mut commands: Commands) {
should_block_lower: false,
..Default::default()
},
INITIAL_DIAGNOSTICS_OVERLAY_PLANE_Z_INDEX,
GlobalZIndex::new(INITIAL_DIAGNOSTICS_OVERLAY_PLANE_Z_INDEX),
));
}

Expand Down
15 changes: 10 additions & 5 deletions crates/bevy_dev_tools/src/fps_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use bevy_text::{RemSize, TextColor, TextFont, TextSpan};
use bevy_time::common_conditions::on_timer;
use bevy_ui::{
widget::{Text, TextUiWriter},
ComputedUiRenderTargetInfo, FlexDirection, GlobalZIndex, Node, PositionType, Val,
ComputedUiRenderTargetInfo, FlexDirection, GlobalZIndex, GlobalZLayers, Node, PositionType,
Val,
};
#[cfg(not(all(target_arch = "wasm32", not(feature = "webgpu"))))]
use bevy_ui_render::prelude::MaterialNode;
Expand All @@ -32,9 +33,7 @@ use crate::frame_time_graph::FrameTimeGraphConfigUniform;
use crate::frame_time_graph::{FrameTimeGraphPlugin, FrametimeGraphMaterial};

/// [`GlobalZIndex`] used to render the fps overlay.
///
/// We use a number slightly under `i32::MAX` so you can render on top of it if you really need to.
pub const FPS_OVERLAY_ZINDEX: i32 = i32::MAX - 32;
pub const FPS_OVERLAY_ZINDEX: &str = "bevy_dev_tools::fps_overlay";

// Warn the user if the interval is below this threshold.
const MIN_SAFE_INTERVAL: Duration = Duration::from_millis(50);
Expand Down Expand Up @@ -67,6 +66,12 @@ pub enum FpsOverlaySystems {

impl Plugin for FpsOverlayPlugin {
fn build(&self, app: &mut bevy_app::App) {
app.init_resource::<GlobalZLayers>();
let mut layers = app.world_mut().resource_mut::<GlobalZLayers>();
let index = layers
.get_index(crate::picking_debug::DEBUG_PICKING_LAYER)
.map_or(layers.len(), |index| index as usize);
layers.insert(index, FPS_OVERLAY_ZINDEX.into());
// TODO: Use plugin dependencies, see https://github.com/bevyengine/bevy/issues/69
if !app.is_plugin_added::<FrameTimeDiagnosticsPlugin>() {
app.add_plugins(FrameTimeDiagnosticsPlugin::default());
Expand Down Expand Up @@ -197,7 +202,7 @@ fn setup(
..Default::default()
},
// Render overlay on top of everything
GlobalZIndex(FPS_OVERLAY_ZINDEX),
GlobalZIndex::new(FPS_OVERLAY_ZINDEX),
Pickable::IGNORE,
))
.with_children(|p| {
Expand Down
9 changes: 8 additions & 1 deletion crates/bevy_dev_tools/src/picking_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ impl DebugPickingMode {
#[derive(Debug, Default, Clone)]
pub struct DebugPickingPlugin;

/// [`GlobalZIndex`] used to render the picking debug overlay.
pub const DEBUG_PICKING_LAYER: &str = "bevy_dev_tools::picking_debug";

impl Plugin for DebugPickingPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<GlobalZLayers>();
app.world_mut()
.resource_mut::<GlobalZLayers>()
.push(DEBUG_PICKING_LAYER.into());
app.register_type::<PointerDebugOverlayOf>()
.register_type::<PointerDebugOverlay>()
.init_resource::<DebugPickingMode>()
Expand Down Expand Up @@ -299,7 +306,7 @@ pub fn debug_draw(
..Default::default()
},
BackgroundColor(Color::BLACK.with_alpha(0.75)),
GlobalZIndex(i32::MAX),
GlobalZIndex::new(DEBUG_PICKING_LAYER),
Pickable::IGNORE,
UiTargetCamera(camera),
children![(Text::new(text.clone()), TextFont::from_font_size(12.0))],
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_feathers/src/controls/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ impl Default for FeathersDialogProps {
}
}

/// [`GlobalZIndex`] layer used by [`FeathersDialog`].
pub const FEATHERS_DIALOG_LAYER: &str = "bevy_feathers::dialog";

/// A modal dialog box
#[derive(SceneComponent, Default, Clone, Reflect)]
#[scene(FeathersDialogProps)]
Expand All @@ -68,7 +71,7 @@ impl FeathersDialog {
ModalDialogBarrier
FixedNode
OverrideClip
GlobalZIndex(99) // One less than menu layer
GlobalZIndex::new(FEATHERS_DIALOG_LAYER) // One less than menu layer
Children [
Node {
display: Display::Flex,
Expand Down
18 changes: 16 additions & 2 deletions crates/bevy_feathers/src/controls/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use bevy_reflect::Reflect;
use bevy_scene::prelude::*;
use bevy_text::{FontSourceTemplate, FontWeight};
use bevy_ui::{
px, AlignItems, AlignSelf, BoxShadow, Display, FlexDirection, GlobalZIndex,
px, AlignItems, AlignSelf, BoxShadow, Display, FlexDirection, GlobalZIndex, GlobalZLayers,
InteractionDisabled, JustifyContent, Node, OverrideClip, PositionType, Pressed, UiRect,
DEFAULT_GLOBAL_Z_LAYER,
};
use bevy_ui_widgets::{
popover::{Popover, PopoverAlign, PopoverPlacement, PopoverSide},
Expand Down Expand Up @@ -339,6 +340,9 @@ impl FeathersMenuToolButton {
}
}

/// [`GlobalZIndex`] layer used by [`FeathersMenuPopup`].
pub const FEATHERS_MENU_LAYER: &str = "bevy_feathers::menu";

/// A menu popup widget.
#[derive(SceneComponent, Default, Clone, Reflect)]
#[reflect(Component, Default, Clone)]
Expand Down Expand Up @@ -370,7 +374,7 @@ impl FeathersMenuPopup {
px(1),
px(4),
)
GlobalZIndex(100)
GlobalZIndex::new(FEATHERS_MENU_LAYER)
Popover {
positions: vec![
PopoverPlacement {
Expand Down Expand Up @@ -607,6 +611,16 @@ pub struct MenuPlugin;

impl Plugin for MenuPlugin {
fn build(&self, app: &mut bevy_app::App) {
app.init_resource::<GlobalZLayers>();
let mut layers = app.world_mut().resource_mut::<GlobalZLayers>();
let index = layers.get_index(DEFAULT_GLOBAL_Z_LAYER).unwrap() as usize + 1;
layers.splice(
index..index,
[
super::FEATHERS_DIALOG_LAYER.into(),
FEATHERS_MENU_LAYER.into(),
],
);
app.add_systems(
PreUpdate,
(
Expand Down
16 changes: 12 additions & 4 deletions crates/bevy_feathers/src/controls/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use bevy_scene::prelude::*;
use bevy_text::{FontSourceTemplate, FontWeight, LineBreak, TextLayout};
use bevy_ui::{
px, AlignItems, BorderRadius, BoxShadow, ComputedNode, Display, FlexDirection, GlobalZIndex,
InlineDirection, InteractionDisabled, Node, OuterColor, Outline, Overflow, PositionType,
Selected, UiRect, UiSystems, Val,
GlobalZLayers, InlineDirection, InteractionDisabled, Node, OuterColor, Outline, Overflow,
PositionType, Selected, UiRect, UiSystems, Val, DEFAULT_GLOBAL_Z_LAYER,
};
use bevy_ui_widgets::{
ControlOrientation, DragOverlayRoot, DragProxy, SelectedTab, Tab, TabActivation, TabDragMode,
Expand Down Expand Up @@ -57,7 +57,7 @@ const STRIP_INSET: f32 = 3.0;
const STRIP_BORDER: f32 = 1.0;
const INDICATOR_SIZE: f32 = 2.0;
const DRAG_PROXY_OFFSET: Vec2 = Vec2::new(10.0, 10.0);
const DRAG_PROXY_Z: i32 = 200;
const DRAG_PROXY_Z: &str = "bevy_feathers::tab_drag";

/// A themed strip of [`FeathersTab`]s.
///
Expand Down Expand Up @@ -946,7 +946,7 @@ fn spawn_tab_drag_proxy(
border_radius: tab_node.border_radius,
..Default::default()
},
GlobalZIndex(DRAG_PROXY_Z),
GlobalZIndex::new(DRAG_PROXY_Z),
Outline::new(
px(1),
px(0),
Expand Down Expand Up @@ -976,6 +976,14 @@ pub struct FeathersTabsPlugin;

impl Plugin for FeathersTabsPlugin {
fn build(&self, app: &mut bevy_app::App) {
app.init_resource::<GlobalZLayers>();
let mut layers = app.world_mut().resource_mut::<GlobalZLayers>();
let index = layers
.get_index(super::FEATHERS_MENU_LAYER)
.or_else(|_| layers.get_index(DEFAULT_GLOBAL_Z_LAYER))
.unwrap() as usize
+ 1;
layers.insert(index, DRAG_PROXY_Z.into());
app.add_observer(spawn_tab_drag_proxy).add_systems(
PostUpdate,
(
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ parley = { version = "0.11.0", default-features = false, features = ["std"] }
swash = { version = "0.2.6" }
tracing = { version = "0.1", default-features = false, features = ["std"] }


[dev-dependencies]
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.20.0-dev" }

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl Plugin for UiPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<UiScale>()
.init_resource::<UiStack>()
.init_resource::<GlobalZLayers>()
.init_resource::<UiRoots>()
.register_required_components::<
bevy_text::EditableText,
Expand Down
Loading
Loading