From 7a86c75f51e7498c53479c83556a7b0eadfcb1fe Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Fri, 8 Jul 2022 00:59:39 +0000 Subject: [PATCH] Rename CameraUi (#5234) # Objective In bevy 0.7, `CameraUi` was a component specifically added to cameras that display the UI. Since camera-driven rendering was merged, it actually does the opposite! This will make it difficult for current users to adapt to 0.8. ## Solution To avoid unnecessary confusion, we rename `CameraUi` into `UiCameraConfig`. --- ## Changelog - Rename `CameraUi` to `UiCameraConfig` --- crates/bevy_ui/src/entity.rs | 20 +++++++++++++++----- crates/bevy_ui/src/lib.rs | 4 ++-- crates/bevy_ui/src/render/mod.rs | 9 +++------ crates/bevy_ui/src/render/render_pass.rs | 6 +++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index d62575c2608456..a78d4a64fb656d 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -136,18 +136,28 @@ impl Default for ButtonBundle { } } } +/// Configuration for cameras related to UI. +/// +/// When a [`Camera`] doesn't have the [`UiCameraConfig`] component, +/// it will display the UI by default. +/// +/// [`Camera`]: bevy_render::camera::Camera #[derive(Component, Clone)] -pub struct CameraUi { - pub is_enabled: bool, +pub struct UiCameraConfig { + /// Whether to output UI to this camera view. + /// + /// When a `Camera` doesn't have the [`UiCameraConfig`] component, + /// it will display the UI by default. + pub show_ui: bool, } -impl Default for CameraUi { +impl Default for UiCameraConfig { fn default() -> Self { - Self { is_enabled: true } + Self { show_ui: true } } } -impl ExtractComponent for CameraUi { +impl ExtractComponent for UiCameraConfig { type Query = &'static Self; type Filter = With; diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 135cca188eb49d..149893e669d698 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -33,7 +33,7 @@ use bevy_transform::TransformSystem; use bevy_window::ModifiesWindows; use update::{ui_z_system, update_clipping_system}; -use crate::prelude::CameraUi; +use crate::prelude::UiCameraConfig; /// The basic plugin for Bevy UI #[derive(Default)] @@ -50,7 +50,7 @@ pub enum UiSystem { impl Plugin for UiPlugin { fn build(&self, app: &mut App) { - app.add_plugin(ExtractComponentPlugin::::default()) + app.add_plugin(ExtractComponentPlugin::::default()) .init_resource::() .register_type::() .register_type::() diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 43469a71efcb31..cc356a00df7f84 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -5,7 +5,7 @@ use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d}; pub use pipeline::*; pub use render_pass::*; -use crate::{prelude::CameraUi, CalculatedClip, Node, UiColor, UiImage}; +use crate::{prelude::UiCameraConfig, CalculatedClip, Node, UiColor, UiImage}; use bevy_app::prelude::*; use bevy_asset::{load_internal_asset, AssetEvent, Assets, Handle, HandleUntyped}; use bevy_ecs::prelude::*; @@ -227,14 +227,11 @@ pub struct DefaultCameraView(pub Entity); pub fn extract_default_ui_camera_view( mut commands: Commands, render_world: Res, - query: Query<(Entity, &Camera, Option<&CameraUi>), With>, + query: Query<(Entity, &Camera, Option<&UiCameraConfig>), With>, ) { for (entity, camera, camera_ui) in query.iter() { // ignore cameras with disabled ui - if let Some(&CameraUi { - is_enabled: false, .. - }) = camera_ui - { + if matches!(camera_ui, Some(&UiCameraConfig { show_ui: false, .. })) { continue; } if let (Some(logical_size), Some(physical_size)) = ( diff --git a/crates/bevy_ui/src/render/render_pass.rs b/crates/bevy_ui/src/render/render_pass.rs index 36a51b61a7c343..2a129694f71a31 100644 --- a/crates/bevy_ui/src/render/render_pass.rs +++ b/crates/bevy_ui/src/render/render_pass.rs @@ -1,5 +1,5 @@ use super::{UiBatch, UiImageBindGroups, UiMeta}; -use crate::{prelude::CameraUi, DefaultCameraView}; +use crate::{prelude::UiCameraConfig, DefaultCameraView}; use bevy_ecs::{ prelude::*, system::{lifetimeless::*, SystemParamItem}, @@ -20,7 +20,7 @@ pub struct UiPassNode { ( &'static RenderPhase, &'static ViewTarget, - Option<&'static CameraUi>, + Option<&'static UiCameraConfig>, ), With, >, @@ -66,7 +66,7 @@ impl Node for UiPassNode { return Ok(()); } // Don't render UI for cameras where it is explicitly disabled - if let Some(&CameraUi { is_enabled: false }) = camera_ui { + if matches!(camera_ui, Some(&UiCameraConfig { show_ui: false })) { return Ok(()); }