Skip to content

Add more tools to conveniently work with hierarchies, especially in the presence of ghost nodes #15609

Open
@alice-i-cecile

Description

@alice-i-cecile

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:

  1. Add more methods to HierarchyQueryExt to capture other common tasks.
  2. Add a ghost-node aware version of this trait, which lives in bevy_ui and takes a Has<GhostNode> argument as well. These methods should be named iter_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:

  1. root_parent: the entity that is highest up the hierarchy tree, if any.
  2. leaf_children: an iterator over the children that have no children of their own.
  3. siblings: other entities that are in direct children of the same parent.
  4. parent: a convenience method that looks for the parent (much more useful when working with ghost nodes).
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-FeatureA new feature, making something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions