Skip to content

Assorted small small style refactors #16205

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

Closed
wants to merge 4 commits into from

Conversation

sharma-shray
Copy link

Objective

  • Describe the objective or issue this PR addresses.
  • If you're fixing a specific issue, say "Fixes #X".

Solution

  • Describe the solution used to achieve the objective above.
    we can directly assign the result of the loop to name
    text.into() can be changing the type conversion method to be more explicit.

Testing

  • Did you test these changes? If so, how?
  • Are there any parts that need more testing?
  • How can other people (reviewers) test your changes? Is there anything specific they need to know?
  • If relevant, what platforms did you test these changes on, and are there any important ones you can't test?

Showcase

This section is optional. If this PR does not include a visual change or does not add a new feature, you can delete this section.

  • Help others understand the result of this PR by showcasing your awesome work!
  • If this PR adds a new feature or public API, consider adding a brief pseudo-code snippet of it in action
  • If this PR includes a visual change, consider adding a screenshot, GIF, or video
    • If you want, you could even include a before/after comparison!
  • If the Migration Guide adequately covers the changes, you can delete this section

While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases:

Click to view showcase
println!("My super cool code.");

Migration Guide

This section is optional. If there are no breaking changes, you can delete this section.

  • If this PR is a breaking change (relative to the last release of Bevy), describe how a user might need to migrate their code to support these changes
  • Simply adding new functionality is not a breaking change.
  • Fixing behavior that was definitely a bug, rather than a questionable design choice is not a breaking change.

Copy link
Contributor

github-actions bot commented Nov 1, 2024

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@BenjaminBrienen BenjaminBrienen added C-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged A-UI Graphical user interfaces, styles, layouts, and widgets labels Nov 1, 2024
@alice-i-cecile alice-i-cecile changed the title Suggestions refactoring Assorted small small style refactors Nov 4, 2024
@alice-i-cecile
Copy link
Member

Can you justify why these changes are good? One sentence is fine.

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy and removed D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Nov 4, 2024
@@ -95,8 +95,7 @@ impl RelativeCursorPosition {
/// A helper function to check if the mouse is over the node
pub fn mouse_over(&self) -> bool {
self.normalized
.map(|position| self.normalized_visible_node_rect.contains(position))
.unwrap_or(false)
.map_or(false, |position| self.normalized_visible_node_rect.contains(position))
Copy link
Member

Choose a reason for hiding this comment

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

there's some distaste amongst some contributors (me included) with using map_or as it's harder to read because it put the "or" case first

Comment on lines 27 to +36
for child in children {
let values = text_reader
.iter(child)
.map(|(_, _, text, _, _)| text.into())
.map(|(_, _, text, _, _)| text.to_string())
.collect::<Vec<String>>();
if !values.is_empty() {
name = Some(values.join(" "));
name = Some(values.join(" ").into_boxed_str());
}
}
name.map(String::into_boxed_str)
name
Copy link
Contributor

Choose a reason for hiding this comment

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

Your changes seem sensible, but this function doesn't look right. Even if it's correct, it could iterate children backwards and short circuit return the first success rather than collecting and throwing away all these intermediate vecs?

@doup
Copy link
Contributor

doup commented Nov 6, 2024

Looks like this should be closed in favor of #16250 as it's a subset of the same changes.

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 D-Trivial Nice and easy! A great choice to get started with Bevy S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants