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

Add builder methods to bevy_ui's Style struct #7881

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nicoburns
Copy link
Contributor

Objective

Make it more ergonomic to create UI nodes

Solution

  • Builder methods have been added to the Style object
  • From impls have been added to Val (f32 and i32 both map to Val::Px)

Notes

I've added the methods to Style, but I'm they might be better on NodeBundle? Advantage of that is that it cuts out an extra level of nesting. Disadvantage is that we'd presumably have to add them for every bundle.


Changelog

  • Added builder methods to bevy_ui::Style

@ickshonpe
Copy link
Contributor

ickshonpe commented Mar 3, 2023

I think the builder methods would be more useful on the node bundles probably, or they could be implemented for both the bundles and Style.

@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 X-Controversial There is active debate or serious implications around merging this PR labels Mar 4, 2023
@alice-i-cecile
Copy link
Member

Perhaps we can use a trait here with default impls to reduce boilerplate in the engine?

@nicoburns
Copy link
Contributor Author

Perhaps we can use a trait here with default impls to reduce boilerplate in the engine?

Hmm... I suppose you could probably set it up so that the only method each implementor of the trait needed to implement was something like:

fn apply_style(mut self, applicator: FnMut(&mut Style)) -> Self {
    applicator(&mut self.style);
    self
}

It would leak the implementation detail through to the docs though (the methods for layout would all be grouped together on the trait separately from other methods)

@alice-i-cecile
Copy link
Member

Leaking that through to the docs seems net good to me? Being able to see that structure is good, and as a user I'd really like to be able to easily use whatever ergonomics solution we end up on with my own bundle types.

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 X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants