Open
Description
Bevy version
v0.16.1
What you did
Created a box and put an image as a child of the box. A node structure like:
"root"
Node{width:100px height:100px}
"img"
Node{width:100% max_height:100%}
ImageNode{image:"my_image.png", image_mode: NodeImageMode::Auto}
What went wrong
If my_image
is too tall, then the image will compress vertically to respect max_height
, without the width changing at all.
As ImageMeasure
is currently designed, it is impossible to maintain an image's aspect ratio while getting it to fill a box of arbitrary dimensions.
Expected fix
ImageMeasure
should follow these steps:
- Maintain aspect ratio when applying
max_height/max_width
. - Maintain aspect ratio when applying
min_height/min_width
. - Clamp to
min/max height/width
. This is allowed to stretch the image.
Note that the following code currently exists:
let width = width.or(s_width
.or(s_min_width)
.maybe_clamp(s_min_width, s_max_width));
But IMO the .or(s_min_width)
should be removed since it will interfere with applying aspect ratio when a min is hit.