-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Register UiImageSize
#8441
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
Register UiImageSize
#8441
Conversation
crates/bevy_ui/src/widget/image.rs
Outdated
| #[derive(Component, Copy, Clone, Debug, Default)] | ||
| /// This field is set automatically by `update_image_calculated_size_system` | ||
| #[derive(Component, Debug, Copy, Clone, Default, Reflect, FromReflect)] | ||
| #[reflect(Component, Default)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add FromReflect (ReflectFromReflect) to this list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right I'm silly I need to learn how the reflection API works properly. I've mostly just been doing what I thought was needed to support reflection, without really understanding how it worked.
So what you mean is that this should derive Reflect and FromReflect, and then reflect FromReflect?
Most of the components in bevy_ui only derive Reflect and then reflect Component and Default, is this wrong?
I thought FromReflect was something that you needed to derive for types with a container field like an option or a vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great question! I highly recommend the bevy_reflect docs.
Basically, FromReflect just allows you to turn a dyn Reflect into a concrete type, like UiImage.
By doing #[reflect(FromReflect)], you're registering ReflectFromReflect for UiImage, which can be used to dynamically do the conversion (i.e. where we don't necessarily have access to or even know about UiImage).
And there's not really a reason the other types don't have this derive or registration. They really should, but it just hasn't happened yet. So might as well start now imo 😄
MrGVSV
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks!
|
could you rebase this PR? CI is failing for a rust update that has already been done on main |
|
Okay |
Objective
Add
register_typeand deriveReflectforUiImageSize.Changelog
register_typeand deriveReflectforUiImageSize.