-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
refactor ui/borders example to use new children! macro #18962
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
refactor ui/borders example to use new children! macro #18962
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clicked approve but left some optional tidying suggestions.
CI failures seem unrelated to this PR and it previously passed CI before using TextFont::from_font_size, so moving to ready for final review since it has 2 approvals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better. I always wanted to change this to use a grid layout but it was too much hassle before without the children macro, should be simple now.
) # Objective Refactor [`examples/ui/borders.rs`](https://github.com/bevyengine/bevy/blob/7f0490655c3ede945e6babc1f1a1f06b13404aa8/examples/ui/borders.rs) to use the new spawning/hierarchy APIs in 0.16. ## Solution This refactor reduces the number of `.spawn` calls from about 16 to 2, using one spawn for each major feature: * camera2d * ui layout The `Children::spawn` relationship API is used to take advantage of `SpawnIter` for the borders examples in each block. Each block of examples now returns a Bundle into its respective variable, which is then used in combination with the new `label` widget which makes use of the new `impl Bundle` return capability. This allows the ui layout to use a single `.spawn` with the `children!` macro. The blocks of examples are still in separate variables because it felt like a useful way to organize it still, even without needing to spawn at those locations. Functionality of the demo hasn't changed, this is just an API/code update. ## Showcase  <details> <summary>Before screenshot</summary>  </details> --------- Co-authored-by: François Mockers <[email protected]>
Objective
Refactor
examples/ui/borders.rs
to use the new spawning/hierarchy APIs in 0.16.Solution
This refactor reduces the number of
.spawn
calls from about 16 to 2, using one spawn for each major feature:The
Children::spawn
relationship API is used to take advantage ofSpawnIter
for the borders examples in each block.Each block of examples now returns a Bundle into its respective variable, which is then used in combination with the new
label
widget which makes use of the newimpl Bundle
return capability. This allows the ui layout to use a single.spawn
with thechildren!
macro.The blocks of examples are still in separate variables because it felt like a useful way to organize it still, even without needing to spawn at those locations.
Functionality of the demo hasn't changed, this is just an API/code update.
Showcase
Before screenshot