Skip to content

Refactor examples/helpers/checkbox.rs - #25527

Open
tevans-3 wants to merge 9 commits into
bevyengine:mainfrom
tevans-3:refactor_examples_checkbox_helper
Open

tevans-3 wants to merge 9 commits into
bevyengine:mainfrom
tevans-3:refactor_examples_checkbox_helper

Conversation

@tevans-3

Copy link
Copy Markdown
Member

Objective

  • The checkbox helper in examples/helpers only lets callers create unchecked boxes. Callers should be able to create both checked and unchecked variants.

Solution

  • Refactor the checkbox helper to accept an "IsChecked" flag and spawn both checked and unchecked checkboxes.
  • Update the other users of checkbox.rs (examples/2d/2d_shapes.rs) to pass IsChecked to the helper. (I also updated the pending Migrate 3d_shapes to feathers #25436)

Testing

I tested examples that use the helper and verified that they still work as expected.

tevans-3 added a commit to tevans-3/bevy that referenced this pull request Aug 23, 2026
@Zeophlite Zeophlite added A-UI Graphical user interfaces, styles, layouts, and widgets D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 24, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI Aug 24, 2026
Comment thread examples/helpers/checkbox.rs Outdated
@Zeophlite

Copy link
Copy Markdown
Contributor

Just needs a cargo fmt --all

Comment thread examples/helpers/checkbox.rs Outdated
Comment thread examples/helpers/checkbox.rs Outdated
Comment thread examples/2d/2d_shapes.rs Outdated
@tevans-3
tevans-3 force-pushed the refactor_examples_checkbox_helper branch from e567281 to ee41b5c Compare August 25, 2026 14:50

@mnmaita mnmaita left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Took a second look at this and found a few more nits 🙏🏻 thanks!

Comment thread examples/helpers/checkbox.rs Outdated
Hovered::default()
{checkbox_identifier.is_some().then(||
{ bsn! { template_value(checkbox_identifier.unwrap()) }
})}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

        {checkbox_identifier.and_then(|checkbox_identifier| {
            bsn! { template_value(checkbox_identifier) }
        })}

Would something like this work here to simplify things a bit?

@tevans-3 tevans-3 Aug 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Apparently, with and_then, the compiler expects the closure to return an option, so to get it to work, you have to wrap the bsn!: Some(bsn! { .. } )

But the linter objected to that, on the grounds that that's identical to this:

        {checkbox_identifier.map(|checkbox_identifier| {
            bsn! { template_value(checkbox_identifier) }
        })}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh yeah map makes more sense here, good catch.

Sorry that I was insisting on these refactors but I feel like they are great examples that we should show so people know they can optionally add components in BSN easily.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No need to apologize; the code is better because of your suggestions! And I'm learning stuff too, I didn't know bsn could "do" conditional components, or that .and_then / then could be used like that

Comment thread examples/helpers/checkbox.rs
Comment thread examples/2d/2d_shapes.rs Outdated
top_left_scene()
Children [
feathers_option_checkbox("ROTATE", Some(CheckboxInput::Rotation), IsChecked(false)),
feathers_option_checkbox("WIREFRAME", Some(CheckboxInput::Wireframe), IsChecked(false)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might be worthwile to also get rid of the almost identical branches here by doing something like:

{(!cfg!(target_arch = "wasm32")).then(|| {
    bsn! { feathers_option_checkbox("WIREFRAME", Some(CheckboxInput::Wireframe), IsChecked(false)) }
})}

@mnmaita mnmaita left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for addressing the requested changes! I just tested the example locally and it looks good. I left a small clarification on the BSN formatting comment that you could address too but I don't want to block on that.

@tevans-3 tevans-3 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 Aug 31, 2026
@Zeophlite Zeophlite added the S-Merge-Conflicts Merge conflicts :( Add this label on top of other S- labels. label Sep 1, 2026
@alice-i-cecile

Copy link
Copy Markdown
Member

Please resolve merge conflicts <3

@Zeophlite Zeophlite removed the S-Merge-Conflicts Merge conflicts :( Add this label on top of other S- labels. label Sep 5, 2026
@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Sep 7, 2026
@Zeophlite Zeophlite added the S-Merge-Conflicts Merge conflicts :( Add this label on top of other S- labels. label Sep 8, 2026
@Zeophlite

Copy link
Copy Markdown
Contributor

This needs an update with the recent bsn changes

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Sep 9, 2026

This branch has not been deployed

No deployments
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-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Merge-Conflicts Merge conflicts :( Add this label on top of other S- labels. S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

4 participants