Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Add Visibility component to UI #3426

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
};

/// User indication of whether an entity is visible
#[derive(Component, Clone, Reflect)]
#[derive(Component, Clone, Reflect, Debug)]
#[reflect(Component)]
pub struct Visibility {
pub is_visible: bool,
Expand Down
8 changes: 7 additions & 1 deletion crates/bevy_ui/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use bevy_ecs::bundle::Bundle;
use bevy_render::{
camera::{Camera, DepthCalculation, OrthographicProjection, WindowOrigin},
view::VisibleEntities,
view::{Visibility, VisibleEntities},
};
use bevy_text::Text;
use bevy_transform::prelude::{GlobalTransform, Transform};
Expand All @@ -18,6 +18,7 @@ pub struct NodeBundle {
pub image: UiImage,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub visibility: Visibility,
}

#[derive(Bundle, Clone, Debug, Default)]
Expand All @@ -30,6 +31,7 @@ pub struct ImageBundle {
pub image: UiImage,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub visibility: Visibility,
}

#[derive(Bundle, Clone, Debug)]
Expand All @@ -41,6 +43,7 @@ pub struct TextBundle {
pub focus_policy: FocusPolicy,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub visibility: Visibility,
}

impl Default for TextBundle {
Expand All @@ -53,6 +56,7 @@ impl Default for TextBundle {
style: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
visibility: Default::default(),
}
}
}
Expand All @@ -68,6 +72,7 @@ pub struct ButtonBundle {
pub image: UiImage,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub visibility: Visibility,
}

impl Default for ButtonBundle {
Expand All @@ -82,6 +87,7 @@ impl Default for ButtonBundle {
image: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
visibility: Default::default(),
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bevy_render::{
render_resource::*,
renderer::{RenderDevice, RenderQueue},
texture::Image,
view::ViewUniforms,
view::{ViewUniforms, Visibility},
RenderApp, RenderStage, RenderWorld,
};
use bevy_sprite::{Rect, SpriteAssetEvents, TextureAtlas};
Expand Down Expand Up @@ -139,12 +139,16 @@ pub fn extract_uinodes(
&GlobalTransform,
&UiColor,
&UiImage,
&Visibility,
Option<&CalculatedClip>,
)>,
) {
let mut extracted_uinodes = render_world.get_resource_mut::<ExtractedUiNodes>().unwrap();
extracted_uinodes.uinodes.clear();
for (uinode, transform, color, image, clip) in uinode_query.iter() {
for (uinode, transform, color, image, visibility, clip) in uinode_query.iter() {
if !visibility.is_visible {
continue;
}
let image = image.0.clone_weak();
// Skip loading images
if !images.contains(image.clone_weak()) {
Expand Down Expand Up @@ -174,6 +178,7 @@ pub fn extract_text_uinodes(
&Node,
&GlobalTransform,
&Text,
&Visibility,
Option<&CalculatedClip>,
)>,
) {
Expand All @@ -185,7 +190,10 @@ pub fn extract_text_uinodes(
1.
};

for (entity, uinode, transform, text, clip) in uinode_query.iter() {
for (entity, uinode, transform, text, visibility, clip) in uinode_query.iter() {
if !visibility.is_visible {
continue;
}
// Skip if size is set to zero (e.g. when a parent is set to `Display::None`)
if uinode.size == Vec2::ZERO {
continue;
Expand Down