Skip to content

Commit

Permalink
Added marker components:
Browse files Browse the repository at this point in the history
* ExtractUiNode
* ExtractUiNodeBorder
* ExtractUiNodeText
* ExtractUiNodeAtlasImage
These are added to the relevant UI node bundles.

The UI's extraction functions now have query filters that allow selective extraction of UI node entities:
* `extract_uinode` has filter `With<ExtractUiNode>`
* `extract_uinode_borders` has filter `With<ExtractUiNodeBorder>`
* `extract_text_uinodes` has filter `With<ExtractUiNodeText>`
* `extract_atlas_uinodes` has filter `With<ExtractUiNodeAtlasImage>`
  • Loading branch information
ickshonpe committed Aug 24, 2023
1 parent b88ff15 commit 0a88bb5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 13 deletions.
25 changes: 24 additions & 1 deletion crates/bevy_ui/src/node_bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
use crate::widget::TextFlags;
use crate::{
widget::{Button, UiImageSize},
BackgroundColor, BorderColor, ContentSize, FocusPolicy, Interaction, Node, Style, UiImage,
BackgroundColor, BorderColor, ContentSize, ExtractUiNode, ExtractUiNodeAtlasImage,
ExtractUiNodeBorder, ExtractUiNodeText, FocusPolicy, Interaction, Node, Style, UiImage,
UiTextureAtlasImage, ZIndex,
};
use bevy_asset::Handle;
Expand Down Expand Up @@ -50,6 +51,10 @@ pub struct NodeBundle {
pub computed_visibility: ComputedVisibility,
/// Indicates the depth at which the node should appear in the UI
pub z_index: ZIndex,
/// Extract with [`extract_uinodes`](`crate::render::extract_uinodes`)
pub extract_uinode: ExtractUiNode,
/// Extract with [`extract_uinode_borders`](`crate::render::extract_uinode_borders`)
pub extract_border: ExtractUiNodeBorder,
}

impl Default for NodeBundle {
Expand All @@ -66,6 +71,8 @@ impl Default for NodeBundle {
visibility: Default::default(),
computed_visibility: Default::default(),
z_index: Default::default(),
extract_uinode: ExtractUiNode,
extract_border: ExtractUiNodeBorder,
}
}
}
Expand Down Expand Up @@ -108,6 +115,8 @@ pub struct ImageBundle {
pub computed_visibility: ComputedVisibility,
/// Indicates the depth at which the node should appear in the UI
pub z_index: ZIndex,
/// Extract with [`extract_uinodes`](`crate::render::extract_uinodes`)
pub extract_uinode: ExtractUiNode,
}

/// A UI node that is a texture atlas sprite
Expand Down Expand Up @@ -150,6 +159,8 @@ pub struct AtlasImageBundle {
pub computed_visibility: ComputedVisibility,
/// Indicates the depth at which the node should appear in the UI
pub z_index: ZIndex,
/// Extract with [`extract_uinodes`](`crate::render::extract_uinodes`)
pub extract_uinode: ExtractUiNodeAtlasImage,
}

#[cfg(feature = "bevy_text")]
Expand Down Expand Up @@ -189,6 +200,10 @@ pub struct TextBundle {
pub z_index: ZIndex,
/// The background color that will fill the containing node
pub background_color: BackgroundColor,
/// Extract with [`extract_uinodes`](`crate::render::extract_uinodes`)
pub extract_uinode: ExtractUiNode,
/// Extract with [`extract_text_uinodes`](`crate::render::extract_text_uinodes`)
pub extract_text: ExtractUiNodeText,
}

#[cfg(feature = "bevy_text")]
Expand All @@ -209,6 +224,8 @@ impl Default for TextBundle {
visibility: Default::default(),
computed_visibility: Default::default(),
z_index: Default::default(),
extract_uinode: ExtractUiNode,
extract_text: ExtractUiNodeText,
}
}
}
Expand Down Expand Up @@ -299,6 +316,10 @@ pub struct ButtonBundle {
pub computed_visibility: ComputedVisibility,
/// Indicates the depth at which the node should appear in the UI
pub z_index: ZIndex,
/// Extract with [`extract_uinodes`](`crate::render::extract_uinodes`)
pub extract_node: ExtractUiNode,
/// Extract with [`extract_uinode_borders`](`crate::render::extract_uinode_borders`)
pub extract_border: ExtractUiNodeBorder,
}

