Skip to content

Conversation

@ickshonpe
Copy link
Contributor

Objective

Add register_type and derive Reflect for UiImageSize.

Changelog

  • Added register_type and derive Reflect for UiImageSize.

@MrGVSV MrGVSV added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types labels Apr 19, 2023
#[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)]
Copy link
Member

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?

Copy link
Contributor Author

@ickshonpe ickshonpe Apr 20, 2023

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.

Copy link
Member

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 😄

Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks!

@MrGVSV MrGVSV added this to the 0.11 milestone Apr 23, 2023
@mockersf
Copy link
Member

could you rebase this PR? CI is failing for a rust update that has already been done on main

@ickshonpe
Copy link
Contributor Author

Okay

@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Apr 29, 2023
@mockersf mockersf enabled auto-merge April 29, 2023 23:36
@mockersf mockersf added this pull request to the merge queue Apr 29, 2023
Merged via the queue into bevyengine:main with commit ee697f8 Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants