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

Expose sorting methods in Children #8522

Merged
merged 2 commits into from
May 1, 2023

Conversation

coreh
Copy link
Contributor

@coreh coreh commented May 1, 2023

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 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). 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)

@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use labels May 1, 2023
@alice-i-cecile alice-i-cecile added this to the 0.11 milestone May 1, 2023
Copy link
Contributor

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect these methods may be largely obseleted once we have a higher level API for tree creation/modification. But I can see that they will be quite useful in the meantime, and the implementation looks good to me :)

@alice-i-cecile
Copy link
Member

Yep, I'm very happy to include them for now, and these are likely to be useful for said higher-level abstractions.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label May 1, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 1, 2023
Merged via the queue into bevyengine:main with commit 5288be7 May 1, 2023
@coreh coreh deleted the children-sort branch May 2, 2023 03:08
@coreh coreh restored the children-sort branch January 14, 2024 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants