bevy/crates/bevy_hierarchy
Marco Buono 5288be7c6e
Expose sorting methods in Children (#8522)
# Objective

- For many UI use cases (e.g. tree views, lists), it is important to be
able to imperatively sort child nodes.
- This also enables us to eventually support something like the
[`order`](https://developer.mozilla.org/en-US/docs/Web/CSS/order) CSS
property, that declaratively re-orders flex box items by a numeric
value, similar to z-index, but in space.

## Solution

We removed the ability to directly construct `Children` from `&[Entity]`
some time ago (#4197 #5532) to enforce consistent hierarchies ([RFC
53](https://github.com/bevyengine/rfcs/blob/main/rfcs/53-consistent-hierarchy.md)).
If I understand it correctly, it's currently possible to re-order
children by using `Children::swap()` or
`commands.entity(id).replace_children(...)`, however these are either
too cumbersome, needlessly inefficient, and/or don't take effect
immediately.

This PR exposes the in-place sorting methods from the `slice` primitive
in `Children`, enabling imperatively sorting children in place via `&mut
Children`, while still preserving consistent hierarchies.

---

## Changelog
### Added
- The sorting methods from the `slice` primitive are now exposed by the
`Children` component, allowing imperatively sorting children in place
(Useful for UI scenarios such as lists)
2023-05-01 15:57:25 +00:00
..
src Expose sorting methods in Children (#8522) 2023-05-01 15:57:25 +00:00
Cargo.toml chore: Release (#7920) 2023-03-06 05:13:36 +00:00