Apply scale factor to ImageMeasure sizes#8545
Apply scale factor to ImageMeasure sizes#8545alice-i-cecile merged 12 commits intobevyengine:mainfrom
ImageMeasure sizes#8545Conversation
ImageMeasure's sizeImageMeasure sizes
|
Could you add a comment on |
Done, |
* Added comment to `ImageMeasure` noting that its size value needs to be in physical pixels.
Multiply `ImageMeasure::size` by the combined scale factor for UI texture atlas images too.
Checking for changed scale factor is required, unless the `image_size.size` is set to the scaled image size, which doesn't seem desirable.
|
This fix needs to be included with 0.11 I think, otherwise updating any UI projects using images from 0.10 is going to be really painful. |
| // target size of the image | ||
| size: Vec2, | ||
| /// The size of the image's texture | ||
| pub size: Vec2, |
There was a problem hiding this comment.
Do we want this to be editable by the user? Or should this be pub(crate)?
There was a problem hiding this comment.
Yes it's intended to be pub. That way someone can use ImageMeasure for their own custom widget if they want.
Otherwise, it doesn't matter that it's pub as measure funcs can't be accessed by users once they've been added to the layout tree.
Objective
In Bevy main, the unconstrained size of an
ImageBundleorAtlasImageBundleUI node is based solely on the size of its texture and doesn't change with window scale factor orUiScale.Solution
ImageMeasureshould be multiplied by the current combined scale factor.ImageMeasureshould be updated when the combined scale factor is changed.Example:
The red node is given a size with the same dimensions as the texture. So we would expect the texture to fill the node exactly.
Result with Bevy main branch bb59509:

Result with this PR (and Bevy 0.10.1):

Changelog
bevy_ui::widget::imageImageMeasures on changes to the window scale factor orUiScale.ImageMeasure::sizeby the window scale factor andUiScale.Migration Guide