Skip to content

Commit bef8285

Browse files
committed
Rename CameraUi
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. To avoid unnecessary confusion, we rename `CameraUi` into `CameraUiConfig`. Since currently it's only used to prevent the UI from rendering on a specific viewport, we also define its `Default` value as false rather than true (with `show_ui` set to true, this actually does nothing).
1 parent bf1ca81 commit bef8285

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

crates/bevy_ui/src/entity.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,22 @@ impl Default for ButtonBundle {
136136
}
137137
}
138138
}
139-
#[derive(Component, Clone)]
140-
pub struct CameraUi {
141-
pub is_enabled: bool,
139+
/// Configuration for cameras related to UI.
140+
///
141+
/// When a [`Camera`] doesn't have the [`CameraUiConfig`] component,
142+
/// it will display the UI by default.
143+
///
144+
/// [`Camera`]: bevy_render::camera::Camera
145+
#[derive(Component, Clone, Default)]
146+
pub struct CameraUiConfig {
147+
/// Whether to output UI to this camera view.
148+
///
149+
/// When a `Camera` doesn't have the [`CameraUiConfig`] component,
150+
/// it will display the UI by default.
151+
pub show_ui: bool,
142152
}
143153

144-
impl Default for CameraUi {
145-
fn default() -> Self {
146-
Self { is_enabled: true }
147-
}
148-
}
149-
150-
impl ExtractComponent for CameraUi {
154+
impl ExtractComponent for CameraUiConfig {
151155
type Query = &'static Self;
152156
type Filter = With<Camera>;
153157

crates/bevy_ui/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use bevy_transform::TransformSystem;
3333
use bevy_window::ModifiesWindows;
3434
use update::{ui_z_system, update_clipping_system};
3535

36-
use crate::prelude::CameraUi;
36+
use crate::prelude::CameraUiConfig;
3737

3838
/// The basic plugin for Bevy UI
3939
#[derive(Default)]
@@ -50,7 +50,7 @@ pub enum UiSystem {
5050

5151
impl Plugin for UiPlugin {
5252
fn build(&self, app: &mut App) {
53-
app.add_plugin(ExtractComponentPlugin::<CameraUi>::default())
53+
app.add_plugin(ExtractComponentPlugin::<CameraUiConfig>::default())
5454
.init_resource::<FlexSurface>()
5555
.register_type::<AlignContent>()
5656
.register_type::<AlignItems>()

crates/bevy_ui/src/render/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d};
55
pub use pipeline::*;
66
pub use render_pass::*;
77

8-
use crate::{prelude::CameraUi, CalculatedClip, Node, UiColor, UiImage};
8+
use crate::{prelude::CameraUiConfig, CalculatedClip, Node, UiColor, UiImage};
99
use bevy_app::prelude::*;
1010
use bevy_asset::{load_internal_asset, AssetEvent, Assets, Handle, HandleUntyped};
1111
use bevy_ecs::prelude::*;
@@ -227,14 +227,11 @@ pub struct DefaultCameraView(pub Entity);
227227
pub fn extract_default_ui_camera_view<T: Component>(
228228
mut commands: Commands,
229229
render_world: Res<RenderWorld>,
230-
query: Query<(Entity, &Camera, Option<&CameraUi>), With<T>>,
230+
query: Query<(Entity, &Camera, Option<&CameraUiConfig>), With<T>>,
231231
) {
232232
for (entity, camera, camera_ui) in query.iter() {
233233
// ignore cameras with disabled ui
234-
if let Some(&CameraUi {
235-
is_enabled: false, ..
236-
}) = camera_ui
237-
{
234+
if matches!(camera_ui, Some(&CameraUiConfig { show_ui: false, .. })) {
238235
continue;
239236
}
240237
if let (Some(logical_size), Some(physical_size)) = (

crates/bevy_ui/src/render/render_pass.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{UiBatch, UiImageBindGroups, UiMeta};
2-
use crate::{prelude::CameraUi, DefaultCameraView};
2+
use crate::{prelude::CameraUiConfig, DefaultCameraView};
33
use bevy_ecs::{
44
prelude::*,
55
system::{lifetimeless::*, SystemParamItem},
@@ -20,7 +20,7 @@ pub struct UiPassNode {
2020
(
2121
&'static RenderPhase<TransparentUi>,
2222
&'static ViewTarget,
23-
Option<&'static CameraUi>,
23+
Option<&'static CameraUiConfig>,
2424
),
2525
With<ExtractedView>,
2626
>,
@@ -66,7 +66,7 @@ impl Node for UiPassNode {
6666
return Ok(());
6767
}
6868
// Don't render UI for cameras where it is explicitly disabled
69-
if let Some(&CameraUi { is_enabled: false }) = camera_ui {
69+
if matches!(camera_ui, Some(&CameraUiConfig { show_ui: false })) {
7070
return Ok(());
7171
}
7272

0 commit comments

Comments
 (0)