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

Fixes for a few minor borders and outlines bugs #16071

Merged
merged 4 commits into from
Oct 23, 2024
Merged
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
45 changes: 25 additions & 20 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ mod ui_material_pipeline;
pub mod ui_texture_slice_pipeline;

use crate::{
BackgroundColor, BorderColor, CalculatedClip, ComputedNode, DefaultUiCamera, Outline,
ResolvedBorderRadius, TargetCamera, UiAntiAlias, UiBoxShadowSamples, UiImage, UiScale,
BackgroundColor, BorderColor, CalculatedClip, ComputedNode, DefaultUiCamera, Display, Node,
Outline, ResolvedBorderRadius, TargetCamera, UiAntiAlias, UiBoxShadowSamples, UiImage, UiScale,
};
use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, AssetEvent, AssetId, Assets, Handle};
Expand Down Expand Up @@ -399,6 +399,7 @@ pub fn extract_uinode_borders(
uinode_query: Extract<
Query<(
Entity,
&Node,
&ComputedNode,
&GlobalTransform,
&ViewVisibility,
Expand All @@ -415,7 +416,8 @@ pub fn extract_uinode_borders(

for (
entity,
uinode,
node,
computed_node,
global_transform,
view_visibility,
maybe_clip,
Expand All @@ -435,24 +437,22 @@ pub fn extract_uinode_borders(
continue;
};

// Skip invisible borders
if !view_visibility.get()
|| maybe_border_color.is_some_and(|border_color| border_color.0.is_fully_transparent())
&& maybe_outline.is_some_and(|outline| outline.color.is_fully_transparent())
{
// Skip invisible borders and removed nodes
if !view_visibility.get() || node.display == Display::None {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean 🤌

continue;
}

// don't extract border if no border or the node is zero-sized (a zero sized node can still have an outline).
if !uinode.is_empty() && uinode.border() != BorderRect::ZERO {
if let Some(border_color) = maybe_border_color {
// Don't extract borders with zero width along all edges
if computed_node.border() != BorderRect::ZERO {
if let Some(border_color) = maybe_border_color.filter(|bc| !bc.0.is_fully_transparent())
{
extracted_uinodes.uinodes.insert(
commands.spawn(TemporaryRenderEntity).id(),
ExtractedUiNode {
stack_index: uinode.stack_index,
stack_index: computed_node.stack_index,
color: border_color.0.into(),
rect: Rect {
max: uinode.size(),
max: computed_node.size(),
..Default::default()
},
image,
Expand All @@ -463,8 +463,8 @@ pub fn extract_uinode_borders(
transform: global_transform.compute_matrix(),
flip_x: false,
flip_y: false,
border: uinode.border(),
border_radius: uinode.border_radius(),
border: computed_node.border(),
border_radius: computed_node.border_radius(),
node_type: NodeType::Border,
},
main_entity: entity.into(),
Expand All @@ -473,15 +473,20 @@ pub fn extract_uinode_borders(
}
}

if let Some(outline) = maybe_outline {
let outline_size = uinode.outlined_node_size();
if computed_node.outline_width() <= 0. {
continue;
}

if let Some(outline) = maybe_outline.filter(|outline| !outline.color.is_fully_transparent())
{
let outline_size = computed_node.outlined_node_size();
let parent_clip =
maybe_parent.and_then(|parent| parent_clip_query.get(parent.get()).ok());

extracted_uinodes.uinodes.insert(
commands.spawn(TemporaryRenderEntity).id(),
ExtractedUiNode {
stack_index: uinode.stack_index,
stack_index: computed_node.stack_index,
color: outline.color.into(),
rect: Rect {
max: outline_size,
Expand All @@ -495,8 +500,8 @@ pub fn extract_uinode_borders(
atlas_scaling: None,
flip_x: false,
flip_y: false,
border: BorderRect::square(uinode.outline_width()),
border_radius: uinode.outline_radius(),
border: BorderRect::square(computed_node.outline_width()),
border_radius: computed_node.outline_radius(),
node_type: NodeType::Border,
},
main_entity: entity.into(),
Expand Down
12 changes: 11 additions & 1 deletion examples/ui/display_and_visibility.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Demonstrates how Display and Visibility work in the UI.

use bevy::{
color::palettes::css::{DARK_GRAY, YELLOW},
color::palettes::css::{DARK_CYAN, DARK_GRAY, YELLOW},
prelude::*,
winit::WinitSettings,
};
Expand Down Expand Up @@ -187,6 +187,11 @@ fn spawn_left_panel(builder: &mut ChildBuilder, palette: &[Color; 4]) -> Vec<Ent
..default()
},
BackgroundColor(palette[0]),
Outline {
width: Val::Px(4.),
color: DARK_CYAN.into(),
offset: Val::Px(10.),
},
))
.with_children(|parent| {
parent.spawn(Node {
Expand Down Expand Up @@ -289,6 +294,11 @@ fn spawn_right_panel(
..default()
},
BackgroundColor(palette[0]),
Outline {
width: Val::Px(4.),
color: DARK_CYAN.into(),
offset: Val::Px(10.),
},
))
.with_children(|parent| {
spawn_buttons(parent, target_ids.pop().unwrap());
Expand Down