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
`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).
  • Loading branch information
nicopap committed Jul 7, 2022
1 parent bf1ca81 commit aa9593d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
22 changes: 12 additions & 10 deletions crates/bevy_ui/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,20 @@ impl Default for ButtonBundle {
}
}
}
#[derive(Component, Clone)]
pub struct CameraUi {
pub is_enabled: bool,
/// Configuration for cameras related to UI.
///
/// When a [`Camera`] doesn't have the [`CameraUiConfig`] component,
/// it will display the UI by default.
#[derive(Component, Clone, Default)]
pub struct CameraUiConfig {
/// Whether to output UI to this camera view.
///
/// When a [`Camera`] doesn't have the [`CameraUiConfig`] component,
/// it will display the UI by default.
pub show_ui: bool,
}

impl Default for CameraUi {
fn default() -> Self {
Self { is_enabled: true }
}
}

impl ExtractComponent for CameraUi {
impl ExtractComponent for CameraUiConfig {
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::CameraUiConfig;

/// 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::<CameraUiConfig>::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::CameraUiConfig, 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<&CameraUiConfig>), 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(&CameraUiConfig { 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::CameraUiConfig, 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 CameraUiConfig>,
),
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(&CameraUiConfig { show_ui: false })) {
return Ok(());
}

Expand Down

0 comments on commit aa9593d

Please sign in to comment.