-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add more tools to conveniently work with hierarchies, especially in the presence of ghost nodes #15609
Comments
The |
# Objective - Working with hierarchies in Bevy is far too tedious due to a lack of helper functions. - This is the first half of #15609. ## Solution Extend [`HierarchyQueryExt`](https://docs.rs/bevy/latest/bevy/hierarchy/trait.HierarchyQueryExt) with the following methods: - `parent` - `children` - `root_parent` - `iter_leaves` - `iter_siblings` - `iter_descendants_depth_first` I've opted to make both `iter_leaves` and `iter_siblings` collect the list of matching Entities for now, rather that operate by reference like the existing `iter_descendants`. This was simpler, and in the case of `iter_siblings` especially, the number of matching entities is likely to be much smaller. I've kept the generics in the type signature however, so we can go back and optimize that freely without a breaking change whenever we want. ## Testing I've added some basic testing, but they're currently failing. If you'd like to help, I'd welcome suggestions or a PR to my PR over the weekend <3 --------- Co-authored-by: Viktor Gustavsson <[email protected]> Co-authored-by: poopy <[email protected]> Co-authored-by: Christian Hughes <[email protected]>
With the first half of this issue is merged (#15627), we can focus on the second half: UI tree. The second halfFor the second half of this issue, we would want to make I propose we also change name of I looked over the APIs and summarized the current state along with proposed
Bonus utilitiesIn addition to the above, we could also add more utilities that are useful in UI, here is a list inspired by CSS psuedo-classes:
Maybe something for a follow-up though, and I'm not sure how much bloat we want in the API. |
Excellent investigation. Of the bonus APIs, I like |
What problem does this solve or what need does it fill?
Following the introduction of #15341, some users have expressed concerns around difficulties migrating to account for ghost nodes in their hierarchies.
This is a great opportunity to add more tools for traversing hierarchies in the spirit of
iter_descendants
.What solution would you like?
There are two stages to this:
HierarchyQueryExt
to capture other common tasks.bevy_ui
and takes aHas<GhostNode>
argument as well. These methods should be namediter_node_descendants
and so on.In theory these can be done in either order, or in a single PR. Your choice!
In terms of additional tasks to cover:
root_parent
: the entity that is highest up the hierarchy tree, if any.leaf_children
: an iterator over the children that have no children of their own.siblings
: other entities that are in direct children of the same parent.parent
: a convenience method that looks for the parent (much more useful when working with ghost nodes).children
: as above, but for children.What alternative(s) have you considered?
One day (🥺), this will get rolled into #3742. It's nice to ship helpful APIs to users sooner though, and these methods will be easier to migrate since they have semantic meaning.
The text was updated successfully, but these errors were encountered: