Skip to content

Commit 5ac16eb

Browse files
authored
Fix: Ignores nodes that are hidden via their parents in directional nav (#22123)
# Objective - Fixes #21950 ## Solution - Updated the query as suggested in the issue to also check for `InheritedVisibility`. Entities that have `Visibility::INHERITED` and `InheritedVisibility::HIDDEN` should also be ignored for directional navigation ## Testing - Did you test these changes? If so, how? I did not test this change at all! And I wasn’t sure how best to set up an automated test for this since there is not an existing one for that function, else I would have. However, the logic change is simple at least… So if a test is desired, just let me know and please provide me with a little direction :)
1 parent 0303bd6 commit 5ac16eb

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

crates/bevy_input_focus/src/directional_navigation.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
6161
use alloc::vec::Vec;
6262
use bevy_app::prelude::*;
63-
use bevy_camera::visibility::Visibility;
63+
use bevy_camera::visibility::{InheritedVisibility, Visibility};
6464
use bevy_ecs::{
6565
entity::{EntityHashMap, EntityHashSet},
6666
prelude::*,
@@ -749,6 +749,7 @@ fn auto_rebuild_ui_navigation_graph(
749749
&ComputedNode,
750750
&UiGlobalTransform,
751751
Option<&Visibility>,
752+
Option<&InheritedVisibility>,
752753
),
753754
With<AutoDirectionalNavigation>,
754755
>,
@@ -759,18 +760,24 @@ fn auto_rebuild_ui_navigation_graph(
759760

760761
let nodes: Vec<FocusableArea> = all_nodes
761762
.iter()
762-
.filter_map(|(entity, computed, transform, visibility)| {
763-
// Skip hidden or zero-size nodes
764-
if computed.is_empty() || matches!(visibility, Some(Visibility::Hidden)) {
765-
return None;
766-
}
767-
let (_scale, _rotation, translation) = transform.to_scale_angle_translation();
768-
Some(FocusableArea {
769-
entity,
770-
position: translation,
771-
size: computed.size(),
772-
})
773-
})
763+
.filter_map(
764+
|(entity, computed, transform, visibility, inherited_visibility)| {
765+
// Skip hidden or zero-size nodes
766+
if computed.is_empty()
767+
|| matches!(visibility, Some(Visibility::Hidden))
768+
|| (matches!(visibility, Some(Visibility::Inherited))
769+
&& matches!(inherited_visibility, Some(&InheritedVisibility::HIDDEN)))
770+
{
771+
return None;
772+
}
773+
let (_scale, _rotation, translation) = transform.to_scale_angle_translation();
774+
Some(FocusableArea {
775+
entity,
776+
position: translation,
777+
size: computed.size(),
778+
})
779+
},
780+
)
774781
.collect();
775782

776783
// clear the old nav map between rebuilds to ensure any removed entities' edges are pruned

0 commit comments

Comments
 (0)