bevyengine / bevyengine/bevy

ImageMeasure does not apply aspect_ratio to max width/height

Open
#19,576 2 comments 0 reactions 1 assignee Claimed by @UkoeHB View on GitHub
A-UI C-Bug S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

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:
```rs
"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:
1. Maintain aspect ratio when applying `max_height/max_width`.
1. Maintain aspect ratio when applying `min_height/min_width`.
1. Clamp to `min/max height/width`. This is allowed to stretch the image.

Note that the following code currently exists:
```rs
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.