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 z-index support with a predictable UI stack #5877

Closed
wants to merge 30 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bf32dbe
Add ZIndex component and consistent UI stack
oceantume Sep 4, 2022
f5ac1e4
Merge branch 'main' into feature/zindex-and-uistack
oceantume Sep 4, 2022
1bd3fe1
Fix small issues after merging
oceantume Sep 4, 2022
04e5d7a
Run fmt and clippy
oceantume Sep 4, 2022
321de09
Fix clippy errors
oceantume Sep 4, 2022
12cc199
Fix example error
oceantume Sep 4, 2022
0c1bbab
Simplify the z_index example
oceantume Sep 7, 2022
2d2d335
Replace one color in z-index example
oceantume Sep 7, 2022
97205c7
Add ZIndex to UI bundles and change example to reflect that
oceantume Sep 8, 2022
c4a3f48
Add unit test for the UI Stack system
oceantume Sep 8, 2022
37a8c40
Merge branch 'main' into feature/zindex-and-uistack
oceantume Sep 8, 2022
34fd3a2
Fix clippy errors
oceantume Sep 8, 2022
e0690a6
Improvements based on review comments
oceantume Sep 9, 2022
fff9b33
Use iter_many in focus system to improve perfs and readability
oceantume Sep 9, 2022
4e6a193
Use iter_many in UI render extraction
oceantume Sep 9, 2022
bc7c725
Revert "Use iter_many in UI render extraction"
oceantume Sep 9, 2022
d11dbb5
Fix hover state by restoring the mutable iterator logic
oceantume Sep 9, 2022
29bf401
Fix small issues from comments
oceantume Sep 9, 2022
e1d58fe
Fix clippy error 💦💦💦
oceantume Sep 9, 2022
775ebc6
Add comments to clarify the interaction & focus system
oceantume Sep 20, 2022
2b58677
Update examples/ui/z_index.rs
oceantume Sep 20, 2022
791b677
Update examples/README.md
oceantume Sep 20, 2022
6a70d96
Update crates/bevy_ui/src/ui_node.rs
oceantume Sep 20, 2022
a4d8e7b
Update examples readme
oceantume Sep 20, 2022
34f9790
Properly update example description
oceantume Sep 20, 2022
c0ff6f5
Remove unused component from z_index example
oceantume Sep 21, 2022
bd18d78
Merge branch 'main' into feature/zindex-and-uistack
oceantume Oct 31, 2022
36dfd25
Fix format
oceantume Oct 31, 2022
32766b3
Fix example and reuse uinodes vector
oceantume Oct 31, 2022
2f793cc
Fix merge errors
cart Nov 2, 2022
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
Prev Previous commit
Next Next commit
Use iter_many in focus system to improve perfs and readability
oceantume committed Sep 9, 2022
commit fff9b33f0238f3cfba17f08d53c961e6b7fb92a6
55 changes: 26 additions & 29 deletions crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
@@ -168,55 +168,52 @@ pub fn ui_focus_system(
};

if contains_cursor {
return Some(entity);
return Some(*entity);
} else if let Some(mut interaction) = node.interaction {
if *interaction == Interaction::Hovered
|| (cursor_position.is_none() && *interaction != Interaction::None)
{
*interaction = Interaction::None;
}
}
return None;
}
None
})
.collect::<Vec<_>>();
.collect::<Vec<Entity>>();

// set Clicked or Hovered on top nodes
for entity in &moused_over_nodes {
if let Ok(node) = node_query.get_mut(**entity) {
if let Some(mut interaction) = node.interaction {
if mouse_clicked {
// only consider nodes with Interaction "clickable"
if *interaction != Interaction::Clicked {
*interaction = Interaction::Clicked;
// if the mouse was simultaneously released, reset this Interaction in the next
// frame
if mouse_released {
state.entities_to_reset.push(**entity);
}
let mut iter = node_query.iter_many_mut(&moused_over_nodes);
while let Some(node) = iter.fetch_next() {
if let Some(mut interaction) = node.interaction {
if mouse_clicked {
// only consider nodes with Interaction "clickable"
if *interaction != Interaction::Clicked {
*interaction = Interaction::Clicked;
// if the mouse was simultaneously released, reset this Interaction in the next
// frame
if mouse_released {
state.entities_to_reset.push(node.entity);
}
} else if *interaction == Interaction::None {
*interaction = Interaction::Hovered;
}
} else if *interaction == Interaction::None {
*interaction = Interaction::Hovered;
}
}

match node.focus_policy.cloned().unwrap_or(FocusPolicy::Block) {
FocusPolicy::Block => {
break;
}
FocusPolicy::Pass => { /* allow the next node to be hovered/clicked */ }
match node.focus_policy.cloned().unwrap_or(FocusPolicy::Block) {
FocusPolicy::Block => {
break;
}
FocusPolicy::Pass => { /* allow the next node to be hovered/clicked */ }
}
}
// reset lower nodes to None
for entity in &moused_over_nodes {
if let Ok(node) = node_query.get_mut(**entity) {
if let Some(mut interaction) = node.interaction {
// don't reset clicked nodes because they're handled separately
if *interaction != Interaction::Clicked && *interaction != Interaction::None {
*interaction = Interaction::None;
}
let mut iter = node_query.iter_many_mut(&moused_over_nodes);
while let Some(node) = iter.fetch_next() {
if let Some(mut interaction) = node.interaction {
// don't reset clicked nodes because they're handled separately
if *interaction != Interaction::Clicked && *interaction != Interaction::None {
*interaction = Interaction::None;
}
}
}