Skip to content

ImageMeasure does not apply aspect_ratio to max width/height #19576

Open
@UkoeHB

Description

@UkoeHB

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:

  1. Maintain aspect ratio when applying max_height/max_width.
  2. Maintain aspect ratio when applying min_height/min_width.
  3. 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.

Metadata

Metadata

Assignees

Labels

A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions