Skip to content

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

Merged
merged 5 commits into from
May 4, 2025

Conversation

ChristopherBiscardi
Copy link
Contributor

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:

  • 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

screenshot-2025-04-27-at-18 05 19@2x

Before screenshot

screenshot-2025-04-27-at-18 17 12@2x

@ChristopherBiscardi ChristopherBiscardi added C-Examples An addition or correction to our examples A-UI Graphical user interfaces, styles, layouts, and widgets S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 28, 2025
Copy link

@dj-blume9 dj-blume9 left a comment

Choose a reason for hiding this comment

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

I ran this on my windows 11 and my Fedora 42 linux machines. Both instances ran as expected with no deviation from the original example.
image

Copy link
Contributor

@greeble-dev greeble-dev left a 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.

@ChristopherBiscardi ChristopherBiscardi added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 29, 2025
@ChristopherBiscardi
Copy link
Contributor Author

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

Copy link
Contributor

@ickshonpe ickshonpe left a 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.

@mockersf mockersf enabled auto-merge May 4, 2025 08:16
@mockersf mockersf added this pull request to the merge queue May 4, 2025
Merged via the queue into bevyengine:main with commit 5640589 May 4, 2025
32 checks passed
andrewzhurov pushed a commit to andrewzhurov/bevy that referenced this pull request May 17, 2025
)

# 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

![screenshot-2025-04-27-at-18 05
19@2x](https://github.com/user-attachments/assets/5f10b28b-b0f1-4a55-af9f-2e7b05b7b4bf)

<details>
<summary>Before screenshot</summary>

![screenshot-2025-04-27-at-18 17
12@2x](https://github.com/user-attachments/assets/ae159d96-ba4d-4429-b934-7779470c480a)

</details>

---------

Co-authored-by: François Mockers <[email protected]>
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-Examples An addition or correction to our examples 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.

5 participants