impl Default for ButtonBundle {
Expand All @@ -317,6 +338,8 @@ impl Default for ButtonBundle {
visibility: Default::default(),
computed_visibility: Default::default(),
z_index: Default::default(),
extract_node: ExtractUiNode,
extract_border: ExtractUiNodeBorder,
}
}
}
44 changes: 32 additions & 12 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod render_pass;

use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d};
use bevy_hierarchy::Parent;
use bevy_reflect::std_traits::ReflectDefault;
use bevy_render::{ExtractSchedule, Render};
use bevy_window::{PrimaryWindow, Window};
pub use pipeline::*;
Expand All @@ -17,7 +18,7 @@ use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, AssetEvent, Assets, Handle, HandleUntyped};
use bevy_ecs::prelude::*;
use bevy_math::{Mat4, Rect, URect, UVec4, Vec2, Vec3, Vec4Swizzles};
use bevy_reflect::TypeUuid;
use bevy_reflect::{Reflect, TypeUuid};
use bevy_render::texture::DEFAULT_IMAGE_HANDLE;
use bevy_render::{
camera::Camera,
Expand Down Expand Up @@ -164,6 +165,22 @@ pub struct ExtractedUiNode {
pub flip_y: bool,
}

#[derive(Component, Default, Debug, Copy, Clone, Reflect)]
#[reflect(Component, Default)]
pub struct ExtractUiNode;

#[derive(Component, Default, Debug, Copy, Clone, Reflect)]
#[reflect(Component, Default)]
pub struct ExtractUiNodeBorder;

#[derive(Component, Default, Debug, Copy, Clone, Reflect)]
#[reflect(Component, Default)]
pub struct ExtractUiNodeText;

#[derive(Component, Default, Debug, Copy, Clone, Reflect)]
#[reflect(Component, Default)]
pub struct ExtractUiNodeAtlasImage;

#[derive(Resource, Default)]
pub struct ExtractedUiNodes {
pub uinodes: Vec<ExtractedUiNode>,
Expand All @@ -185,7 +202,7 @@ pub fn extract_atlas_uinodes(
&Handle<TextureAtlas>,
&UiTextureAtlasImage,
),
Without<UiImage>,
(With<ExtractUiNodeAtlasImage>, Without<UiImage>),
>,
>,
) {
Expand Down Expand Up @@ -273,7 +290,7 @@ pub fn extract_uinode_borders(
&ComputedVisibility,
Option<&CalculatedClip>,
),
Without<ContentSize>,
(With<ExtractUiNode>, Without<ContentSize>),
>,
>,
node_query: Extract<Query<&Node>>,
Expand Down Expand Up @@ -390,7 +407,7 @@ pub fn extract_uinodes(
&ComputedVisibility,
Option<&CalculatedClip>,
),
Without<UiTextureAtlasImage>,
(With<ExtractUiNode>, Without<UiTextureAtlasImage>),
>,
>,
) {
Expand Down Expand Up @@ -512,14 +529,17 @@ pub fn extract_text_uinodes(
ui_stack: Extract<Res<UiStack>>,
ui_scale: Extract<Res<UiScale>>,
uinode_query: Extract<
Query<(
&Node,
&GlobalTransform,
&Text,
&TextLayoutInfo,
&ComputedVisibility,
Option<&CalculatedClip>,
)>,
Query<
(
&Node,
&GlobalTransform,
&Text,
&TextLayoutInfo,
&ComputedVisibility,
Option<&CalculatedClip>,
),
With<ExtractUiNodeText>,
>,
>,
) {
// TODO: Support window-independent UI scale: https://github.com/bevyengine/bevy/issues/5621
Expand Down

0 comments on commit 0a88bb5

Please sign in to comment.