Skip to content

Conversation

bushrat011899
Copy link
Contributor

Objective

Solution

  • Export the variants of Val in the bevy_ui prelude.
  • Updated examples to use the shortened names.

Testing

  • Ran CI.

Notes

I'm not totally convinced this is that big of a deal ergonomically. It's pretty easy for the end-user to write use Val::{...}; at the top of their own files if it really helps them. This was a simple enough PR that I just wanted to create this as a way to decide whether #15937 should just be closed.

@bushrat011899 bushrat011899 added D-Trivial Nice and easy! A great choice to get started with Bevy 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 S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 16, 2024
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.

I don't hate this but I have a strong preference for the free functions alternative. Except for ubiquitous stuff like Option I don't like enum exports, (like you say) users can easily add bevy::Val::* to their own project's prelude if they want to, px is easier to type than Px and a free function API would be more flexible. A px function could support:

pub trait AsValNum {
    fn as_val_num(self) -> f32;
}

impl AsValNum for i32 {
    fn as_val_num(self) -> f32 {
        self as f32
    }
}

impl AsValNum for f32 {
    fn as_val_num(self) -> f32 {
        self
    }
}

pub fn px(n: AsValNum) -> Val {
    Val::Px(n.as_val_num())
}

for instance. Maybe AsValNum (or whatever) would be controversial and I'm not suggesting it has to be included but it's available to us as an option with free functions. I just find it unpleasant that probably 99% of Bevy UI code uses integers but the API has to require floats everywhere.

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 D-Trivial Nice and easy! A great choice to get started with Bevy S-Needs-Review Needs reviewer attention (from anyone!) to move forward 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.

Add Val helper functions

3 participants