Skip to content

Commit

Permalink
Rename CameraUi
Browse files Browse the repository at this point in the history
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
`UiCameraConfig`.
  • Loading branch information
nicopap committed Jul 7, 2022
1 parent bf1ca81 commit 11d59a1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
20 changes: 15 additions & 5 deletions crates/bevy_ui/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Camera>;

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -50,7 +50,7 @@ pub enum UiSystem {

impl Plugin for UiPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(ExtractComponentPlugin::<CameraUi>::default())
app.add_plugin(ExtractComponentPlugin::<UiCameraConfig>::default())
.init_resource::<FlexSurface>()
.register_type::<AlignContent>()
.register_type::<AlignItems>()
Expand Down
9 changes: 3 additions & 6 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -227,14 +227,11 @@ pub struct DefaultCameraView(pub Entity);
pub fn extract_default_ui_camera_view<T: Component>(
mut commands: Commands,
render_world: Res<RenderWorld>,
query: Query<(Entity, &Camera, Option<&CameraUi>), With<T>>,
query: Query<(Entity, &Camera, Option<&UiCameraConfig>), With<T>>,
) {
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)) = (
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ui/src/render/render_pass.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -20,7 +20,7 @@ pub struct UiPassNode {
(
&'static RenderPhase<TransparentUi>,
&'static ViewTarget,
Option<&'static CameraUi>,
Option<&'static UiCameraConfig>,
),
With<ExtractedView>,
>,
Expand Down Expand Up @@ -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(());
}

Expand Down

0 comments on commit 11d59a1

Please sign in to comment.